martikainen
(Mattias Martikainen)
March 28, 2017, 5:47am
1
Hi
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
sensor.kyl_power_8_8
sensor.pc_power_2_4
sensor.server_power_3_4
//BR Mattias
phileep
(Phil)
March 28, 2017, 6:23am
2
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 ?
fabaff
(Fabian Affolter)
March 28, 2017, 6:52am
4
I think this will make the addition of consumption as well? Would be awesome dude!
martikainen
(Mattias Martikainen)
March 28, 2017, 6:27pm
6
Would be awesome if you could post an example when you have the time, I’ve been trying but cant get the code right =/
phileep
(Phil)
March 28, 2017, 10:35pm
7
This is my sensor for rain today:
- platform: template
sensors:
rain:
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
martikainen
(Mattias Martikainen)
March 29, 2017, 6:09am
8
Thanks alot Phileep!
No problems at all tweaking that code
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
sensors:
total_power_usage:
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'
11 Likes
Thanks will try my friend