Manually calculating power consumption of lights

@tbloth, when you say ‘it has no state’, what do you mean? Do you mean that the state is only real time and not available in history?

From the macro:

What I mean by that is, how would you build a history_stats out of

sum_power_consumption_lights:

Aaand, here is my second dataset: bulbs_consumption_values/lct012_hue.csv at main · CM000n/bulbs_consumption_values (github.com) :slight_smile:

This time it’s for a Philips Hue White & Color Candle and includes power consuption based on brigthness, hue & saturation. Otherwise, I think I will first carry out measurements for mired values, as this is used more frequently in our home. Coloured light is hardly ever used.

Hi @CM000n , that is an awesome list, and all for just one build too

Nope, only brightness it seems.

For the basic white dimmable bulbs which is the majority of what I have, a straight forward maths formula , that calculates that calculate the wattage based on the brightness level (0-255) would be very handy (if anyone knows how to do that)

@CM000n Right now I have a test setup using a Shelly smartplug (with power measuring) and taking measurements for the Philips Hue White Ambiance color (LCT010).
I am not using home assistant but made a python script using aioshelly and aiohue directly.
Also I used hue range 0-65535 and saturation 0-254 as this is in line with the Philips Hue API. We could alter your CSV files to convert to the Hue format, or my CSV to hass format when I’m done.
I take 25x32x25 measurements with 2 seconds interval which is 40.000 second total (will take approx 5~6 hours)

I have also made a start with a custom component which will calculate the power consumption real time based on brightness, mired and hs values of existing hue lights.
Right now it will set the power to 0 when the light is off and the power to the brightness level when it is on. Obviously we need to implement logic to calculate real power usage from lookup tables based on the particular hue model.
But at least this is a start.

1 Like

That’s some great work! Can’t wait to have the consumption of all my lights in HA, those are some of the last pieces I’m missing now.

Thanks. I have worked for a few hours today to get the power calculation algorithm working using lookup tables. Got a first version working now on my machine.
We still need to have a lot of CSV files with the consumption data of different models. For now we have half support for LCT012 (provided by @CM000n) and LCT010 (I am actively taking measurement now, almost complete). For both models we have Brightness/Hue/Saturation measurements now, however we also need measurements for Brightness/ColorTemp (mired) combinations. @CM000n could you do that for LCT012?
I have some more models which I am going to measure (Hue Go, Hue being, Hue GU10 white ambiance etc.)
@jatd which hue light models do you have in your home?

1 Like

Shure. Think I can start a mired test for the LCT012 tomorrow

1 Like

My custom integration is working and ready for beta testing. Also added support for LTW001.
Please let me know if there are any issues.

Hue White and Color Ambiance Spot GU10 (LCT003) measurements for color temperature mode are also done and included in the integration. Now I am starting with color measurements. This will take 13 hours.

1 Like

Excellent work @CM000n and @bramski!

@bramski, I’ve had an error come up, I assume one for each light. I’m running the lights with a zigbee USB stick, so no Hue.

sensors - lights.yaml

- platform: huepower
  entity_id: light.bedroom_ceiling_light
  model: LTW001
- platform: huepower
  entity_id: light.bedroom_lamp
  model: LTW001
- platform: huepower
  entity_id: light.living_room_big_lamp
  model: LTW001
- platform: huepower
  entity_id: light.living_room_ceiling_light
  model: LTW001
- platform: huepower
  entity_id: light.living_room_small_lamp
  model: LTW001
- platform: huepower
  entity_id: light.desk_lamp
  model: LCT012
2021-06-06 22:28:59 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up huepower platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/huepower/sensor.py", line 61, in async_setup_platform
    light = await find_hue_light(hass, entity_entry)
  File "/config/custom_components/huepower/sensor.py", line 102, in find_hue_light
    bridge = hass.data[HUE_DOMAIN][entity_entry.config_entry_id]
KeyError: 'hue'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/huepower/sensor.py", line 61, in async_setup_platform
    light = await find_hue_light(hass, entity_entry)
  File "/config/custom_components/huepower/sensor.py", line 102, in find_hue_light
    bridge = hass.data[HUE_DOMAIN][entity_entry.config_entry_id]
KeyError: 'hue'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/huepower/sensor.py", line 61, in async_setup_platform
    light = await find_hue_light(hass, entity_entry)
  File "/config/custom_components/huepower/sensor.py", line 102, in find_hue_light
    bridge = hass.data[HUE_DOMAIN][entity_entry.config_entry_id]
KeyError: 'hue'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/huepower/sensor.py", line 61, in async_setup_platform
    light = await find_hue_light(hass, entity_entry)
  File "/config/custom_components/huepower/sensor.py", line 102, in find_hue_light
    bridge = hass.data[HUE_DOMAIN][entity_entry.config_entry_id]
KeyError: 'hue'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/huepower/sensor.py", line 61, in async_setup_platform
    light = await find_hue_light(hass, entity_entry)
  File "/config/custom_components/huepower/sensor.py", line 102, in find_hue_light
    bridge = hass.data[HUE_DOMAIN][entity_entry.config_entry_id]
