Trigger an automation once on sensor value transition

I want to create a trigger which triggers an automation when a sensor value changes from any value above 200 to any value below 10. So I want HA to behave like: when the sensor value is anything below 10, HA says “hey I don’t care”. When sensor value goes above 200, HA says “hey I am watching you”. When sensor value drops to any number below 10, HA triggers the automation actions only once and then keeps ignoring the sensor till it goes back above 200 again. How to achieve this?


Create a threshold binary sensor with hysteresis:

  - platform: threshold
    entity_id: sensor.your_sensor_here
    upper: 105
    hysteresis: 95
    name: Sensor Threshold

This will turn on at upper + hysteresis (200) and turn off at upper - hysteresis (10).

Trigger your automation using a state trigger that monitors this binary sensor turning on.

Thank you so much…!!! I did not know about the Threshold integration. Always something new to learn.

1 Like

Sometime later… having a similar problem.
It sounds very simple for the logic, but quite complicated workaround.
I have an idea how this could be implemented in a generic way.
It would be nice to have a section similar to trigger, but as an “arming” for the actual trigger. Or think about it like a 2 stage trigger.
Whether it should be called “arming”, or “pre-trigger”, I don’t know (or care :slight_smile: )
The logic would be: the pre-trigger (stage 1) is just enabling the normal trigger (stage 2).
This way one can implement time hysteresis (e.g. a device must be off a certain duration before allowing turning on again), or numerical hysteresis like you wanted here…

That already exists.

Use a trigger with a for: time for your first stage. Then use a wait_for_trigger in the actions for your second stage.

I’m relatively new and I might have missed it :slight_smile: .
This is very useful in all kind of hysteresis situations (time and/or numerical), and I saw many related questions (people using workarounds…).
I beliebe it deserves a special hint somewhere in the documentation.