Automation not triggering on numeric state above/below threshold for X seconds

I am trying to craft an automation to run an action when the numeric state of an entity either falls below or rises above X, i.e. I want to trigger it in both ways, and then differentiate in the action clause.

My problem is that I cannot get the automation to trigger. I have the following code:

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.tas_freezer_energy_power
    for:
      hours: 0
      minutes: 0
      seconds: 30
    below: 35
    attribute: value
  - platform: numeric_state
    entity_id:
      - sensor.tas_freezer_energy_power
    for:
      hours: 0
      minutes: 0
      seconds: 30
    above: 35
    attribute: value

This has fired a couple of times, but it is completely undeterministic, and I cannot get it to fire by turning the device on and off for longer than 30 seconds.

Am I misunderstanding something? How do triggers like this work? I know that the value has to cross the threshold (which it does). But if it then doesn’t cross again the other way for 30+ seconds, shouldn’t the trigger fire?

Does sensor.tas_freezer_energy_power have an attribute named value? You can check by going to Developer Tools > States and looking at the Attributes column for that sensor.

I will assume it doesn’t and you are actually trying to monitor the sensor’s state value. If that’s the case then remove this line from both Numeric State Triggers:

attribute: value

Reference

State Objects

Thanks @123. You’re right, “value” doesn’t exist, but it was only a try I had made and not removed from the paste here. Once I remove the attribute though, nothing changes. I just turned power on, and after about two minutes, the automation was triggered. Five minutes ago, I turned power off, but so far, the automation has not triggered again. So I am wondering if there’s some sort of resolution/sampling issue going on. It’s clearly not real-time, but I need to know what sort of margins I need to work with…

You need to check the dev tools. The problem is more likely from the device that is reporting the value. For example I have ZWave sockets that report power use, but so that they don’t flood the network, they by default only report if the new value is more than 10% different to the previous value it recorded.

Well I can guarantee that a Numeric State Trigger will never trigger if it’s configured to monitor a non-existent attribute.

I agree with you that it appears like the device doesn’t report its power level promptly. That behavior doesn’t work well with the for option.

I suggest you do what mobile.andrew.jones suggested. You need to observe and characterize the behavior of the reported power levels to understand how you can, or cannot, use them in a trigger.

What kind of power-monitoring device is it? For example, I have several Tasmotized devices and can control their power reporting behavior to be based on either a percentage change or an incremental value.

try creating a template helper with that single numeric attribute as its state
disconnect the device and use dev tools to force the value change.
Also, check how often the data is polled via teh integration, i have hive and thats defaulted to every 2mins to poll