What module for ESP32 or Arduino control of a external speed controller on a EC Hyper Phashfan?

ok here's the code just modify it to suit
when its connected to the fan
set the pid controller in home assistant a few degrees lower than your temp
run the auto tune and watch the output logs in esphome
might take some time it depends on your setup but at the the end it should say some shit like success and give you
kp: what ever you got
ki: what ever you got
kd: what ever you got
then just edit the config in esphome to these numbers




YAML:
output:
  - platform: esp8266_pwm
    pin: D1
    frequency: 1000
    id: pwm_output
    inverted: true
    min_power: 0.0
    max_power: 1.0



sensor:
  - platform: homeassistant
    name: "scd4 Tent Temperature"                 #
    id: scd4_c02                                                #
    entity_id: sensor.scd4_tent_temperature   # change to what ever you have

  - platform: rotary_encoder
    name: "Rotary Encoder"
    pin_a: D2
    pin_b: D3
    min_value: 0
    max_value: 53
    resolution: 4

  - platform: pid
    name: "Climate Result"
    type: RESULT

binary_sensor:
  - platform: gpio
    pin: D4
    name: "rotary button"





climate:
  - platform: pid
    visual:
      min_temperature: 15
      max_temperature: 30
      temperature_step: 0.1
    id: pid_climate
    name: "Fan Controller"
    sensor: scd4_c02
    default_target_temperature: 25°C
    cool_output: pwm_output
    control_parameters:
      kp: 0.72757
      ki: 0.01819      #change theses after auto tune with your output logs
      kd: 7.27541   

switch:
  - platform: template
    name: "PID Climate Autotune"
    turn_on_action:
      - climate.pid.autotune: pid_climate
hope this works for ya i"m no coder, all the rotary stuffs in ha automatons and check wiring on the mosfet board, if you look at the pictures they are different in each pic (was wrecked n took a while to figure out why fan was at full speed)
 
Last edited:

waring192

Active Member
Cheers mik! All parts have arrived, just waiting for boiler tech to come out as home boiler has a problem and it’s too cold to be messing with electronics!

regarding your second post about the pid controller in the esphome, is that different to the code you previously posted? I am quite good with esp home so will take a look at that also.

Thanks again :)
 
Cheers mik! All parts have arrived, just waiting for boiler tech to come out as home boiler has a problem and it’s too cold to be messing with electronics!

regarding your second post about the pid controller in the esphome, is that different to the code you previously posted? I am quite good with esp home so will take a look at that also.

Thanks again :)
It uses the climate pid controller from esphome so you can search that and it tells you about auto tune and other parameters you can set. I have the bang bang climate controller from esphome turning on a ac and heater
 

waring192

Active Member
I converted the v2 controller to use with home assistant. Used a esp8266 with a rotary encoder and a mosfet boardView attachment 5232899View attachment 5232900View attachment 5232902View attachment 5232904
Hey again, I'm just about to solder it now. I can tell where most of the wires go, but I'm just wondering what connects to the blue terminals on the mosfet board? I can see the black and red attach to the top but what about the bottom two? Also, I cannot quite see what connects the encoder?
 
Last edited:
Hey again, I'm just about to solder it now. I can tell where most of the wires go, but I'm just wondering what connects to the blue terminals on the mosfet board? I can see the black and red attach to the top but what about the bottom two? Also, I cannot quite see what connects the encoder?
the wires from the old potentiometer connect one in each side of the mossfet board

Rotary Encoder
pin_a: D2
pin_b: D3

rotary button
pin: D4


connect the grounds together and solder to ground
 

waring192

Active Member
the wires from the old potentiometer connect one in each side of the mossfet board

Rotary Encoder
pin_a: D2
pin_b: D3

rotary button
pin: D4


connect the grounds together and solder to ground
Hi Mike, so from what you said the Encoder goes to the D2, 3 and 4 of the ESP.What about the the two soldered pins from the Mosfet and what attaches to the blue terminals of the Mosfet as the wires charge in the photos?
 

waring192

Active Member
Hi again mike, can you just confirm this please:

Rotary Encoder to ESP:
CLK: D2
DT: D3
SW: D4
+: ?
GND: GND

