It has now taken about 10 hours to collect ~1000 data points. So I just need to run it for ~2 months to have all the data.
Of course, that is totally impractical. I need to look again at what intervals might make sense for a coarser sampling.
@tbloth
The one in Grafana is actually not that exciting. There are only two queries, one for the current consumption and one for the total consumption, which go against my Postgres database where my Homeassistant sensor data is stored.
These are then simply two line graphs plotted against two y-axes.
One of these queries then looks like this, for example:
SELECT
$__timeGroupAlias("time",$__interval,0)
, 'Aktueller Verbrauch Spülmaschine'
, AVG(state::FLOAT) AS value
FROM ltss
WHERE
$__timeFilter("time")
AND entity_id = 'sensor.stromverbrauch_spuehlmaschine'
AND state != 'None'
GROUP BY 1,2
ORDER BY 1,2
Quite simple. I use Fritz!DECT 200 plugs for my household appliances that determine the total consumption itself.
For my lamps, I only have a very rough approximation so far, in which I determine how long they have been on per year so far and then multiply that by the possible maximum consumption according to the manufacturer:
@tbloth, I have the template below for calculating total light power based on the template sensor above, my naming convention of sensor.*light_power or sensor.*lamp_power, and inspiration from this post.
- platform: template
sensors:
sum_power_consumption_lights:
friendly_name: "Total Light Power Consumption"
unit_of_measurement: 'W'
icon_template: mdi:home-lightbulb-outline
value_template: >
{%- macro wildcard(entity_ids, select1, select2) %}
{%- for entity_id in entity_ids %}
{% set state_value = states(entity_id) %}
{%- if select1 in entity_id or select2 in entity_id %}
{{- state_value }}{{ '' if loop.last else ',' }}
{%- endif %}
{%- endfor %}
{%- endmacro %}
{% set entity_ids = states.sensor | selectattr('attributes.device_class', '==', 'power') | map(attribute='entity_id') %}
{{ wildcard(entity_ids, 'light_power','lamp_power').split(',') | map('float') | sum | round(2) }}
Nice, this is a good start. What sensor do you use to take the measurements? And how long do you need to wait between two measurements?
We definitely need to go a little coarser, as 2 months will be impractable.
I’m defining a sensor as I mostly took from here, such as:
All my lights are connected to my ABB Free@Home, so I had to define a sensor just for the wattage manually for every light. But I can ‘measure’ when they are on or off.
I simply plugged a table lamp for E14 sockets into my Fritz!DECT 200 socket.
The Fritz socket does not have the most accurate electricity meter and the snychronization with Home Assistant takes a while, but for the test it fits for now. My task currently always sleeps 30 seconds between switching the lamp and recording the consumption values.
Currently I’m running it again with an interval of 5 for brightness and 6 for Mired values. This seems to be quite a good compromise.
It’s doing a wildcard text search looping through the entity_ids for entities with light_power and lamp_power in their names, then adding their state (power) to a list for summing. Given i’ve already filtered for the domain power, i really only need to have to do a search for light and lamp.
I searched for ages to find a wildcard string search using Jinja2 filters, but couldn’t find anything. More than happy if someone can simplfy the code!
yeah, exactly. And for other integrations, like my Smartthigns Smart Plugs, i’ve gone with a similar naming convention to lamp_power and light_power and added the following to customize_glob.yaml. It’s not clear to me why I can do a wildcard string in customize glob, but not in a filter.
hopefully this is it - copy paste error on my part. Add the following to the bottom of the code i replied with earlier, but with appropriate indenting - refer this post
That did it, no error and I can see it listed under sensors on the UI, however when I turn the light on it goes from 0.0 W to ‘Unavailable’ ? So something is still not quite right.
Hey @nodecentral, what bulb do you have? The template is for a Hue LTW001.
Does your bulb have the capability to change warmth (mired) or is it just brightness?
If just brightness, the template won’t work
I don’t think color_temp should be color_mode. Color_mode sounds like an actual mode. And 254 should probably change to 255, but it may be a mute point
Checking all my hue bulbs I sadly done have that specific model.
Is it possible to adapt this code to focus on the brightness of the bulb to calculate the watts ? Even if we started off with a very rudimentary calculator , that takes a # watt hue bulb (e.g 9w) and do some calculations based on the brightness level ? 255 = 9 watts, 128 = 4.5w etc etc
The collection for this has now taken about 30 hours.
I think I will also run another test for one of my Hue bulbs tonight or tomorrow. This is certainly more interesting to most people than my SHYNE Globe that I tested the whole thing with.