Automation - Condition triggering only once

I have device sending in logs in yaml format via mqtt every 60 seconds. Based upon received values I want to restart device when it has been detected as stuck aka if reported value is 0 (below 1) for at least 5 minutes.

Here is my yaml code for automation I’ve made:

platform: numeric_state
  - sensor.device_some_float_value
  hours: 0
  minutes: 5
  seconds: 0
below: 1

Now it seems like this is triggering an action but only the 1st time this condition has been true. Next time when device hangs this automation will not be triggered.
I’ve gone through numerous automation posts trying to figure this out but without any luck although .last_updated is not changing.

I’ve tried with template option as well tracking other (integer) value (also provided via mqtt) but with no luck either - again it is being triggered only once.

{{ now()-states.sensor.device_some_int_value.last_changed | int > timedelta(minutes=5) }}

I’m obviously missing something out. Any help would be appreciated. Thank you.

is the state of your sensor.device_some_float_value going above 1 then going back to below 1?

if not then it won’t re-trigger until it does.

While device is working normally it is above 1 when it gets stuck it turns to 0. But after restart it should repeat the cycle as sensor.device_some_float_value gets updated. In normal operational mode it will never be below 1. But you got me thinking … It seems like there are situations in which reboot does not help restoring device’s normal operational state but in that case template automation should kick in …

I know what you are saying but the question was specifically about the actual state of the sensor.

The trigger will only happen if the state is above 1 and then goes below 1. It will not re-trigger until the state goes back to above 1 and then goes below 1 again.

If the state never actually goes above 1 then the automation will never trigger again.

If a reboot should check this automation again then you could add that as a trigger too. When you add it you should check for below 0 again in the conditions.

Sadly numerical_state conditions cannot use for: to check for five minutes. State conditions do allow a for: duration, so creating a binary sensor first (for instance a threshold sensor) and testing for that could help.

There’s an explanatory topic about these kinds of things here:

1 Like