MOSFET:
Blue terminals: ?
Trig/PWM: ?
GND: GND

Cheers
 
Last edited:

waring192

Active Member
@mikothegreen Hi fella, just really struggling on the mosfet. Your red and black are in two different photo positions in the photos?

Also, before I solder up:

Input from fan (My black wire is nearest the Rotary) >> Mosfet Blue Vin-
Input from fan (Red wire) >> Mosfet Blue Volt +
Mosfet GND >> ESP GND
Mosfet Trig/PWM>> ESP D1
Rotary A >> ESP D2
Rotary B >> ESP D3
Rotary SW >> ESP D4
Rotary + >> ESP 5V
Rotary GND >>GND

I think that's all correct apart from maybe the 1st two?
 
@mikothegreen Hi fella, just really struggling on the mosfet. Your red and black are in two different photo positions in the photos?

Also, before I solder up:

Input from fan (My black wire is nearest the Rotary) >> Mosfet Blue Vin-
Input from fan (Red wire) >> Mosfet Blue Volt +
Mosfet GND >> ESP GND
Mosfet Trig/PWM>> ESP D1
Rotary A >> ESP D2
Rotary B >> ESP D3
Rotary SW >> ESP D4
Rotary + >> ESP 5V
Rotary GND >>GND

I think that's all correct apart from maybe the 1st two?
red wire from controller to dc - out
black wire to dc- input
connect (SIGNAL GND) to the other ground i just twisted them together and soldered
connect (SIGNAL PWM+) to D1
index.jpg
 

waring192

Active Member
Hi @mikothegreen. Well, I picked up my Hyper Phresh from a friend and its almost useless. He has put rivets through to hold a crappy air filter and also some 8" ends so it looks like a silent one but isn't..

