Timed Automation trigger does not work

Hello Community. I got thie automation set up:

  • id: "Gate Pos Helper Controller"
    alias: "Gate Pos Helper Controller"
    trigger:
    • platform: template
      value_template: "{{ (states('sensor.en_gesamt_leistung') > 50) and (states('sensor.sax_battery_power_average') | float(0) < 50) }}"
      for:
      seconds: 5
      id: "turn_on"
    • platform: template
      value_template: "{{ (states('sensor.sax_battery_power_average') | float(0) > 50) }}"
      for:
      seconds: 5
      id: "turn_off"
      action:
    • choose:
      • conditions:
        • condition: trigger
          id: "turn_on"
          sequence:
        • service: input_boolean.turn_on
          target:
          entity_id: input_boolean.en_gate_pos
      • conditions:
        • condition: trigger
          id: "turn_off"
          sequence:
        • service: input_boolean.turn_off
          target:
          entity_id: input_boolean.en_gate_pos
          mode: restart

Sadly, the triggers never fire and i have no clue why. The correspondending sensors are -of of course - on the wanted state for more than 5 seconds, but it just does not fire. Any idea why?

Thanks a lot for any help

They don't fire because the first one contains an error and the second may behave differently than how you think it does.

In the first Template Trigger, this part is wrong:

states('sensor.en_gesamt_leistung') > 50

You must convert the sensor's value from a numeric string to a number using the float or int filter before comparing it to another number (50).

states('sensor.en_gesamt_leistung') | float(0) > 50

The second Template Trigger will trigger when sensor's value increases above the threshold value of 50 and remains above it for at least 5 seconds. Triggering only occurs when the threshold is crossed.

In other words, the Template Trigger's state must change from false to true to cause triggering. So if the sensor's current value is already higher than 50, the Template Trigger's state is already true and it won't trigger.

From the documentation:

Template triggers work by evaluating a template when any of the recognized entities change state. The trigger will fire if the state change caused the template to render ‘true’ (a non-zero number or any of the strings true, yes, on, enable) when it was previously ‘false’ (anything else).