I’m trying to figure out how to sum up the daily usage of power from all the sensors that deliver that value.
So far I’ve taken this from another thread and modified it slightly:
This seems to give me the correct result, but is it really necessary to do a group, or can I filter the name of the sensor by ‘_daily_energy’ or something like that?
if you want to go the _daily_engery route without an entity list, you’d have to do a for loop and use namespace to add up the results and divide by the count. It won’t be a “pretty one line expression”.
{% set ns = namespace(total=0, count=0) %}
{% for s in states.sensor %}
{% if s.entity_id.endswith('_daily_energy') %}
{% set ns.total = ns.total + s.state | float %}
{% set ns.count = ns.count + 1 %}
{% endif %}
{% endfor %}
{{ ns.total / ns.count }}
I am trying to achieve something quite similar and thought I could tweak the above template to use the relevant attribute of my LightWaveRF Gen 22 sockets and lights but am currently failing.
Can anyone see what I am likely doing wrong in this value_template?
Maybe I missed it but nothing seems wrong with it. Paste it into the Template Editor and, starting from the end of the template, remove each filter in succession until you start seeing results. That will help narrow down which filter is the culprit.
definedError: 'mappingproxy object' has no attribute 'current_power_w'
I interpret this error message as saying that not all sensors which have a unit_of_measurement of “W” have an attribute of current_power_w - which is certainly true. My conclusion is that I should try setting up a group and iterating round it (I think I saw a method for that somewhere else on the forum.)
Very happy to - although that conversion comes ‘for free’ with the Lightwave sockets and lightswitches. Each device has a current W and kWh and resets at the end of each month which I just use templates to add up. There are some reliability difficulties with some of the devices but nearly all work. I’ll write a longer post describing the other bits in a bit.
Although it took a while to do, there is definitely no rocket science here.
In outline (and ignoring the complication that I am having to do it separately for two parts of the property), I
Used LightwaveRF Gen 2 light switches and sockets around the house.
Created a group for the sockets and switches in groups.yaml
Create template sensors to add up the power and the consumption
Used the standard gauge card to display the template numbers
Used auto-entities and the flex-table card for the long form display.
Added a power clamp to get a grand total power number and created a template sensor which is the difference between the clamp value and the total of the switches and sockets. This represents the power which is not being consumed via a LightWave socket or switch.
HI Andrew,
I dont know if i will do exactly the same as you…
I have two different Gauge Outputs from my PV Systems. They are mesured by two different Smartmeters. Is it possible to collect it in ONE Gauge? Im not able to do it.
One shows energy 5 kWh the other shows 7kWh so I would like to see ONE with 12 kWh.
The Same with the actual power
I hope youre understanding me instead of my bad english
Sascha