It’s working great! I’m using it to sum some WSDOT trip time measurements for the freeway routes between our company offices since they only provide the values on a per-segment basis, but I need it on a freeway exit-to-exit basis.
Like any other entity, it starts recording its historical data at the time you create the helper rather than just being a passthrough of the preexisting historical data from the entities that are being used for the sum. (That would have been amazingly neat, but I suspect it would be difficult to do efficiently.)
It would be nice to have subtract… or the ability to include any kind of manual/static values rather than only including references to entities. One could make a helper that contains a negative number and then include than as part of a sum. It’s a workaround, but that could probably work? (she says, not having tried it… )
I tried make helper with constant negative walue… wihtout success.
But I made some trick.
I made virtual mqtt sensor.
Usine MQTT Explorer i publish topic with negative value. (Remember topic must have Retain Flag).
Next, I made sum with my sensor.
It’s work but need a lot of work. Aubstract with constant value should be much simply
Until a ‘Subtract Two Sensors’ Helper is implemented (if ever) here’s how to do it with a simple Template Sensor.
In the following example, the goal is to subtract the value of sensor.subtrahend from the value of sensor.minuend and report the result in sensor.difference.
states('sensor.minuend') gets the state value of sensor.minuend.
State values are always strings (text) even when they appear to be numeric. We convert the string value to a floating point number (a number with decimal places as opposed to integer) using float(0).
The 0 in float(0) is a chosen default value. If float is unable to convert the sensor’s state value it will report 0 (the default value). You can set the default value to whatever is best for your application. For example, if the sensor’s value is unavailable then float will report 0.
The second half of the template simply performs the same procedure for sensor.subtrahend and then subtracts the resulting value from the value of sensor.minuend.
Substraction of a fixed value is possible though:
Create a Number with a negative value.
Create a ‘Combine the state of several sensors’ and ‘Sum’ the Number and e.g. a sensor value.
I used this to make a sensor offset.
If you see a ‘non-numeric’ error when using the Sum result in a Card on your Dashboard: A restart of Home Assistant will solve this error.
Also looking for subtract.
Could be a good option to negate any used sensor with a checkbox, then SUM could be simply used for subtract (not only 2 sensors, but any)