Triggers vs Conditions

When I try to use triggers for automation the automations don’t seem to work.
I think I may be missing some thing, however I cant seem to work it out. I am new to this YAML, and HA has so may variables its hard to know where to look to find answers. Its probably cause I don’t know the terminology when searching.

I can get it to work if I use conditions and not the trigger id in the Options
Any pointers would be appreciated.

I have a high and low input setup so i can change the temp settings without having to edit the automation.

If I setup the options with a condition it works but I cant use the input numbers in the conditions.

input_number.ac_set_high_temp

input_number.ac_set_low_temp

sensor.humidity_and_temperature_sensor_temperature

below is the automation that doesnt seem to trigger anything

alias: AC heat on and off
description: ""
triggers:
  - trigger: template
    value_template: >-
      {{ states('sensor.humidity_and_temperature_sensor_temperature') <=
      states('input_number.ac_set_low_on_temp') }}
    id: temp_low
  - trigger: template
    value_template: >-
      {{ states('sensor.humidity_and_temperature_sensor_temperature') >=
      states('input_number.ac_set_high_on_temp') }}
    id: temp_high
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - temp_low
        sequence:
          - action: climate.set_temperature
            metadata: {}
            data:
              hvac_mode: heat
              temperature: "{{ states('input_number.ac_set_high_on_temp') }}"
            target:
              entity_id: climate.ir_remote_lounge_living_room_ac
          - action: climate.set_fan_mode
            metadata: {}
            data:
              fan_mode: low
            target:
              entity_id: climate.ir_remote_lounge_living_room_ac
      - conditions:
          - condition: trigger
            id:
              - temp_high
        sequence:
          - action: climate.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: climate.ir_remote_lounge_living_room_ac
mode: single

[=“tugsynz, post:1, topic:899577”]

{{ states('sensor.humidity_and_temperature_sensor_temperature') <=
      states('input_number.ac_set_low_on_temp') }}

[/quote]

All states are strings. You need to convert to an integer or float before you do a numerical comparison.

{{ states('sensor.humidity_and_temperature_sensor_temperature') | float <=
      states('input_number.ac_set_low_on_temp') | float }}

You may also want to consider how to handle the sensor becoming unavailable; the template will generate an error when that happens unless you supply a default value to the float filter.

Also note that the trigger will only fire when the template changes from false to true. If it is already true and you change the input number so that it is still true, nothing will happen.

I have added the float, however still getting false. So not triggering.

triggers:
  - trigger: template
    value_template: >-
      {{ states('sensor.humidity_and_temperature_sensor_temperature') | float <=
      states('input_number.ac_set_low_on_temp') | float }}
    id: temp_low
  - trigger: template
    value_template: >-
      {{ states('sensor.humidity_and_temperature_sensor_temperature') | float >=
      states('input_number.ac_set_high_on_temp') | float }}
    id: temp_high

The sensor temp is currently 22.5 and the input set to 22

Based on that trace, you manually ran the automation… so it wasn’t trigger by either id: temp_high or id: temp_low… and you don’t have options in your Choose to deal with that.

You may want to read the following:

The trace was just to show that the trigger is still false even though the actual conditions have met the criteria of the temp sensor going higher than the input that was set.

At some stage the sensor temp changed from below the set temp to equal it/go past.

What am I missing. its a basic if sensor temp >= than input temp then trigger?

You seem to be missing the fact that the triggers are not conditions.

  • Triggers are events that start an automation.
    • In the case of your example it is the event of either one of the templates’ rendered values turning from false to true.
  • Conditions are tests that must be met before an action can be run.
    • In your automation, the only conditions you have are the ones in the Choose action and they are based on the trigger ID, if there is no trigger event, there is no trigger ID.

As described in the troubleshooting link I provided earlier… To effectively test your automation, you need to alter the state of one of the entities in the template such that the template renders false, then either change it back manually or wait for it to update naturally so that the template renders true. Then the automation will trigger.

Yes, so if no event then id expect that nothing happens.

As stated earlier I have let the trigger events become true, however, they are not triggering as true.

I have gone down the developer actions and set the input to a lower number so that the trigger should work. however this is not happening.

I have also allowed the temperature to drop well below the thresholds and above.

this works

alias: Aircon Temp
description: ""
triggers:
  - type: temperature
    device_id: 072444ed0a2d98c380f2f7cc90920660
    entity_id: 30db3ec7dc0bf8130024b571b85f4990
    domain: sensor
    trigger: device
    above: 23
    id: temp change above 23
  - type: temperature
    device_id: 072444ed0a2d98c380f2f7cc90920660
    entity_id: 30db3ec7dc0bf8130024b571b85f4990
    domain: sensor
    trigger: device
    below: 21
    id: temp change below 21
conditions: []
actions:
  - choose:
      - conditions:
          - type: is_temperature
            condition: device
            device_id: 072444ed0a2d98c380f2f7cc90920660
            entity_id: 30db3ec7dc0bf8130024b571b85f4990
            domain: sensor
            below: 21
        sequence:
          - action: climate.set_temperature
            metadata: {}
            data:
              hvac_mode: heat
              temperature: 22
            target:
              device_id: 07df5768d56ca09c10cb120f0f0f98c4
              entity_id: climate.ir_remote_lounge_living_room_ac
          - action: climate.set_fan_mode
            metadata: {}
            data:
              fan_mode: low
            target:
              device_id: 07df5768d56ca09c10cb120f0f0f98c4
              entity_id: climate.ir_remote_lounge_living_room_ac
      - conditions:
          - type: is_temperature
            condition: device
            device_id: 072444ed0a2d98c380f2f7cc90920660
            entity_id: 30db3ec7dc0bf8130024b571b85f4990
            domain: sensor
            above: 23
        sequence:
          - action: climate.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: climate.ir_remote_lounge_living_room_ac
mode: single

however when I change it to my previous code to include the input.number it fails.

I still don’t understand why the event (not the condition) doesn’t trigger when it should. Is there a problem with my input.number setup? or the ‘States’ boolen

Is there another way to use the input.number in the conditions?

I am trying to understand it all, but to me it seems overly complex. I am not arguing, just trying to figure it out.

I appreciate anyone that takes the time to reply. Thanks

Hi, did you test the template in dev tools/template? Just to confirm that you are using all the correct entity ids.
(sorry if I missed it above)

no, and looking at it, I wouldn’t know where to start.

The automation I made was created with the ui editor and made any changes as suggested, in my post. I’m not any kind of coder at all.

the entities are showing in the cards I added, so id have to assume I have them correct.

Select Developer tools in the side menu, then Template, then paste the teplate part of your trigger. My result will not be correct since I do not have your sensors

Thank you. Just trying it now

I have just tested it, and now get the true as desired. I had a mistake in the Entity ID.

Thank you.

2 Likes