KeyError: 'hue'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/huepower/sensor.py", line 61, in async_setup_platform
    light = await find_hue_light(hass, entity_entry)
  File "/config/custom_components/huepower/sensor.py", line 102, in find_hue_light
    bridge = hass.data[HUE_DOMAIN][entity_entry.config_entry_id]
KeyError: 'hue'

Yes, I made the module dependant on the philips hue integration, to auto discover the light models by checking the Hue bridge. so this error is expected in your situation. Maybe I can make this optional so it will also work for your case. Will have a look soon.

I have made some modifications to also make the integration work when you don’t use the Philips Hue integration.
COuld you try again? Also check the Readme, because you also need to supply a manufacturer now.

Progress…I’m off to bed, so I’ll see how you’re travelling tomorrow.

2021-06-07 00:15:57 INFO (MainThread) [homeassistant.setup] Setting up huepower
2021-06-07 00:15:57 INFO (MainThread) [homeassistant.setup] Setup of domain huepower took 0.0 seconds
2021-06-07 00:15:57 INFO (MainThread) [custom_components.eventsensor.sensor] Added event listener for 'hue_event'
2021-06-07 00:15:57 INFO (MainThread) [custom_components.eventsensor.sensor] sensor.eventsensor: Added sensor listening to 'hue_event' with event data: {}
2021-06-07 00:15:57 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.huepower
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Manufacturer not supplied for entity: light.bedroom_ceiling_light
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Light not supported: ('Model not found in data directory', 'LTW001')
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Manufacturer not supplied for entity: light.bedroom_lamp
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Manufacturer not supplied for entity: light.living_room_big_lamp
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Manufacturer not supplied for entity: light.living_room_ceiling_light
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Manufacturer not supplied for entity: light.living_room_small_lamp
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Manufacturer not supplied for entity: light.desk_lamp
2021-06-07 00:15:57 ERROR (MainThread) [custom_components.huepower.sensor] Light not supported: ('Model not found in data directory', 'LCT012')

Did you update your config to also include the manufacturer? i.e.:

- platform: huepower
  entity_id: light.bedroom_ceiling_light
  manufacturer: signify
  model: LTW001

I have also added extra debug logging.
Please update the component and enable logging, than hopefully we can figure out what is missing.

logger:
  default: warning
  logs:
    custom_components.huepower: debug

I was too excited and missed the manufacturer part :slight_smile:

I’ve updated the component and have the following logs - no sensor is visible in the developer tools.

2021-06-07 19:36:26 INFO (MainThread) [homeassistant.setup] Setting up huepower
2021-06-07 19:36:26 INFO (MainThread) [homeassistant.setup] Setup of domain huepower took 0.0 seconds
2021-06-07 19:36:26 INFO (MainThread) [custom_components.eventsensor.sensor] Added event listener for 'hue_event'
2021-06-07 19:36:26 INFO (MainThread) [custom_components.eventsensor.sensor] sensor.eventsensor: Added sensor listening to 'hue_event' with event data: {}
2021-06-07 19:36:26 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.huepower
2021-06-07 19:36:26 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.huepower
2021-06-07 19:36:26 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.huepower
2021-06-07 19:36:26 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.huepower
2021-06-07 19:36:26 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.huepower
2021-06-07 19:36:26 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.huepower
2021-06-07 19:36:26 ERROR (MainThread) [custom_components.huepower.sensor] Light not supported: ('No lookup file found for mode', 'color_temp')

2021-06-07 19:36:57 DEBUG (MainThread) [custom_components.huepower] Looking up power usage for bri:112 mired:454
2021-06-07 19:36:57 DEBUG (MainThread) [custom_components.huepower] Power:2.61
2021-06-07 19:36:57 DEBUG (MainThread) [custom_components.huepower] Looking up power usage for bri:112 mired:454
2021-06-07 19:36:57 DEBUG (MainThread) [custom_components.huepower] Power:2.61
2021-06-07 19:36:57 DEBUG (MainThread) [custom_components.huepower] Looking up power usage for bri:112 mired:454
2021-06-07 19:36:57 DEBUG (MainThread) [custom_components.huepower] Power:2.61

And FYI, these are the attributes of the lights:

LCT012 - temperature mode

min_mireds: 153
max_mireds: 500
effect_list:
  - colorloop
supported_color_modes:
  - color_temp
  - hs
color_mode: color_temp
brightness: 106
color_temp: 500
off_brightness: null
friendly_name: Desk Lamp
icon: mdi:desk-lamp
supported_features: 63

LCT012 - colour mode

min_mireds: 153
max_mireds: 500
effect_list:
  - colorloop
supported_color_modes:
  - color_temp
  - hs
color_mode: hs
brightness: 102
hs_color:
  - 29.834
  - 70.98
rgb_color:
  - 255
  - 163
  - 74
xy_color:
  - 0.539
  - 0.392
off_brightness: null
friendly_name: Desk Lamp
icon: mdi:desk-lamp
supported_features: 63

LTW001

min_mireds: 153
max_mireds: 454
supported_color_modes:
  - color_temp
color_mode: color_temp
brightness: 105
color_temp: 454
off_brightness: null
friendly_name: Living Room Ceiling Light
icon: mdi:globe-light
supported_features: 43