Detecting a difference in value

I’ve set up an automation to trigger when my house load drops below a certain value, and that certain value is set on a sensor by another automation. I can’t afford the API calls to keep checking the certain value on the sensor so I can’t trigger off that, so I want to know if I can detect the difference vs the house load.

Here’s an example:

House load is 6kwh
Value of other sensor is 2kwh

If I trigger the automation when the house load drops below 2kwh then that works when the house load is say 3kwh and then it becomes 1kwh (as it’s below 2kwh), but if I have electric heaters on then it won’t trigger for example, so I need to detect when the house load drops BY 2kwh, not drops BELOW 2kwh.

trigger:
  - platform: state # trigger when the house load changes
    entity_id: sensor.house_load
    not_from:
      - unknown
      - unavailable
    not_to:
      - unknown
      - unavailable
  - platform: state # or when the other sensor changes
    entity_id: sensor.other_sensor
    not_to:
      - unknown
      - unavailable
condition:
  - condition: template # check if the change is greater than the value of the other sensor.
    value_template: "{{ trigger.to_state.state|float - trigger.from_state.state|float > states('sensor.other_sensor')|float }}"
action:
...

Thank you I’ll give it a go!

I just edited my post to change the error checking a bit.

1 Like