Manually calculating power consumption of lights

Hello, folks,

In our flat I have set it up in such a way that power consumption is now recorded for almost all devices:

The only devices which, apart from our oven which uses high voltage, are not yet recorded are our Hue lights and Sonos speakers.

So I was wondering if anyone of you knows a way to calculate the power consumption of our Hue Lights manually depending on their status and brightness?

Maybe via a template sensor?
I would be happy if maybe one of you has already done something like this and could give me some tips :slight_smile:

1 Like

I use template sensors like this:

- platform: template
  sensors:
    myensor:
      unit_of_measurement: "W"
      entity_id: light.foo
      value_template: >-
        {% if is_state('light.foo', 'on') %}
          10.5
        {% else %}
          0
        {% endif %}

This obviously does not take into account how bright the lamp is. But for me it’s sufficient to just go with the consomption the lamp has by specification. Of course you can nest some brightness conditions in there. And Technically the off-consumption wouldb’t be 0 either. Anyways, maybe this gets you started.

5 Likes

Thank you @danielperna84 .

That’ll help a lot!
I think I’ll set it up like in your example first and then try to figure out how to calculate the consumption per year.
Maybe a combination of history and statistic sensors?

Ok, I think I managed it in a first try with the history sensor and another template sensor.
First, I calculate the time when a certain light was on yesterday:

  - platform: history_stats
    name: Deckenlampe Wohnzimmer AN gestern
    entity_id: light.deckenlampe_wohnzimmer
    state: 'on'
    type: time
    end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 24

In a second step I multiply this time by the average consumption of the lamp (in my case 9.5 Watt).

   gesamtverbrauch_light_deckenlampe_wohnzimmer:
      value_template: '{{ states.sensor.deckenlampe_wohnzimmeran_gestern.state | multiply(0.0095) | round(2)}} kWh' 
      friendly_name: 'Gesamtverbrauch Deckenlampe Wohnzimmer'

With these values, I can now display the total consumption in Grafana via a rolling cumulation, I think.

Unfortunately, with this method I only have the total consumption up to the day before. However, I would like to have the total consumption of this year as live data until now.

Unfortunately I haven’t found a way to do this yet :frowning:
Probably I only need a hint how I can use the Statistic Sensor to calculate how long my lamps have been on this year so far.

Maybe somebody else has any other idea

Hello, folks,

Calculating the time a lamp was on this year is relatively easy.
Maybe it will help one or the other of you, so I’ll post it here:

  - platform: history_stats
    name: Deckenlampe Ankleide AN Jahr
    entity_id: light.deckenlampe_ankleide
    state: 'on'
    type: time
    start: '{{ now().replace(month=1).replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
2 Likes

is there a way to factor in the dimming ? consumption = wattage * Dimmning facot

try:

myensor:
      unit_of_measurement: "W"
      entity_id: light.foo
      value_template: >-
        {% if is_state('light.foo', 'on') %}
           {{0.2 + state_attr("light.foo", "brightness") * 10.3 / 255 }}
        {% else %}
          0
        {% endif %}

or similar.

2 Likes

Hi All
I’ve started making power consumption calculations for my Hue lights unnecessarily complicated, because I almost can. I took power measurements of one of my Philips Hue LTW001 bulbs using a Power-Mate Lite PML10A power meter, stepping brightness from 1% to 100% in 10% steps and mired temperature from 153 to 454 in 50 steps.

Charting the results (below) gave an unexpected curve at first glance (the peak near the middle of the mired values). Sort of makes sense on second glance.

I’ve used bilinear interpolation to estimate the power values for any other values of brightness and mired. I can handle myself in excel well enough, but have no idea how to make this happen in python, or any other code.

If I can figure out how to upload the excel file with the measurements and the calcs, would any one be interested in have a crack and translating the formulas into some code that can be used in HA?


2 Likes

I asked a similar question here, if it helps? If I can understand the maths (which is difficult for me) I’d like to have a function/formula I can apply to any hue bulb model…

Hi @nodecentral , I think the answer was already given in the link you posted. https://stackoverflow.com/a/66525656
If I see it correctly and the values are correct, you would need a template sensor for each lamp that looks something like this:

  - platform: template
    sensors:
      stromverbrauch_light_deckenlampe_buro_test:
        unit_of_measurement: "W"
        value_template: "{{ 0.43981651 * (e ** (0.012712893 * (state_attr('light.buro_deckenlampe', 'brightness')))) }}"

In general, you can take any data points (e.g. for other lamps models) and try to fit them to your function. A natural e function seems to be a good model for this. It’s just simple algebra
Fitting Exponential Models to Data – Algebra and Trigonometry (opentextbc.ca)

Of course, there are also online calculators where you can enter your data and which will give you a possible function. Or you can simply do it in any office program (e.g. MS Office or Libre Office). Here is one of such online calculators e-Exponential regression Calculator - High accuracy calculation (casio.com)

