Triggering when a value changes above (or below) a threshold

I can’t figure out how to do the following automation:
I have a sensor value and I want to do something when it changes from below (or equal) a threshold value to a value above the threshold.
For example:
Threshold is 20
sensor value changes from 7 to 10 - do nothing
sensor value changes from 10 to 11 - trigger automation
sensor value changes from 11 to 12 - do nothing

My problem is that I would need the previous sensor value, but don’t have access to it in an automation.

Any idea how to implement this?

This kind of operation is easy in AppDaemon - when you subscribe to a state change you are handed the old and the new values so you can decide what to do.

I saw this before. However, I’m still interested to see if this can be done with the “normal” automations.

Make a sensor and trigger it with something like this:
`
trigger:
platform: numeric_state
entity_id: sensor.battery_stefan
below: 15
action:

  • service: notify.Stefan
    data:
    title: ‘Home Assistant’
    message: ‘Stefan’‘s batterij is bijna leeg!’
  • service: notify.Denise
    data:
    title: ‘Home Assistant’
    message: ‘Stefan’‘s batterij is bijna leeg!’ `

Does this fire only once? That would be what I’m looking for but I had expected that this will fire as long as the value stays below this value.

It sends just once, untill it goed above and then below the treshhold again

Cool, that’s exactly what I was looking for.

Good to know because this is the center of my issues with implementing the laundry sensor project.