Helper: Subtract/Add/divide/multiply two sensor values

I am trying to create a delta sensor of multiple sensor. I have an Emporia meter with a Balance sensor that I would like to subscract 1 zigbee sensor value:

Energy delta

This seems to work but I get the negative values in the energy dashboard on a per device item:

I got - more or less - the same issue when I try to add to values…

I got two sets of solar panels : one in front of the house, one in the back.
The entity of the panels in front is sensor.zonnepanelen_vooraan_actueel_vermogen
The entity of the panels in the back is sensor.zonnepanelen_achteraan_actueel_vermogen

How can I add these 2 values, and create a new value “sensor.zonnepanelen_totaal_vermogen”? that I can display on the home panel

Hi Kris, isn’t that explained in this post?

Found it! for use of total power usage in my house:

  1. Create Helper for “Combine the state of several sensors” , use sensor of power production for your solar panels and sensor of your Net (eg DSMR) power production. Use the ‘Statistical Range’. This wil calculate the own usage of your solar energy.
  2. Create another Helper for “Combine the state of several sensors”, use the above sensor from 1 and your Net power consumption. Use the ‘Sum’ function.

However for other purposes I need the substract function also…

1 Like

Sensor helpers already exist for sum. They do not exist for subtraction.


This can be solve if you think more than 5s About it. You can keep the sumation and add multipliers to the sensor outputs. This could do multiple interesting functions at once.

Please explain the ‘Statistical Range’ this does the “subtraction”; at least it works for me! to have a helper at the end that shows my actual power usage.

1 Like

Max minus min.

Yes, it’s not the most obvious way to subtract but it works for two enties. So for entities a, b statistical_range gives modulus(a-b) not quite true subtraction but would work ok if you know one is always bigger than the other, otherwise could confuse.

1 Like

It is also possible to use a helper of type template and subtract sensor values this way

For example

{{ states('sensor.sensor1') | float(0) - states('sensor.sensor2') | float(0) }}

Simple replace sensor1 and sensor2 with your entity ids.

First argument of float function is the precision of rounding. In the example I don’t care about the decimal places at all. Pipe Sensor values to a float function have the effect that Unavailable or NaN Values are become a zero before subtraction.

1 Like

That’s not true. The first argument of the float filter is the default value that’s output when the function cannot convert the string to a number.

I have the same problem. I have two energy sensors. One for my heat pump, the other general.
It is not possible for me to subtract the heat pump from general consumption. Both are added to Energy dashboard

You can subtract them in a template sensor

Thanks Petro. I will try it

I have solved it in this way:
Create a Number Helper „Minus-1“ with a fixed value of -1
Create a Helper „Heatpump-Inverted“ which multiplies the Heatpump and „Minus-1“
Sum General Consumption and Heatpump-Inverted, the result is what you want.

Hope this helps.

thank you. I try ASAP

Good idea. It works. Thanks to the community

1 Like