Thanks @nodecentral,
That’s for a single dimension, but if i take what @CM000n says about fitting exponential functions and do it for a number of points of light warmth, then I may be able to interpolate between those funcions.

Exactly, except that it would make it even more complicated.
Here you would have a multivariate function, which could look like this, where x1 = brightness and x2 = color temperature:
456456nt

Perhaps this would be a good starting points:
scipy - Python curve_fit with multiple independent variables - Stack Overflow
python - Exponential curve fitting in SciPy - Stack Overflow

If you would like to make your data available @cloak , I’m sure someone would try their hand at it sometime.
I would also be very interested, but I have little time at the moment and can’t promise anything.

I have also found a very interesting official Philips Hue page here, where you can see the power consumption of a lamp under certain conditions:
Energy consumption - calculate yours | Philips Hue (philips-hue.com)

Hi @cloak

I played around a bit and created a Jupyter notebook with some test data for a lamp, from the official Hue page mentioned above:
https://colab.research.google.com/drive/1vEcx7GAZqYq2SMNzvX-HgLGlkluHJmbP?usp=sharing
Of course without claim to correctness and completeness :wink: But maybe this shows, how you could do it if necessary. All suggestions or improvements are welcome

Overall, I then get this (z=brightness and x=kelvin):


More data would certainly not be bad here. Since the 5 different measurement series for the Kelvin values hardly play a role in my example

Hi all,

Most of my bulbs are Phillips Hue, although I don’t have that many models, it would be good to have a calculator where based on the model/number in use, you can find a corresponding set of values to understand the watts (cost) being used.

Now the following is mostly dummy data, and I found various other Hue bulb model numbers online, which I’ve been testing out (using Lua) on my Vera HA controller.

It’ll be great to have the a list of calculations for each bulb model.

local wattsFromDim = {
  LWB010 = function (dim) return 0.43981651 * math.exp(0.012712893 * dim) end,
  LWA004 = function (dim) return 0.45677776 * math.exp(0.012712893 * dim) end,
  LWW001 = function (dim) return 0.48765897 * math.exp(0.012712893 * dim) end,
  LWB006 = function (dim) return 0.40134543 * math.exp(0.012712893 * dim) end,
  LWB004 = function (dim) return 0.40134543 * math.exp(0.012712893 * dim) end,
  LCT007 = function (dim) return 0.41987568 * math.exp(0.012712893 * dim) end,
  RS125 = function (dim) return 0.41987568 * math.exp(0.012712893 * dim) end
}

I recently measured my HUE RGB candles and tried my hand at interpolation and symbolic regression with the data set.
interpolate_mired_brightness.ipynb - Colaboratory (google.com)
symbolic_regression_kelvin_brightness.ipynb - Colaboratory (google.com)

Unfortunately, the results are not really satisfactory so far. :frowning:
Maybe @robmarkcole can step in as our Home Assistant Date Science guy and give us some tips if he is interested? I’m sure he can give us some good advice on how best to find a mathematical formula to a given data set :slight_smile:

Possibly we also have to consider the physical basics regarding radiation energy etc. more, but this probably makes things even more complicated.

And the basic problem is, of course, the almost non-existent measured values for the individual lamp models. Maybe we can create a kind of database here via Github or something similar, where everyone can contribute their measurements and lamp models?

I did not read every comment in this thread but I suggest that measuring the power consumption (as someone reported) is the advised technique. This will give a lookup table that can be used to calc power usage under any settings

Hi @robmarkcole cool that you took a look. Thanks a lot for your feedback! Shure, a “simple” lookup table would certainly be the most accurate solution.
But that would result in a total of 34.700 measurement points with a mired range of 153-500 and a brightness range of 0%-100%, I don’t think anyone had the patience for that yet :smiley:
Therefore the Intension was, whether not with a few measuring points a formula can be found, with which one can determine the not existing measuring points.

Ah, and of course there would be even more datapoints if we count in the RGB Values of some lamps :smiley:

Just try a polynomial fit

Already dit that; power_cosumption_hue_bulbs.ipynb - Colaboratory (google.com)
But the result is not really satisfactory. Looks like we’ll have to generate a few more data points after all :smiley:

Interesting link from philips - although it doesn’t compare with the measurements, if your fit is accurate - there’s a much sharper bump in the middle. With my measurements, rather than do a exponential fit, I did a polynomial fit in excel and got an R^2 of 0.99+ for all equations (although it appears I didn’t save). I don’t think it would be that complicated to do the interpolation if the equations are plugged into a template. I’ve measured for 7 values of mired, so it’s not too complex.
A crude way could be:

  • If mired is between a and b, then
    • calculate power for the respective a and the b mired equations with a brightness of x for both
    • interpolate between the results of the two equations
  • else if mired between b and c
    • …
  • else if mired between c and d
    • …
  • else if mired between n-1 and n
    • …
  • end if