#Numeric State trigger not triggering - need tips to debug/investigate

1 messages · Page 1 of 1 (latest)

grave mist
#

I'm new to HA so probably missing something obvious. My automation is simple: It should trigger when outside temp < inside temp and send a notification. I'm using a Number State trigger. It should have ran 20 minutes ago but it didn't and I don't understand why not.

I've done the following to investigate the issue:

  1. Reviewed the automation settings (3 times) to try and spot any issues
  2. Checked state on the Ecolink - sensor.ecolink_air_temperature reports 85.5
  3. Checked state on the outside temperature module - sensor.outside_temp_and_humidity_air_temperature reports 85.3

I'd appreciate any tips on where to go from here to try and debug this. Below is the YAML for the trigger, if that is helpful:

entity_id:
  - sensor.ecolink_air_temperature
for:
  hours: 0
  minutes: 5
  seconds: 0
above: sensor.outside_temp_and_humidity_air_temperature
alias: Outside is cooler than inside```

And here is the full automation YAML:
```alias: Outside cooled off notification (test)
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.ecolink_air_temperature
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: sensor.outside_temp_and_humidity_air_temperature
    alias: Outside is cooler than inside
conditions:
  - condition: numeric_state
    entity_id: sensor.ecolink_air_temperature
    above: 72
    alias: Inside temp > 72
actions:
  - action: notify.mobile_app_sugar3
    metadata: {}
    data:
      message: >-
        Outside {{ states('sensor.outside_temp_and_humidity_air_temperature') }}
        is cooler than inside {{ states('sensor.ecolink_air_temperature') }} -
        turn on fan!
      title: Turn on the fan
mode: single```
swift glen
#

was the ecolink air temperature entity's state below the outside temperature before you created the automation?

grave mist
#

It was not

swift glen
#

that's your problem then

#

numeric state triggers will only trigger when crossing the threshold you define

#

the inside temp will need to be less than the outside temp before that automation would ever trigger again

grave mist
#

I'm sorry, I misunderstood your question, even though it was clear. Yes, the Ecolink was below the outside temp when I created the automation. It only just crossed 30 minutes ago

swift glen
#

ah gotcha

#

what does the latest automation trace show?

grave mist
#

No traces found

swift glen
#

also make sure the automation is actually on

grave mist
#

It's on

swift glen
#

have you tried asking it nicely to please work?

grave mist
#

Nicely? No 😉

#

I'm struggling with not having tools to investigate, or I should say not knowing where the tools are. I'm sure some process is evaluating these triggers every second or whatever, I wish I could see debug logs of that evaluation.

swift glen
#

i assume you've run a config check?

grave mist
#

I have not. I'm searching now what that is...

#

"Configuration will not prevent Home Assistant from starting!" - config checked out fine

swift glen
#

command line check, not the UI one

#

regardless, try running the automation's action manually to double check that it works

grave mist
#

Actions ran fine, push notification popped up on my phone

grave mist
#

Developer Tools > States > Set State is a great tool to dev/debug

#

Alright!! - figured it out and it's a strange UI behavior. At first I thought it was a bug, but as I was preparing to write up an Issue I changed to thinking it was just "odd". Basically, if you have an entity set for an upper/lower limit, then select the Fixed number radio button and save, you haven't removed the entity. The UI makes you think you did because the control goes away, but the entity is still there and part of the trigger. You need to select the entity radio option again and click the X to remove the entity from the list.

wheat gyro
#

FWIW, in many cases a Template trigger is going to be the better choice over a Numeric State trigger when comparing values from entities. When you use a Numeric State trigger, in order for the trigger to fire, it has to be the state of the entity under entity_id that causes the comparison to become true.

For example, in your automation above, if the indoor temperature is stable and the outside temperature drops below the indoor temperature, the automation will not fire... however, if the outdoor temperature is stable and the indoor temperature rises above the outside temperature (like when you are running a heater) the trigger will fire. In the real world, both values are changing which will lead to the trigger seeming to work sometimes, and "randomly" not work other times.

So, for your situation a better trigger would be to invert the entities, using below instead of above...

alias: Outside BECOMES cooler than inside
trigger: numeric_state
entity_id: sensor.outside_temp_and_humidity_air_temperature
below: sensor.ecolink_air_temperature
for: "00:05:00"

... but better than that would be:

alias: Outside is cooler than inside
trigger: template
value_template: |
  {{ states('sensor.ecolink_air_temperature')|float(0) >
  states('sensor.outside_temp_and_humidity_air_temperature')|float(0) }}
for: "00:05:00"
night sleet
#

That might cause false triggers when the outside sensor becomes unavailable

#

So the bestest trigger would be

alias: Outside is cooler than inside
trigger: template
value_template: |
  {% set in = states('sensor.ecolink_air_temperature') | float('na') %}
  {% set out = states('sensor.outside_temp_and_humidity_air_temperature') | float('na') %}
  {{ in | is_number and out | is_number and in > out }}
for: "00:05:00"
grave mist
grave mist
# night sleet So the bestest trigger would be ```yaml alias: Outside is cooler than inside tri...

I don't have a grasp of YAML syntax, but here's my understanding of your solution:
First two lines are assigning the values from the entities to variables with what appears to be a default assignment to basically NaN
3rd line is the comparison statement checking if both variables are valid numbers and then doing the value comparison.
I don't understand all the pipes all over the place, but see first sentence of this comment 🙂
If I were writing this in another language, say TypeScript, I would have used null rather than NaN - not saying one is better than the other, but that's what I would have done. In YAML or HA is there a reason to avoid null and use a NaN approach or is it just personal preference?

night sleet
#

Templates are written in Jinja

wheat gyro
#

The pipes are used to separate variables from filters as they are applied, so you can chain a sequence of functions.

night sleet
#

You could also do it like this

alias: Outside is cooler than inside
trigger: template
value_template: |
  {% set in = states('sensor.ecolink_air_temperature') %}
  {% set out = states('sensor.outside_temp_and_humidity_air_temperature') %}
  {{ in | is_number and out | is_number and in | float > out | float }}
for: "00:05:00"