Trigger Numeric_State depending on previous state


I am trying to trigger an automation when a sensor enters some range of values, and carry out different actions depending on if it is entering from above or from below. Is this possible in the numeric_state trigger platform. Sort of:

  - platform: numeric_state
    above: 10
    below: 25
    from: ????

If not, I can imagine setting some input_boolean helpers to flag whether I was above or below the range on the moment of time of the trigger and change the status inside the automation. Is that the right way? Or is there some condition I can use?

trigger.from_state.state will get you the state of the entity before it triggered the automation, in a template.
Then use a choose: to do different actions if the previous state was above (trigger.above) or below (trigger.below)

Great, thanks a lot. That’s what I needed.

So there is this recommendation to use states('sensor.my_sensor') instead of sensor.my_sensor.state. Is this not applicable to the trigger states?

Not sure it works with trigger. “states()” is a specific function. Probably, “trigger[].state” will work though.