Simple automation doesn't trigger

Hi all! I have a simple automation to adjust the position of 2 covers that it seemed to me that it stopped working after an update (not sure).

This automation was created through User Interface (UI), so i post here some prints and also the code generated in “automations.yaml”.




- id: '1625524784081'
  alias: Fechar estores (Verão)
  description: f(temps)
  trigger:
  - type: temperature
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: sensor.temperature_158d00056e4ed5
    domain: sensor
    above: 23
  condition:
  - condition: time
    after: '9:30'
    weekday:
    - mon
    - tue
    - wed
    - fri
    before: '21:00'
  action:
  - device_id: xxxxxxxxxxxxxxxxxxxxxxxx
    domain: cover
    entity_id: cover.shellyswitch25_8caab505897a
    type: set_position
    position: 30
  - device_id: xxxxxxxxxxxxxxxxxxxxxxx
    domain: cover
    entity_id: cover.shellyswitch25_8caab54b84e7
    type: set_position
    position: 30
  mode: single

I’ve also tried to use the trigger type “numeric state” instead of “device” but it also doesn’t work.

Any ideas?
Thanks!

If the temperature goes above 23 before 09:30 or after 21:00 then tha automation will never run. Is that what you want?

Try this version. The combination of triggers and conditions ensures the action is performed for all circumstances.

- id: '1625524784081'
  alias: Fechar estores (Verão)
  description: f(temps)
  trigger:
  - platform: numeric_state
    entity_id: sensor.temperature_158d00056e4ed5
	above: 23
  - platform: time
    at: '09:31'
  - platform: homeassistant
    event: start
  condition:
  - condition: time
    after: '9:30'
    weekday:
    - mon
    - tue
    - wed
    - fri
    before: '21:00'
  - condition: numeric_state
    entity_id: sensor.temperature_158d00056e4ed5
	above: 23
  action:
  - device_id: xxxxxxxxxxxxxxxxxxxxxxxx
    domain: cover
    entity_id: cover.shellyswitch25_8caab505897a
    type: set_position
    position: 30
  - device_id: xxxxxxxxxxxxxxxxxxxxxxx
    domain: cover
    entity_id: cover.shellyswitch25_8caab54b84e7
    type: set_position
    position: 30
  mode: single

No. It’s after 9:30 and before 21:00

Tinkerer explained that if the temperature rises above 23 before 09:30, the automation will trigger but will not execute the action because the condition only permits it between 09:30 and 21:30. That is expected. However, the trigger only occurs at the moment the temperature crosses the threshold value of 23. If after triggering, the temperature remains at 23 or continues to increase, it will not trigger the automation again. So the temperature might increase to 24 when it becomes 09:30 but it will not trigger the automation.

That’s how a Numeric State Trigger works (or Numeric Device Action). It only triggers when the threshold value is crossed. In your example, after increasing above the threshold, it must first decrease below it, then rise above it again in order to re-trigger the automation.

The example I posted compensates for this behavior and ensures the automation is triggered appropriately.

Ok @123 , now i understood! Thanks for the clarification!
I’ve tried also the platform “device”, using the following code:

  - type: temperature
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxx
    entity_id: sensor.temperature_158d00056e4ed5
    domain: sensor
    above: 23

But it also doesn’t run, so i supose it has the same logic as mentioned.

So, my big question is: how can enable a trigger everytime that a temperature value changes?

Thanks again for the time and help!

Use a State Trigger. However, that’s not the optimal way to do what you want. It will trigger for every temperature change and your automation will need a condition to confirm it exceeds 23. In addition, if it changes from 23 to 24 it will execute the action again (and again and again if the temperature continues to increase). You would need to add another condition to prevent executing the action if the cover’s position is already 30 (unless you don’t mind needlessly sending the set_position command to a cover that is already in the correct position).

The example I posted avoids all of that and will trigger only when necessary. It also handles the situation where Home Assistant might be offline at 09:30. Whenever Home Assistant starts, the automation is triggered and, if the time is within the desired range and the temperature exceeds 23 it will execute the action.

1 Like

Humm, from your explanation i understood that at 9:31 or when the temperature changes to a value above 23ºC (just the 1st time) it triggers the automation, but really my complete automation includes also a differente related to the outside temperature, so, between 9:30 and 21:00 this can trigger more than once.

And in fact i want it to do so, because i have another one with “open cover” condition, so that throughout the year it manages the opening and closing to maintain the inside temperature optimal.

Thanks agaian

The issue you are experiencing has been encountered by numerous other users who have had the same complaint that their automation has failed to trigger as expected. The root cause has been their misunderstanding of how a Numeric State Trigger, or its Device equivalent, operates. Sometimes they also don’t understand the relationship between triggers and conditions.

If you are saying what you posted above is not the actual automation you are using, then you should post it.

1 Like

So, here it is the complete automation:

- id: '1626172588535'
  alias: Teste fechar estores
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxx
    entity_id: sensor.temperature_158d00056e4ed5
    domain: sensor
    above: 23
  - platform: homeassistant
    event: start
  condition:
  - condition: time
    after: '9:30'
    before: '21:00'
  - condition: and
    conditions:
    - condition: numeric_state
      entity_id: sensor.dif_temp_out_in
      above: '-2'
  action:
  - device_id: xxxxxxxxxxxxxxxxx
    domain: cover
    entity_id: cover.shellyswitch25_8caab54b84e7
    type: set_position
    position: 30
  mode: single

