Automation Template Difference Between Last Two Readings of Sensor

Hi There,

I’m looking for a way to get a difference value between readings of a single specific sensor, just the last two readings.
Something like this

{{ (states.sensor.ensuite_humidity_sensor_humidity.state - states.sensor.ensuite_humidity_sensor_humidity.previous_state) }}

Looking to turn on a fan based on humidity change, but I really want to do it only if the jump between the two readings is greater than 5%. The trend sensor doesn’t fire when I want it as the humidity sensors seem to update pretty infrequently.

I wasn’t able to find an example for this type of thing.

yes you can using template triggers.
Check this page for more info:

Basically it would look like
{{ trigger.to_state.state - trigger.from_state.state }}

If the values are supposed to be numbers you may need to convert them to integers:
{{ (trigger.to_state.state | int) - (trigger.from_state.state | int) }}

1 Like

Thank you I’ll give that a try!