Automation does not trigger (sometimes) after manually executing the action

I have a Tuya Multiprise connected through Zigbee to hassio. It also has physical buttons to switch on/off each independent socket.

I wired a fan to socket 1, and wrote an Template automation to turn it on whenever the humidity is too high (I’ve got an Mijia sensor).

My issue is that sometimes when I turn off socket 1 manually (press the switch), and when the condition is satisfied to trigger the automation, the automation does not fire.
How can I investigate what’s going wrong? With the latest update, I can see the trace when the trigger is fired and debug, but I can’t check when the trigger condition is satisfied but it’s not triggered.

Can someone help me? I’ve included my automation below:

alias: Turn the Fan On
description: >-
  Turn on the fan in the room whenever the humidity OR the temperature are too high
trigger:
  - platform: template
    value_template: >-
      {% if states.sensor.room_temperature.state  | float > 35 %} true {%
      endif %}
  - platform: template
    value_template: >-
      {% if states.sensor.room_humidity.state  | float > 70 %} true {% endif
      %}
condition: []
action:
  - type: turn_on
    device_id: c28
    entity_id: switch.0x001234_l1
    domain: switch
mode: single

So if I turn off the switch manually (humidity is 75), and few minutes later the humidity hits 90 (value increases), the switch does not turn on. Does my template condition always need to go from below 70 to above 70 or does it mean that anytime the change above 70 happens the action is executed?

triggers always have to go from false to true before they will trigger the automation.

if the humidity is already above 70 (both triggers are already true) then it won’t trigger until at least the humidity goes below 70 and then back above (trigger from false to true).

Thanks for confirming my suspicion!
I there a way to evaluate the condition based on the change of the value of the sensor rather than the state of the trigger?

Try this version:

alias: Turn the Fan On
description: Turn on the fan in the room whenever the humidity OR the temperature are too high
trigger:
  - platform: state
    entity_id:
      - sensor.room_temperature
      - sensor.room_humidity
condition:
  - "{{ states('sensor.room_temperature') | int > 35 or states('sensor.room_humidity') | int > 70 }}"
  - "{{ is_state('switch.0x001234_l1', 'off') }}"
action:
  - service: switch.turn_on
    target:
      entity_id: switch.0x001234_l1
mode: single

It triggers whenever the temperature or humidity changes, then checks if the temperature is above 35 or humidity below 70 and the switch is currently off. If true then it turns on the switch.

1 Like