Value Template Automation re-trigger

I’m working on an automation that will turn on the bathroom fan (right now its just set up to send a notification for testing, but eventually the action will be to turn on a switch) once a certain humidity is reached. The code below works, but my issue is that after the delay is up, the automation does not trigger again if the humidity is still above the threshold.

Does the humidity have to go below the threshold, and then above again to get a second trigger? The idea is to get the automation to continually make sure the fan is turned on until the humidity is below the threshold. Thanks

alias: Auto Fan Power
trigger:
  - platform: template
    value_template: '{{ states.sensor.bathroom_humidity.state | int > 40 }}'

action:
  - service: notify.pushover
    data:
      message: Someone is in shower? Humidity at {{states('sensor.bathroom_humidity')}}
  - delay: '00:01:59'
  - service: notify.pushover
    data:
      message: It has been 2 minutes, humidity is at {{states('sensor.bathroom_humidity')}}

To achieve what you want you’d need two automations.
One to turn on the fan above a value, the other to turn it off below a value.
You might also want to set a dead zone so you fan isn’t continually switching if the humidity is constantly hovering around your setpoint.

For the switch to turn on

trigger:
  - platform: state
    entity_id: sensor.bathroom_humidity
    above: 50

And off

trigger:
  - platform: state
    entity_id: sensor.bathroom_humidity
    below: 45
1 Like

I don’t know why I didn’t think of this, I think i was trying to overcomplicate things. Thanks for the advice!

We’ve all been there :wink: