Helper to subtract sensors

Currently we have “sum”, “maximum”, “media”, etc, in sensor groups, but why there isn’t subtract option to have the operation: Sensor A - Sensor B = Sensor C ?

Thank you!

Are you aware that you can set that up easily with a template sensor?

If not, here’s an example:

- platform: template
      friendly_name: "Sensor A - Sensor B = Sensor C"
      value_template:  >-
        {{ ((states('sensor.sensor_a') | float(2)) 
        - (states('sensor.sensor_b') | float(2))) | round(2) }}
      unit_of_measurement: W

When suggesting templates it is best to use the modern format:

  - sensor:
      - name: "Sensor A - Sensor B = Sensor C"
        unit_of_measurement: W
        state: >
            {{ ( states('sensor.sensor_a') | float(0)
               - states('sensor.sensor_b') | float(0) ) | round(2) }}
        availability: >
            {{ states('sensor.sensor_a') | is_number and
               states('sensor.sensor_b') | is_number }}

The legacy format is still supported but will not have new features added.

Also I’m closing this as it has already been requested. Please vote and comment here:

1 Like