Won't trigger when condition becomes true

I am trying to understand why an automation is not triggering. I looked up the forum but couldn’t find how to solve this issue.

I have a template trigger and several conditions.
When the template statement is evaluated as true and the condition is not met there is no trigger as expected.
But when the template statement is still evaluated as true and the condition becomes true, the automation is not triggering.(no entry in the automation history).

At the beginning I was using a numeric_state trigger but if the condition was not met when crossing the threshold then there will be further trigger (with my conditions). I changed it to a template trigger believing that will solve the issue. But it’s not.

Here is the automation:

- id: 'RdC Chauffage marche'
  alias: RdC Chauffage marche
  description: "RdC Chauffage marche"
  trigger:
  - platform: template
    value_template:
      "{{ states('sensor.rdc_ambiant_temperature') | float < states('input_number.rdc_temp_cons_basse') | float }}"
    for:
      minutes: 1
  condition:
    condition: and
    conditions:
      - condition: or
        conditions:
          - condition: state
            entity_id: input_boolean.pac_on_off
            state: "on"
          - condition: state
            entity_id: input_boolean.pac_on_off
            state: "off"
            for:
              minutes: 30
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.zlinky_0x00158d000xxxxxxx_active_register_tier_delivered
            state: "HC.."
          - condition: template
            value_template: >
              {{ (state_attr('input_datetime.hp2hc', 'timestamp')
              - (as_timestamp(now()) - as_timestamp(now().replace(hour=0, minute=0, second=0)))) | round(0) > 5400 }}
  action:
  (...)

Thanks for any help.

The conditions are only evaluated when a trigger fires. If you want the conditions to be evaluated whenever they change then you need to put them as triggers also.

1 Like

A Template Trigger is triggered when the result of evaluating its template changes from false to true.

In other words, once it is true it must first change to false then back to true in order to trigger again.

That means if it triggers but the condition is not met, it won’t trigger again until the trigger first changes to false and then back to true.

Thank you for your quick answer.
That explains why.
Will try to modify this.
The value_template will grow.

Not necessarily. Use multiple triggers and multiple matching conditions if needed.

Thank you Taras.
That is also another possibility for implementing it.

You need multiple triggers with matching conditions.


Ninja’d by Troon

Thanks Troon.
Will look in this possibility too.

I’d like to understand the trigger template behavior.

If the template is true, then the conditions are verified and if the conditions are met then the trigger is set.

Now I am guessing that the template is continuously reevaluated when any entity is changed (sensor.rdc_ambiant_temperature in my case).
Therefore if the conditions become true and eventually sensor.rdc_ambiant_temperature changes (and the template is true), then the trigger should be set.
I am pretty sure that I have not seen a trigger in such a case hence my interrogation.

Check your logs for errors. You haven’t provided a default value for the floats, so if they fail to convert the sensor state (if, for example, you’ve mis-spelled “ambient” in the entity ID) it’ll throw an error in the logs.

Paste a screenshot of the history graph for both entities showing where you think the trigger should have fired but did not.

Here is a screenshot of sensor.rdc_ambiant_temperature

it is compared to input_number.rdc_temp_cons_basse (18,65 °C)

There is an entry in the automation log at 20:50:49, but nothing further. At 20:50:49 one of the conditions was not OK, which explains why there is no triggering.
At 22:08 the conditions were met, therefore it should have triggered at 22:23 when sensor.rdc_ambiant_temperature changed.

No. The template goes true at 20:50:49, and remains true for the rest of the time period, so no further triggers happen. HA is behaving as it should.

As per the first two responses, the conditions are only evaluated at the point of the initial trigger. If you want it to “continuously check” the conditions, you need to set them up as additional triggers. I’ve had a go below: this incorporates your pac_on_off into the triggers, but not the other zlink conditions — you can do that if it’s needed.

Note I’ve changed the original trigger from a template to a numeric_state trigger, and also added it to the conditions; and tidied up the and/or logic (and is default; or has a nice “shorthand” notation):

- id: 'RdC Chauffage marche'
  alias: RdC Chauffage marche
  description: "RdC Chauffage marche"
  trigger:
    - platform: numeric_state
      entity_id: sensor.rdc_ambiant_temperature
      below: input_number.rdc_temp_cons_basse
      for: "00:01:00"
    - platform: state
      entity_id: input_boolean.pac_on_off
      to: "on"
    - platform: state
      entity_id: input_boolean.pac_on_off
      to: "off"
      for: "00:30:00"
  condition:
    - condition: numeric_state
      entity_id: sensor.rdc_ambiant_temperature
      below: input_number.rdc_temp_cons_basse
    - or:
      - condition: state
        entity_id: input_boolean.pac_on_off
        state: "on"
      - condition: state
        entity_id: input_boolean.pac_on_off
        state: "off"
        for: "00:30:00"
    - or:
      - condition: state
        entity_id: sensor.zlinky_0x00158d000xxxxxxx_active_register_tier_delivered
        state: "HC.."
      - condition: template
        value_template: >
          {{ (state_attr('input_datetime.hp2hc', 'timestamp')
             - (as_timestamp(now()) - as_timestamp(now().replace(hour=0, minute=0, second=0)))) | round(0) > 5400 }}
  action:

Thank you Troon for your modifications.
I’ll try that and that should do it.
I’ll let you know when the conditions occur (not every day).

I noticed that the statement
for: “00:01:00”
is not allowed in the “condition: numeric_state” block.

You’re right, apologies. Just remove that line — it should make almost no difference.

After several occurences of the defined triggers, I think I have the right definition for this automation.
Thanks Troon and Taras for your explanations.
I had to rewire a part of my brain to match home assistant logic :slight_smile:

1 Like