This was generated through UI.

I assume this:

sensor.dif_temp_out_in

represents the temperature difference between outside temperature and inside temperature?

I also assume sensor.temperature_158d00056e4ed5 represents inside temperature?

The way that automation is designed, if the inside temperature rises above 23 before 9:30, and stays above 23, the automation will not be triggered at that moment or later, after 9:30. It will first have to decrease below 23 then rise above it (between 9:30 and 21:00) to execute the action.

In addition, when you restart Home Assistant, between 9:30 and 21:00, the automation will execute the action as long as the temperature difference is above -2. It doesn’t check if inside temperature is above 23, only if the temperature difference is greater than -2.

If everything I described is exactly the way you want it to work, then there’s nothing else to discuss.

If what I described is not how you want it to work, you should use the example I posted. The only addition it needs is to handle sensor.dif_temp_out_in.

Thank you very much @123 , i will correct it and later on give some feedback.

I don’t know why i created this idea that at each time the temperature changes it will trigger the automation…

Thanks again!

Trust me when I say you are not the first person to assume that’s how a Numeric State/Device Trigger works nor the last. It’s natural to assume it will keep triggering as the temperature continues to rise above the threshold … but that’s not how it works.

2 Likes

So, dear @123 , i still can’t put my automation to work.
Here are the temperatures:

As you can see, at 9:31 all the conditions should be checked (temp in, diference between temp in/out, and time), but the covers didn’t move. I leave here the “trace timeline”:

I leave here the code:

- id: '1625524784081'
  alias: Estores - Fechar (Verão)
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: 93d20bab264211b2b80b8621b2105d85
    entity_id: sensor.temperature_158d00056e4ed5
    domain: sensor
    above: 23
  - platform: homeassistant
    event: start
  - platform: time
    at: '9:31'
  condition:
  - condition: time
    after: '9:30'
    weekday:
    - mon
    - tue
    - wed
    - fri
    before: '21:00'
  - condition: or
    conditions:
    - condition: time
      after: '10:30'
      before: '21:00'
      weekday:
      - sat
      - sun
  - condition: or
    conditions:
    - condition: time
      after: '9:30'
      before: '13:30'
      weekday:
      - thu
  - condition: and
    conditions:
    - type: is_temperature
      condition: device
      device_id: 93d20bab264211b2b80b8621b2105d85
      entity_id: sensor.temperature_158d00056e4ed5
      domain: sensor
      above: 23
  - condition: and
    conditions:
    - condition: numeric_state
      entity_id: sensor.dif_temp_out_in
      above: '-2'
  action:
  - device_id: ba8506c6ab7179834351692c0402b3a6
    domain: cover
    entity_id: cover.shellyswitch25_8caab505897a
    type: set_position
    position: 30
  - device_id: cf9c73e41233e6d800d229ee6fafcd39
    domain: cover
    entity_id: cover.shellyswitch25_8caab54b84e7
    type: set_position
    position: 30
  mode: single

Can you click there to see what went wrong?
trace error

I believe the problem may be due to the way you structured the multiple conditions.

You need to review how to use the OR Condition. Compare what you have done with the example in the documentation:

condition:
  alias: "Paulus home OR temperature below 20"
  condition: or
  conditions:
    - condition: state
      entity_id: "device_tracker.paulus"
      state: "home"
    - condition: numeric_state
      entity_id: "sensor.temperature"
      below: 20

The conditions to be logically ORed should all be listed below the condition: or statement under conditions. Effectively, your multiple conditions are still being handled as logically ANDed.

Ok. It makes sense.
So i have several “Or” conditions and “and” conditions.
Now i’ve changed them and put them all grouped.

Here is the updated code

- id: '1625524784081'
  alias: Estores - Fechar (Verão)
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: 93d20bab264211b2b80b8621b2105d85
    entity_id: sensor.temperature_158d00056e4ed5
    domain: sensor
    above: 23
  - platform: homeassistant
    event: start
  - platform: time
    at: '9:31'
  condition:
  - condition: time
    after: '9:30'
    weekday:
    - mon
    - tue
    - wed
    - fri
    before: '21:00'
  - condition: or
    conditions:
    - condition: time
      after: '10:30'
      before: '21:00'
      weekday:
      - sat
      - sun
    - condition: time
      after: '9:30'
      before: '13:30'
      weekday:
      - thu
  - condition: and
    conditions:
    - type: is_temperature
      condition: device
      device_id: 93d20bab264211b2b80b8621b2105d85
      entity_id: sensor.temperature_158d00056e4ed5
      domain: sensor
      above: 23
    - condition: numeric_state
      entity_id: sensor.dif_temp_out_in
      above: '-2'
  action:
  - device_id: ba8506c6ab7179834351692c0402b3a6
    domain: cover
    entity_id: cover.shellyswitch25_8caab505897a
    type: set_position
    position: 30
  - device_id: cf9c73e41233e6d800d229ee6fafcd39
    domain: cover
    entity_id: cover.shellyswitch25_8caab54b84e7
    type: set_position
    position: 30

Let’s wait for tomorrow and see! Thanks again for all the help! Always learning :wink:

I think what you want is to logically OR all three of the Time Conditions.

Exactly…let’s see tomorrow