Anyway, got an AC-Infinity Cloudline S8 (paid for by him) so going to be using that. I have found some tutorials which is good but none that incorporate a rotary encoder :( The wiring and code for just he ESP32 are from @zen0n:


cloudline_wiring.png

So I pop the MOSFET as you used inside the sale as per above and below:

newfanwmosfet.png

Following these instructions:

Inside the panel, with it oriented like above, disconnect red, yellow and black wires on the right hand side. The 3 bottom right wires in this pic. Run the red wire to VOUT+ on the mosfet, run the yellow wire to VOUT- on the mosfet. I made a jumper from the ground wire on the terminal block, connected it and the black wire to gnd pin on the mosfet. Only had white hookup wire, but you can see the ground pin on the mosfet has 2 wires coming out of it. Make sure you're jumpers are long enough so the mosfet will tuck into the corner nicely. I dabbed some hot glue on the live points on the backside of the mosfet pcb.

Leave the fan aside for bench testing or roll the dice and seal er up! :P



Wiring up the ESP32:

The yellow wire is the pwm signal from the fan, and black is the ground. Note the notches in the connector for pin orientation. Looking at the pic now, the connector housing is female, but the pins are male. So I may have misgendered this connector. I'll monitor twitter for someone educate me on gender, I'm sure it will trend hahaha Anyhow, knocking these pins out and moving the wires around is easy enough with a precision screwdriver if you're color anal.

And I managed to bang out a fritzing diagram for the esp side, don't judge, first one :P In the diagram I've included both a circuit with the optocoupler (yellow wire coming from esp) or just straight wired to the gpio (green wire). Of note the resister in the opto circuit is 100ohm. The dpi settings on my desktop frigged up the pin labels in the image, but red is the 3.3v rail, blacks are grounds and yellow is GPIO4 and green is GPIO5 (but use whatever pwm applicable pins you want, use esp32 pinout ref to find out what will work for you.

esp32-fan-opto_bb.png

The yellow wire is the pwm signal from the fan, and black is the ground. Note the notches in the connector for pin orientation. Looking at the pic now, the connector housing is female, but the pins are male. So I may have misgendered this connector. I'll monitor twitter for someone educate me on gender, I'm sure it will trend hahaha Anyhow, knocking these pins out and moving the wires around is easy enough with a precision screwdriver if you're color anal.

And I managed to bang out a fritzing diagram for the esp side, don't judge, first one :P In the diagram I've included both a circuit with the optocoupler (yellow wire coming from esp) or just straight wired to the gpio (green wire). Of note the resister in the opto circuit is 100ohm. The dpi settings on my desktop frigged up the pin labels in the image, but red is the 3.3v rail, blacks are grounds and yellow is GPIO4 and green is GPIO5 (but use whatever pwm applicable pins you want, use esp32 pinout ref to find out what will work for you.

ESPHome and Home Assistant programming

* Again, assuming you know you to add esphome add on, and create a new blank esp32 device. I find it convienent to build the empty config and upload right away just to enable OTA updates going forward.

On the esp32 we will be using the ledc output to control the pwm duty cycle. That it's called ledc might seem a little off, but just know it's essentially a library for controlling pwm signals.

Edit your esp32 device to bring up the yaml editor, and paste the following

of note: make sure inverted reads true, or as it sounds 100% will be off, and 0 will be full speed. Make sure id is unique. frequency of 1000 seemed to work well enough for me.

speed_count will give you X amount of steps between 0 and 100, 10 seems to match up pretty well with what AC infinity was using before. Make sure output in the fan section matches the id from the output section. name is the display name you'll see in HA, id is it's internal name essentially.

change the pin to whatever you're using.

YAML:
output:
- platform: ledc
pin: GPIO5
id: intake_fan_op
inverted: true
frequency: 1000

fan:
- platform: speed
output: intake_fan_op
name: "Tent intake fan"
speed_count: 10
id: intake_fan
validate then upload to your esp.

Just wondering how I would incorporate your Rotary Encoder into this process now that I have come accustomed to it!
 
Hi @mikothegreen. Well, I picked up my Hyper Phresh from a friend and its almost useless. He has put rivets through to hold a crappy air filter and also some 8" ends so it looks like a silent one but isn't..

Anyway, got an AC-Infinity Cloudline S8 (paid for by him) so going to be using that. I have found some tutorials which is good but none that incorporate a rotary encoder :( The wiring and code for just he ESP32 are from @zen0n:


View attachment 5248627

So I pop the MOSFET as you used inside the sale as per above and below:

View attachment 5248628

Following these instructions:

Inside the panel, with it oriented like above, disconnect red, yellow and black wires on the right hand side. The 3 bottom right wires in this pic. Run the red wire to VOUT+ on the mosfet, run the yellow wire to VOUT- on the mosfet. I made a jumper from the ground wire on the terminal block, connected it and the black wire to gnd pin on the mosfet. Only had white hookup wire, but you can see the ground pin on the mosfet has 2 wires coming out of it. Make sure you're jumpers are long enough so the mosfet will tuck into the corner nicely. I dabbed some hot glue on the live points on the backside of the mosfet pcb.

Leave the fan aside for bench testing or roll the dice and seal er up! :P



Wiring up the ESP32:

The yellow wire is the pwm signal from the fan, and black is the ground. Note the notches in the connector for pin orientation. Looking at the pic now, the connector housing is female, but the pins are male. So I may have misgendered this connector. I'll monitor twitter for someone educate me on gender, I'm sure it will trend hahaha Anyhow, knocking these pins out and moving the wires around is easy enough with a precision screwdriver if you're color anal.

And I managed to bang out a fritzing diagram for the esp side, don't judge, first one :P In the diagram I've included both a circuit with the optocoupler (yellow wire coming from esp) or just straight wired to the gpio (green wire). Of note the resister in the opto circuit is 100ohm. The dpi settings on my desktop frigged up the pin labels in the image, but red is the 3.3v rail, blacks are grounds and yellow is GPIO4 and green is GPIO5 (but use whatever pwm applicable pins you want, use esp32 pinout ref to find out what will work for you.

View attachment 5248629

The yellow wire is the pwm signal from the fan, and black is the ground. Note the notches in the connector for pin orientation. Looking at the pic now, the connector housing is female, but the pins are male. So I may have misgendered this connector. I'll monitor twitter for someone educate me on gender, I'm sure it will trend hahaha Anyhow, knocking these pins out and moving the wires around is easy enough with a precision screwdriver if you're color anal.

And I managed to bang out a fritzing diagram for the esp side, don't judge, first one :P In the diagram I've included both a circuit with the optocoupler (yellow wire coming from esp) or just straight wired to the gpio (green wire). Of note the resister in the opto circuit is 100ohm. The dpi settings on my desktop frigged up the pin labels in the image, but red is the 3.3v rail, blacks are grounds and yellow is GPIO4 and green is GPIO5 (but use whatever pwm applicable pins you want, use esp32 pinout ref to find out what will work for you.

ESPHome and Home Assistant programming

* Again, assuming you know you to add esphome add on, and create a new blank esp32 device. I find it convienent to build the empty config and upload right away just to enable OTA updates going forward.

On the esp32 we will be using the ledc output to control the pwm duty cycle. That it's called ledc might seem a little off, but just know it's essentially a library for controlling pwm signals.

Edit your esp32 device to bring up the yaml editor, and paste the following

of note: make sure inverted reads true, or as it sounds 100% will be off, and 0 will be full speed. Make sure id is unique. frequency of 1000 seemed to work well enough for me.

speed_count will give you X amount of steps between 0 and 100, 10 seems to match up pretty well with what AC infinity was using before. Make sure output in the fan section matches the id from the output section. name is the display name you'll see in HA, id is it's internal name essentially.

change the pin to whatever you're using.

YAML:
output:
- platform: ledc
pin: GPIO5
id: intake_fan_op
inverted: true
frequency: 1000

fan:
- platform: speed
output: intake_fan_op
name: "Tent intake fan"
speed_count: 10
id: intake_fan
validate then upload to your esp.

Just wondering how I would incorporate your Rotary Encoder into this process now that I have come accustomed to it!
do you want it to control fan speed 1-10?
i haven't compiled this in esphome

YAML:
sensor:
  - platform: rotary_encoder
    name: "Rotary Encoder"
    pin_a: GPIO##
    pin_b: GPIO##
    min_value: 0
    max_value: 10
    resolution: 1
    filters:
      - debounce: 0.1s
    on_value:
      then:
      - light.turn_on:
          id: light_1
          brightness: !lambda "return x/10;"

output:
  - platform: ledc
    pin: GPIO5
    id: intake_fan_pwm
    inverted: true
    frequency: 1000 Hz
   
   
light:
  - platform: monochromatic
    output: intake_fan_pwm
    name: "Intake Fan"
    id: intake_fan_op
 
Last edited:

waring192

Active Member
Hi fella, it's all running well now but is there a way to keep it running constantly, at least a little to keep air moving?

Also, where in the logs do I find the control_parameters from esphome? Cannot see anything to so with them?
 
Last edited:

waring192

Active Member
do you want it to control fan speed 1-10?
i haven't compiled this in esphome
Yep, would love control via fan speed. Would also like to keep the temp around 25 degrees so I guess it's better to follow the last bit of code you posted and then automate the speed to keep it at or around 25 degrees. Is that the best way to go about it instead of the PID Controller? I don't mind using the PID controller as long as I can set a min speed of like 10%or something.

Maybe I have not let Autotune long enough? How many times does it have to go up and down above the 25 degree's?
 
YAML:
output:
  - platform: esp8266_pwm
    pin: D1
    frequency: 1000
    id: pwm_output
    inverted: true
    min_power: 0.0  // this changes min fan speed
    max_power: 1.0 

auto tune can take a while depends on your setup. run log from esphome and push auto tune button and just wait till it says it's done
 

waring192

Active Member
YAML:
output:
  - platform: esp8266_pwm
    pin: D1
    frequency: 1000
    id: pwm_output
    inverted: true
    min_power: 0.0  // this changes min fan speed
    max_power: 1.0

auto tune can take a while depends on your setup. run log from esphome and push auto tune button and just wait till it says it's done
1. Perfect fella! So this will keep it ticking away at say 20% if I put 0.2? It's for a grow tent so I need fresh air no matter what.

2. Regarding the Autotune, as my Fan is not inside the grow tent yet the temp hardly changes as it'strying to reduce the temp of the room, is it ok to pop the thermometer in the path of the extraction instead of using ambient temperature inside the tent so that the temp changes quicker or will that mess up the 'control_parameters' for the PID? I guess I could run Autotune again once setup but I need to pop ESP etc inside the little box and seal it up first making sure it runs well first.

3. I also found this: https://github.com/patrickcollins12/esphome-fan-controller Just wondering if I should chop some code in so I can edit some stuff etc? I know yours does the foundations but I think using all of this is overkill.
 

waring192

Active Member
YAML:
output:
  - platform: esp8266_pwm
    pin: D1
    frequency: 1000
    id: pwm_output
    inverted: true
    min_power: 0.0  // this changes min fan speed
    max_power: 1.0

auto tune can take a while depends on your setup. run log from esphome and push auto tune button and just wait till it says it's done
last question I promise! Do I set the 3 control K’s to 0 or the ones you had in the original code for your setup?
 
To autotune the control parameters:


  1. Set up the PID controller with all control parameters set to zero:

climate:
- platform: pid
id: pid_climate
name: "PID Climate Controller"
sensor: temperature_sensor
default_target_temperature: 21°C
heat_output: heater
control_parameters:
kp: 0.0
ki: 0.0
kd: 0.0
  1. Create a template button to start autotuning later:

button:
- platform: template
name: "PID Climate Autotune"
on_press:
- climate.pid.autotune: pid_climate

  1. Compile & Upload the new firmware.

Now you should have a climate entity called PID Climate Controller and a button called
PID Climate Autotune visible in your frontend of choice.


The autotune algorithm works by repeatedly switching the heat/cool output to full power and off.
This induces an oscillation of the observed temperature and the measured period and amplitude
is automatically calculated. To do this, it needs to observe at least 3 oscillation cycles.



Note
You have to set the setpoint of the climate controller to a value the
device can reach. For example if the temperature of a room is to be controlled, the setpoint needs
to be above the ambient temperature. If the ambient temperature is 20°C, the setpoint of the
climate device should be set to at least ~24°C so that an oscillation can be induced.
Also take care of external influences, like for example when room temperature is severely affected by
outdoor weather like sun, if it starts to warm up the room in parallel with the heating
autotune will likely fail or give false results.


  1. Set an appropriate setpoint (see note above) and turn on the climate controller (Heat, Cool or Auto).
  2. Click the PID Climate Autotune button and look at the the logs of the device.
    You should see output like
    PID Autotune:
    Autotune is still running!
    Status: Trying to reach 24.25 °C
    Stats so far:
    Phases: 4
    Detected 5 zero-crossings
    # ...


Note
In the output above, the autotuner is driving the heating output at 100% and trying to reach 24.25 °C.
This will continue for some time until data for 3 phases (6 crossings of the setpoint; or a bit more, depending on
the data quality) have been acquired.
The autotune algorithm may take a long time to complete, it depends on the time needed to reproduce the
heating up and cooling down oscillations the required number of times.


  1. When the PID autotuner has succeeded, output like the one below can be seen:
    PID Autotune:
    State: Succeeded!
    All checks passed!
    Calculated PID parameters ("Ziegler-Nichols PID" rule):

    control_parameters:
    kp: 0.49460
    ki: 0.00487
    kd: 12.56301

    Please copy these values into your YAML configuration! They will reset on the next reboot.

As soon as the the autotune procedure finishes, the climate starts to work with the calculated parameters
so that expected operation can be immediately verified.


If satisfied, copy the values in control_parameters into your configuration:


climate:
- platform: pid
# ...
control_parameters:
kp: 0.49460
ki: 0.00487
kd: 12.56301
The PID Climate Autotune button can be removed from the config, if the results are satisfactory, it’s not needed anymore.


  1. Complete, compile & upload the updated firmware.
 

waring192

Active Member
@mikothegreen Many thanks again! I was a little confused as I couldn't work out why it would start then stop etc. I didn't realise it was part of the calibration.

I have the fan on my desk at the moment while doing this but will put it along with my filter in the tent etc to replicate how it should be. I will do it again once the lights etc are installed and the ducting is sorted as there will be some changes.

With regards to your note on the heater, I will not be using one as the absent temp in the room (not tent) is around 20 degrees. When I have the lights, pumps etc all installed the temp will rise above 24 on its own I should think. Does it have to be set above or can I set it below the ambient temp inside the tent with lights etc on as the fan will be cooling and be on a minimum of 20% at all times?

Cheers Miko
 
Top