Automation trigger not firing as expected ? no idea why

I am trying to get an automation to evaluate each state and then correlate the conditions:

I start with:

trigger:
  - platform: numeric_state
    entity_id: sensor.aeotec_zw075_smart_switch_gen5_power_21_8
    value_template: '{{ state.attributes.power_consumption }}'
    above: 25

the assumption here is that every time power_consumption is reported and its above 25 it should evaluate the conditions and if all conditions are matched it should action as configured …

my tests however show, that this isnt happening, the trigger works perfectly fine on restart and performs actions - if I set one condition to no longer match and then to match again, the next reported interval or power_consumption doesnt cause the action - anyone know why?

cheers

I would put the above 25 power as the condition and use something else for the trigger. I think if you use above 25 power as the trigger, it will only happen when it goes to >25 from blank or <25. I have seen some people use time as the trigger but that adds lots of events to the database.

thanks - we came to a similar conclusion, though it seems thats not how the trigger is supposed to work, or do I misinterpret this? My understanding would be it should trigger and then evaluate based on conditions if it has to do something … but its not triggering, as the trigger state hasnt changed, but actually the entity state has and hence from my understanding and reading the documentation it should actually trigger …

On state change of a specified entity, attempts to parse the state as a number and triggers if value is above and/or below a threshold.

I agree that its worded so that if power is >25, it should trigger constantly as long as the state changed. If the number is the state, then each change in the number is a state change and thus a trigger if >25. If the state is the same but >25, then it shouldn’t trigger like if it stayed a constant 27.

1 Like

@r4nd0m
Hi mate… Did your trigger worked finally ? In my case, I do have a similar automation in this following syntax…

- alias: 'Energy Usage is above 3.5 kW'
  trigger:
    platform: numeric_state
    entity_id: sensor.energy_usage
    above: 3.5
  action: 
    service: notify.pushbullet
    data:
      message: 'Energy Usage is above 3.5 kW' 

To me you are using the same automation except the value_template. Well in my case, it triggers each time energy usage exceeds 3.5kW limit. But the trigger is fired only once at the changing moment as expected.

If it isn’t working properly for you, I would suggest dig down the reported data format and template to check if it is extracting the right data… If that part is fine, then you might be disable the conditions and see how it goes…

Please make sure you have initial_state: 'on' in the automation.

its extracting the right data perfectly fine and its enabled but as mentioned it will only trigger when crossing the threshold and not while exceeding it further - though the documentation says it should …

I have temporarily gone for a time based trigger where I check all conditions to overcome this but I still believe either the way the trigger works or the documentation is wrong …

Where does it says in the doc that it should ? In all my applications, the trigger is only fired the first time you bypass your limit, and will only fire a second time if meanwhile you went down under your limit. Otherwise I think it will trigger multiple time per second, as long as you are above your limit. I think the best way to do what you want is to have a time trigger (let’s say every minute) and add your sensor value as a condition

Thats what the documentation says, so state change, value change it should parse the entity state and trigger if above or below a threshold - my understanding here: new value, new evaluation not depending to trigger state … thats how I read it …

This behaviour is more like the template trigger has been documented …

I’ve never had much luck with numeric_state triggers. What I’ve done is set up a template sensor that tracks the same value. Then base the automation on the state of that sensor. An extra step, but it’s worked reliably for me.

Is this the equivalent?

trigger:
  platform: state
  entity_id: sensor.aeotec_zw075_smart_switch_gen5_power_21_8
condition:
  condition: numeric_state
  entity_id:  sensor.aeotec_zw075_smart_switch_gen5_power_21_8
  above: 25
  value_template: '{{ state.attributes.power_consumption }}'
1 Like

If the numeric state specified is over 25 and your value is over 25 already, the state has not changed…

This will trigger every time the sensor.aeotec_zw075_smart_switch_gen5_power_21_8 state changes. And will re-execute the automation as long as the value is > 25.

1 Like

just tried this - this works perfectly fine - cheers

1 Like