Sensor: Merge several Power meters?


Is there any way to merge several sensors measuring power usage into one?
I have 7 z-wave plug measuring my power usage all around the house and it would be nice to create a merged sensor showing the total current usage for example.

I’ve tried the MAX/MIN sensor which only gives me “unknown” value, the statistics wouldn’t even go trough config check with several entities.
3 example names used in my config it someone could help me out with a code for it


//BR Mattias

I am pretty sure you can do maths in a template sensor

Create a new sensor that is the sum of the sensors you wish to add

I do something similar to deduct the cumulative rainfall to midnight from current readings to get rain today in my system (just cant show you the config as I am at work right now)

I had a calculation for this but it broke with an update.would be nice if someone could figure this out and let us know ?

Statistics sensor could help.

I think this will make the addition of consumption as well? Would be awesome dude!

Would be awesome if you could post an example when you have the time, I’ve been trying but cant get the code right =/

This is my sensor for rain today:

  - platform: template
        value_template: '{%- if not is_state("sensor.rain_cum","unknown") -%}  {{ ((states.sensor.rain_cum.state | float) - (states.sensor.rain_cum_prior.state | float)) | round(1) }} {%- endif -%}'
        friendly_name: 'Rain Today'
        unit_of_measurement: 'mm'

So, there are 2 sensors already: rain_cum-prior and rain_cum.

Test if there is a value for rain_cum_prior (otherwise I can end up with negative rain if it is not currently initialised).

Then convert the values to float to allow the maths to happen consistently, which is rounded to 1 dp

1 Like

Thanks alot Phileep!
No problems at all tweaking that code :slight_smile:

Here is my code if anyone needs to do the same, i removed the if statement in phileeps code since i dont need it.

platform: template
    value_template: '{{ ((states.sensor.pc_power_2_4.state | float) + 
    (states.sensor.server_power_3_4.state | float) + 
    (states.sensor.frys_power_7_8.state | float) + 
    (states.sensor.kyl_power_8_8.state | float) + 
    (states.sensor.soffa_power_6_8.state | float) + 
    (states.sensor.sovrum_power_10_8.state | float) + 
    (states.sensor.tvattmaskin_power_9_8.state | float) + 
    (states.sensor.tvsovrum_power_5_8.state | float)) | round(1) }}'
    friendly_name: 'Total power usage'
    unit_of_measurement: 'w'

Thanks will try my friend