Automation / Trigger / Above not working?

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?

What switches it off?

Your trigger only checks for when it is below 65 and then goes above 65…

1 Like

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.

Thank you for your help!

So what if I change 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: 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

Is this now correct?

This:

- alias: Turn off cellar plug when humidity is below 60%
  initial_state: 'on'
  trigger:
    - platform: template
      value_template: >-
        {{ states('sensor.humidity_outside')|float >
           states('sensor.humidity_cellar')|float }}
    - platform: numeric_state
      entity_id: sensor.humidity_cellar
      below: 60
  action:
    - service: switch.turn_off
      entity_id: switch.plug

I think I’d personally trigger it every half an hour and set the original trigger as a condition

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.

I’m just lazy and have a LOT of statuses to check

Ok so I made a binary sensor. What about this:

binary_sensor:
  - platform: template
    sensors:
      cellar_fan:
        entity_id: 
          - sensor.humidity_cellar
          - sensor.humidity_outside
        device_class: moving
        value_template: >-
          {{ (states('sensor.humidity_cellar')|float >
              states('sensor.humidity_outside')|float) 
              and (now().month >= 11 or now().month <= 3)
              and states('sensor.humidity_cellar')|float >= 65 }}

and changed my automations to:

- alias: Turn on cellar plug when humidity is above 65%
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.cellar_fan
      to: 'on'
  action:
    - service: switch.turn_on
      entity_id: switch.plug

- alias: Turn off cellar plug when humidity is below 65%
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.cellar_fan
      to: 'off'
  action:
    - service: switch.turn_off
      entity_id: switch.plug

There are so many possibilities to do that!

Looks good, the important thing is, does it work ?

It works! Thanks

Not sure why, you did all the work, great job :+1: