Can anybody please review my code? I can’t get my ‘automatic humidity’ controller get to work.
It looks like is doesnt trigger the lambda’s, it should trigger all the time ( loop ) when the sensor value is above 10… but it doesnt. Anybody some suggestions?
unfortunately it is not possible to have multiple “on_value_range” triggers…
The code
esphome:
name: centrale_afzuiging
platform: ESP8266
board: nodemcuv2
includes:
- custom_fan.h
## PULL UP ALL THE PINS ON BOOT
on_boot:
then:
- fan.turn_on:
id: itho_fan
speed: HIGH
- delay: 500ms
- fan.turn_on:
id: itho_fan
speed: MEDIUM
- delay: 500ms
- fan.turn_on:
id: itho_fan
speed: LOW
wifi:
ssid: ""
password: ""
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ""
password: ""
captive_portal:
# Enable logging
logger:
level: VERY_VERBOSE
# Enable Home Assistant API
api:
ota:
switch:
- platform: template
name: "Automatic humidity controller"
id: auto_humidity
optimistic: true
sensor:
- platform: dht
pin: D2
temperature:
name: "Badkamer Temperatuur"
id: badkamer_temp
humidity:
name: "Badkamer Luchtvochtigheid"
id: badkamer_luchtvochtigheid
on_value_range:
above: 10
then:
- if:
condition:
lambda: 'return id(badkamer_luchtvochtigheid).state > 90 && id(badkamer_luchtvochtigheid).state < 100 && id(auto_humidity).state == true ;'
then:
- fan.turn_on:
id: itho_fan
speed: HIGH
- logger.log: "automated humidity controller : HIGH!"
- if:
condition:
lambda: 'return id(badkamer_luchtvochtigheid).state > 40 && id(badkamer_luchtvochtigheid).state < 90 && id(auto_humidity).state == true ;'
then:
- fan.turn_on:
id: itho_fan
speed: MEDIUM
- logger.log: "automated humidity controller : MEDIUM!"
- if:
condition:
lambda: 'return id(badkamer_luchtvochtigheid).state > 0 && id(badkamer_luchtvochtigheid).state < 40 && id(auto_humidity).state == true ;'
then:
- fan.turn_on:
id: itho_fan
speed: LOW
- logger.log: "automated humidity controller : MEDIUM!"
model: DHT22
update_interval: 60s
output:
- platform: custom
type: float
lambda: |-
auto my_custom_fan_output = new MyCustomFanoutput();
App.register_component(my_custom_fan_output);
return {my_custom_fan_output};
outputs:
id: my_custom_fan
fan:
- platform: speed
output: my_custom_fan
id: itho_fan
name: "Mechanische Ventilatie"
speed:
low: 0
medium: 0.5
high: 1
I would probably create three template binary sensors that define the desired on/off states and then use the on_press and on_release features. The template binary sensor has a poll rate of 60s but it is configurable.
Another idea that is probably better is just to have an automation that fires every x seconds and checks these conditions.
A third option now that I see your humidity sensor updates only every 60s, use the on_value instead of the range. Then check for the range inside like you are already doing.
nickrout
(Nick Rout)
March 11, 2020, 6:59am
5
And yet another idea is to do the automation in home assistant.
Thanks for the responce!
Created a function that fires every minute ( see code ), working perfectly ;)!
Thanks
esphome:
name: centrale_afzuiging
platform: ESP8266
board: nodemcuv2
includes:
- custom_fan.h
## PULL UP ALL THE PINS ON BOOT
on_boot:
then:
- fan.turn_on:
id: itho_fan
speed: HIGH
- delay: 500ms
- fan.turn_on:
id: itho_fan
speed: MEDIUM
- delay: 500ms
- fan.turn_on:
id: itho_fan
speed: LOW
wifi:
ssid: ""
password: ""
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ""
password: ""
captive_portal:
# Enable logging
logger:
level: VERBOSE
# Enable Home Assistant API
api:
ota:
switch:
- platform: template
name: "Automatic humidity controller"
id: auto_humidity
optimistic: true
sensor:
- platform: dht
pin: D2
temperature:
name: "Badkamer Temperatuur"
id: badkamer_temp
humidity:
name: "Badkamer Luchtvochtigheid"
id: badkamer_luchtvochtigheid
model: DHT22
update_interval: 60s
time:
- platform: sntp
on_time:
- seconds: 0
minutes: /1
then:
- logger.log: "getting in trigger loop"
- if:
condition:
lambda: 'return id(badkamer_luchtvochtigheid).state > 85.0 && id(badkamer_luchtvochtigheid).state < 100.0 && id(auto_humidity).state == true ;'
then:
- fan.turn_on:
id: itho_fan
speed: HIGH
- logger.log: "automated humidity controller : HIGH!"
- if:
condition:
lambda: 'return id(badkamer_luchtvochtigheid).state > 70 && id(badkamer_luchtvochtigheid).state < 84.9 && id(auto_humidity).state == true ;'
then:
- fan.turn_on:
id: itho_fan
speed: MEDIUM
- logger.log: "automated humidity controller : MEDIUM!"
- if:
condition:
lambda: 'return id(badkamer_luchtvochtigheid).state > 0.0 && id(badkamer_luchtvochtigheid).state < 69.9 && id(auto_humidity).state == true ;'
then:
- fan.turn_on:
id: itho_fan
speed: LOW
- logger.log: "automated humidity controller : MEDIUM!"
output:
- platform: custom
type: float
lambda: |-
auto my_custom_fan_output = new MyCustomFanoutput();
App.register_component(my_custom_fan_output);
return {my_custom_fan_output};
outputs:
id: my_custom_fan
fan:
- platform: speed
output: my_custom_fan
id: itho_fan
name: "Mechanische Ventilatie"
speed:
low: 0
medium: 0.5
high: 1
Having some issues with the automatic handling of the lambda :
time:
- platform: sntp
on_time:
- seconds: 0
minutes: /1
then:
- logger.log: "getting in trigger loop "
- logger.log:
format: "humidity %.1f auto humidity state %.1f ith_fan speed %.1f"
args: [ 'id(badkamer_luchtvochtigheid).raw_state', 'id(auto_humidity).state','id(itho_fan)' ]
- if:
condition:
lambda: 'return (id(badkamer_luchtvochtigheid).state > 0.0 && id(badkamer_luchtvochtigheid).state < 69.9) && (id(auto_humidity).state == true) && ((id(itho_fan).speed == !0));'
then:
- fan.turn_on:
id: itho_fan
speed: LOW
- logger.log: "automated humidity controller : LOW!"
- if:
condition:
lambda: 'return (id(badkamer_luchtvochtigheid).state > 85.0 && id(badkamer_luchtvochtigheid).state < 100.0) && (id(auto_humidity).state == true) && (id(itho_fan).speed == !1);'
then:
- fan.turn_on:
id: itho_fan
speed: HIGH
- logger.log: "automated humidity controller : HIGH!"
- if:
condition:
lambda: 'return (id(badkamer_luchtvochtigheid).state > 70 && id(badkamer_luchtvochtigheid).state < 84.9) && (id(auto_humidity).state == true) && (id(itho_fan).speed == !0.5);'
then:
- fan.turn_on:
id: itho_fan
speed: MEDIUM
- logger.log: "automated humidity controller : MEDIUM!"
The last statement of the if conditions should get the current speed/state of the fan, thus only going further if the state is not the same as the current state.
Strangely it is only working on medium and low, but the high fan state value won’t be triggered…
id(itho_fan).speed == !1
what does this mean? Did you mean id(itho_fan).speed != 1
?
I’m unclear on why you need this at all. I assume if the fan is on high and you turn it on high nothing happens.
Thanks alot!
That did the trick: “id(itho_fan).speed != 1”, i’m a beginner concerning C (just a mechanical engineer );)!
I need it because otherwise i’m transmitting (with remote hooked up to ESP ) every time the function get’s triggered.
nickrout
(Nick Rout)
March 11, 2020, 9:36pm
11
Then again, this is the home assistant forum…
Oops. Replied to the wrong topic