Trigger an event every time the value has changed X since last trigged

I found a lot of samples on how to trigger an event when a value goes over or under a certain limit but haven’t found any sample on how to trigger a change in the value.

As an example, lets say I have a temperature sensor and when it changed 1 degree sin last time triggered it should trigger the event again. How to do that

I think one way of doing this is by triggering using time, for example every 5 minutes.
Than you define a numeric helper to keep the last temperature value.

The condition would be that the:
absolute_value(current temperature minus the last value) >= X
In the action you store the temperature in the helper and fire the event.

I never done math in home assistant, but I’m guessing it is available?

1 Like

Thanks, that the solution I been thinking on and for example in node-red it’s easy to solve in a function but I’m curious if there is a smart HA solution for that.

I thought it was a quit common problem to check i a certain change in a value has occurred.

Trigger on the change attribute of the statistics sensor:

1 Like

I have a hx711 weight sensor under a cabinet shelf that I use to make sure no one is messing with my liquor.

The automation trigger is any state change on the sensor and the condition measures changes greater than 0.4 lbs (+ or -). Obviously you could set that to whatever you wanted. The 2nd part of the condition after ‘and’ is because the sensor randomly drops to -20ish and then spikes back up for some reason so that part forces the automation to ignore it.

Works well for me; not so much for my teenage kids…

    - platform: state
      entity_id: sensor.basement_liquor_scale_2
    - condition: or
        - condition: template
          value_template: "{{ trigger.from_state.state | float - trigger.to_state.state | float > 0.4 and trigger.from_state.state | float - trigger.to_state.state | float < 20 }}"
        - condition: template
          value_template: "{{ trigger.to_state.state | float - trigger.from_state.state | float > 0.4 and trigger.to_state.state | float - trigger.from_state.state | float < 20 }}"
1 Like