I want to turn on my cellar plug when humidity is above 65% and when outside humidity is bellow cellar humidity. To do that I did the following automation:
- alias: Turn on cellar plug when humidity is above 65%
initial_state: 'on'
trigger:
- platform: numeric_state
entity_id: sensor.humidity_cellar
above: 65
condition:
- condition: template
value_template: >-
{{ (states('sensor.humidity_outside')|float < states('sensor.humidity_cellar')|float)
and (now().month >= 11 or now().month <= 3) }}
action:
- service: switch.turn_on
entity_id: switch.plug
and it does not trigger… cellar humidity is at 75% and condition template is now true…
I though that each time cellar humidity is updated, it checked if it is above 65 but it seems that it is triggered only when cellar humidity is bellow 65 and goes above 65.
Am I true? Does that means that it will trigger again only when cellar humidity goes bellow 65?
As David points out, this trigger only occurs when the value transitions through the value specified.
Don’t worry you are not the first to make this mistake.
You may be better configuring a binary sensor and using that instead
In fact you could do all the comparisons in there (the is it greater than 65 and is it greater than outside) you could also put some time limits too. To stop it running at night or whatever.
- alias: Turn on cellar plug when humidity is above 65%
initial_state: 'on'
trigger:
- platform: template
value_template: >-
{{ (states('sensor.humidity_outside')|float < states('sensor.humidity_cellar')|float)
and (now().month >= 11 or now().month <= 3) }}
condition:
- condition: numeric_state
entity_id: sensor.humidity_cellar
above: 65
action:
- service: switch.turn_on
entity_id: switch.plug
Will it work in this case? or again, will the condition be true only if it is below 65 and then goes above 65? Just saw that documentation is clear for automation trigger but not so clear for condition.
Instead of a binary sensor, I have currently changed my automation to:
- alias: Turn on cellar plug when humidity is above 65%
initial_state: 'on'
trigger:
- platform: template
value_template: >-
{{ (states('sensor.humidity_outside')|float < states('sensor.humidity_cellar')|float)
and (now().month >= 11 or now().month <= 3) }}
condition:
- condition: template
value_template: "{{ states('sensor.humidity_cellar')|float > 65 }}"
action:
- service: switch.turn_on
entity_id: switch.plug
Yep, that will work but again only when the template changes to true.
You are fine if you boot/restart HA, Look at the states and flip the switch manually, you will then be in the control loop.
But when you next start HA …
As @SaNewm says, if you just check every 30 mins, that’s minimal processing and better than just manually flipping the switch.