Still cannot grapple fundamental differences between state and numeric_state

Hello people, it is probably me but I am struggling with the differences between platform trigger state and numeric_state.

What I am trying to do is to turn on the switch for a a set of Sonoff Relays if I detect the temperature of that respective sensor to be below x for 30 mins.

I would like to have 1 automation to do this for multiple similar devices, ideally. Please tell me if this cannot be done and advice on best option. Thank you.

For State - The below works but I would like a range of temperature below x for example and not a point value.

alias: "Rogue AM Air-Con Temp State Change"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_10005bba3c_temperature
      - sensor.sonoff_10011fffb4_temperature
    id: Temperature_Change
    to: "28" # I need < 28 but dont think this can be done here
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition:
  - condition: time
    before: "07:00:00"
    after: "05:00:00"
action:
  - service: >-
      switch.turn_{{ 'on' if states(trigger.entity_id)|float(0) < 28.0 else
      'off' }}
    data: {}
    target:
      entity_id: >-
        {{ trigger.entity_id|replace('sensor', 'switch')|replace('_temperature',
        '') }}
mode: single

For Numeric_State - The below looks ok to set a temperature below x for example for 30 mins for example but nothing gets triggered for multiple entities. Not sure what I am doing wrong.

alias: "Rogue AM Air-Con Temp State Change"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_10005bba3c_temperature
      - sensor.sonoff_10011fffb4_temperature
    id: Temperature_Change
    below: "28.0"
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition:
  - condition: time
    before: "07:00:00"
    after: "05:00:00"
action:
  - service: >-
      switch.turn_{{ 'on' if states(trigger.entity_id)|float(0) < 28.0 else
      'off' }}
    data: {}
    target:
      entity_id: >-
        {{ trigger.entity_id|replace('sensor', 'switch')|replace('_temperature',
        '') }}
mode: single

This is a numeric sate trigger:

https://www.home-assistant.io/docs/automation/trigger/#numeric-state-trigger

You can do tests like above (greater than) or below (less than) or both.

This is a state trigger:

https://www.home-assistant.io/docs/automation/trigger/#state-trigger

Here you can only trigger on matching exact states, like a single numeric value, or ‘off’ or ‘on’ etc… You can match on the state changing to an exact state or from an exact state. You can also trigger on changing to any state by leaving to: as null (blank).

Thanks @tom_l I have read those docs over and over again.

So it seems like what I want to do, I cannot use the state trigger since I need a range of numeric values (< 28.0). I tried the numeric_state as like both my similar code snippets showed but it does not seem to trigger. I am not sure if it supports multiple entities as it does not trigger.

So in a dilemma, looks like there is no one single automation trigger to do what I want it to do ?

Thank you.

Did either of these sensors:

      - sensor.sonoff_10005bba3c_temperature
      - sensor.sonoff_10011fffb4_temperature

Change from above 28 to below 28 and stay below for 30 minutes?

And if so, did that occur between 5am and 7am (your condition)?

1 Like

Yes, they did. I did change the parameters so I am able to test them though and there wasnt any triggers

So multiple entities are able to work in a platform: numeric_state trigger ?

Did you check the automation trace?

Nothing gets triggered, unfortunately

Is there anything I need to do at the value_template itself ?

Show the history graphs for the two sensors between 5am and 7am.

Thanks @tom_l . Looks like it started to trigger when I remove the “” (string) quotes from the Above parm. I will do further testing and update. Thank you !

Yes and it doesn’t matter if the numeric value of above or below is wrapped in quotes (the Numeric State Trigger handles it as a number, not a string).

In order for the automation to trigger, the value of either of the two temperature sensors must decrease from above the threshold of 28 to below the threshold. It’s the crossing of the threshold that causes the trigger.

In addition, once it has crossed the threshold it must remain below it for at least 30 minutes (never even once rising above the threshold otherwise the 30-minute countdown is cancelled and the trigger is reset).

Finally, all of this must happen during a specific 2-hour window (05:00-07:00) in order to execute the automation’s action. For example, if the temperature drops below 28 at 06:45 and remains below 28 for 30 minutes, it won’t execute the actions at 07:15 because that’s outside the 2-hour window.

If there’s no trace then none of the requirements I described were met.

1 Like