Hi,
I know every well how to create an automation that runs on a particular state change. This is what’s usually known as edge trigger. This is trivial to achieve in HA. E.g. I can trigger a notification “system XYZ is offline” when the sensor provided by the “Ping” integration goes from “Connected” to “Disconnected”.
However I wonder how can I create a "level trigger". In other words I would like my automation to fire continuously till a particular state persists (e.g. till the sensor provided by the “Ping” integration remains in the “Disconnected” state).
The last action of my automation would be a Delay of e.g. 1min so that the automation would not actually fire CONSTANTLY but rather every 1min (till the “Disconnected” state persists).
This State Trigger will trigger only when the binary_sensor’s state changes from on to off and remains off for at least one minute.
alias: example
triggers:
- trigger: state
entity_id: binary_sensor.whatever
from: 'on'
to: 'off'
for:
minutes: 1
conditions: []
actions:
.. etc ...
Triggers in Home Assistant are based on state-changes. You can specify a specific state-change or any state-changes. For example, this will trigger for on to off, off to on, unavailable to on or off and on or off to unavailable.
triggers:
- trigger: state
entity_id: binary_sensor.whatever
NOTE
If you want to be notified every minute (or some other time period) after the binary_sensor’s state changes to off, I suggest you use the Alert integration.
Hey @123 ,
thank you so much for your response. That Alert integration looks very interesting. It’s a pity it requires to write configs manually in configuration.yaml instead of using the UI flow… but anyhow, I will give it a try tonight ! thanks
Simplest way would be to reverse roles and use time trigger set to 1min intervals and use your sensor as condition… This way every minute state of sensor would be checked and if condition to run automation is met it would be triggered.
You set a state trigger with no states and then you set your desired states as conditions.
The state trigger will trigger on every update of the state.
The conditions will let it run through with the right states.