bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
971 stars 258 forks source link

LUT file support for only brightness mode #14

Closed bramstroker closed 3 years ago

bramstroker commented 3 years ago

Support for lights having only brightness mode (no color temp or hs modes). For example LWA001 only supports brightness

nepozs commented 3 years ago

LWB010 also has brightness only.

bramstroker commented 3 years ago

@nepozs I have bought a Hue filament light which also have only brightness. This will be delivered next monday. Than I can check if this works with the component or I need to do any changes in the code.

Regarding LWB010. Are you able to measure this light and provide a LUT file? I don't have this light so I cannot do it.

nepozs commented 3 years ago

I can do it only manually, so it will take lots of time, but I'll try to prepare it. I have also LWB004 (very old version named Hue Lux).

bramstroker commented 3 years ago

@nepozs for only brightness mode I would advice to take measurements for steps of 5 brightness. Brightness is from 1 to 255. So take measurements for 1, 6, 11, 16 etc. This would be like 51 data points, which is doable manually. For the Hue/saturation mode we take 40.000 measurements. Imagine doing those manually 😂😂

nepozs commented 3 years ago

I've prepared them with 100 datapoints because the bulbs have nonlinear characteristic (it is maximum doable by hand :P with 1% brighness incerement using HA interface, so they are real use datapoints), I've created pull request with files (hope they will be useable).

BTW I'm using also many Ikea bulbs, some Ligtify/Osram, Jaiawen (Feibit) and innr, but without possibility to automate measurments I'm able to measure only dimmable models, but I don't know proper directory structure to do it. From Philips Hue family I have also LTW010 (White Ambiance E27) and LLC011 (Living Colours Bloom), but they need automated measurment.

bramstroker commented 3 years ago

Thanks for doing the measurements for LWB001 and LWB010, this will also help others.

To determine the correct directory structure fir the other manufacturers could you try the following?

Now check the debug log, there should be some line "Auto discovered Hue model for entity". There you can see the manufacturer and model which are provided by the Hue bridge. Not sure if they are specific enough for the other lights yet. But we will find out.

About automatically measuring. There is a script included in the utils/measure folder, which I am using. I am using a Shelly S smartplug (it's a wifi plug), they are "only" like 20 Euro in dutch shop. When you get that one you need to modify the file measure.py for the smartplug IP address and than run the script python3 measure.py. Alternatively you can wait for others to do those light models (but maybe it never happens), or use the linear mode (to get a approximation).

nepozs commented 3 years ago

I'm not a programmer, but I understand spirit of open-source :D and I've seen this script before, so I have plans - Shelly Plug S sounds good,, in Poland it is slightly more expensive, but it is also available on Amazon.

It looks like brightness only LUT needs some code change

2021-06-21 17:54:43 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up powercalc 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/powercalc/sensor.py", line 127, in async_setup_platform
    await calculation_strategy.validate_config(entity_entry)
  File "/config/custom_components/powercalc/strategy_lut.py", line 135, in validate_config
    await self._lut_registry.get_lookup_dictionary(self._model, color_mode)
  File "/config/custom_components/powercalc/strategy_lut.py", line 49, in get_lookup_dictionary
    lookup_dict[int(row[0])][int(row[1])] = float(row[2])
IndexError: list index out of range

And one more thing - should directory be first word from full name of manufacturer? I can see e.g Signify Netherlands B.V. an directory is signify, so should next directories be osram and ikea?

2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.kuchnia1: (manufacturer=IKEA of Sweden, model=TRADFRI bulb E27 opal 1000lm)
2021-06-21 13:59:07 INFO (MainThread) [custom_components.powercalc.sensor] Model not found in library light.kuchnia1: ('Model not supported', 'TRADFRI bulb E27 opal 1000lm')
2021-06-21 13:59:07 ERROR (MainThread) [custom_components.powercalc.sensor] Skipping sensor setup light.kuchnia1: Cannot select a mode (LINEAR, FIXED or LUT), supply it in the config
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.lampka_biurkowa_biala: (manufacturer=Signify Netherlands B.V., model=LWB004)
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.strategy_lut] Loading data file: /config/custom_components/powercalc/data/signify/LWB004/brightness.csv.gz
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.zyrandol_tv_k: (manufacturer=Signify Netherlands B.V., model=LWB010)
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.strategy_lut] Loading data file: /config/custom_components/powercalc/data/signify/LWB010/brightness.csv.gz
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.wentylator: (manufacturer=OSRAM, model=Plug 01)
2021-06-21 13:59:07 INFO (MainThread) [custom_components.powercalc.sensor] Model not found in library light.wentylator: ('Model not supported', 'Plug 01')
bramstroker commented 3 years ago

I'm not a programmer, but I understand spirit of open-source :D and I've seen this script before, so I have plans - Shelly Plug S sounds good,, in Poland it is slightly more expensive, but it is also available on Amazon.

Cool, you have to start somewhere ;-). Let me know if you have any problems with te script. I have added support for brightness to the measure script as well

It looks like brightness only LUT needs some code change

2021-06-21 17:54:43 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up powercalc 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/powercalc/sensor.py", line 127, in async_setup_platform
    await calculation_strategy.validate_config(entity_entry)
  File "/config/custom_components/powercalc/strategy_lut.py", line 135, in validate_config
    await self._lut_registry.get_lookup_dictionary(self._model, color_mode)
  File "/config/custom_components/powercalc/strategy_lut.py", line 49, in get_lookup_dictionary
    lookup_dict[int(row[0])][int(row[1])] = float(row[2])
IndexError: list index out of range

Yes, I had the same error when testing with the Filament bulb that was just delivered at my place. Just made the necessary changes to the code to support brightness only mode. Will make a new release 0.1.4 in next 10 minutes. Also did the measurements for LWA004.

And one more thing - should directory be first word from full name of manufacturer? I can see e.g Signify Netherlands B.V. an directory is signify, so should next directories be osram and ikea?

2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.kuchnia1: (manufacturer=IKEA of Sweden, model=TRADFRI bulb E27 opal 1000lm)
2021-06-21 13:59:07 INFO (MainThread) [custom_components.powercalc.sensor] Model not found in library light.kuchnia1: ('Model not supported', 'TRADFRI bulb E27 opal 1000lm')
2021-06-21 13:59:07 ERROR (MainThread) [custom_components.powercalc.sensor] Skipping sensor setup light.kuchnia1: Cannot select a mode (LINEAR, FIXED or LUT), supply it in the config
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.lampka_biurkowa_biala: (manufacturer=Signify Netherlands B.V., model=LWB004)
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.strategy_lut] Loading data file: /config/custom_components/powercalc/data/signify/LWB004/brightness.csv.gz
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.zyrandol_tv_k: (manufacturer=Signify Netherlands B.V., model=LWB010)
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.strategy_lut] Loading data file: /config/custom_components/powercalc/data/signify/LWB010/brightness.csv.gz
2021-06-21 13:59:07 DEBUG (MainThread) [custom_components.powercalc.sensor] Auto discovered Hue model for entity light.wentylator: (manufacturer=OSRAM, model=Plug 01)
2021-06-21 13:59:07 INFO (MainThread) [custom_components.powercalc.sensor] Model not found in library light.wentylator: ('Model not supported', 'Plug 01')

For the Signify manufacturer I made a mapping in code so the directory name does not need any uppercase characters and dots etc. See this line of code We can do the same for osram and ikea. However I am not sure yet about the models, need to think about that some more. I was hoping they had some unique model id like the Hue lights, to diffentiate them. Especially the Osram is identified as "Plug 1", not sure what that is about. Is it a light bulb or a smart plug?

bramstroker commented 3 years ago

Actually these model id's are zigbee id's. You can find them here: https://zigbee.blakadder.com/search.html

You can use exactly the same model id as listed in the logs as directory name. So keep the casing the same and spacing. So the structure will look like this

- data
  - ikea
    - TRADFRI bulb E27 opal 1000lm
      - color_temp.csv.gz

The Osram Plug 1 seems te be a smart plug. We cannot include this LUT file in the repository as everyone will have another appliance attached to the plug with other power consumption. Is this plug dimmable or only on/off? When it is not dimmable a LUT file would not make any sense, and you could just use the fixed mode.

nepozs commented 3 years ago

The Osram Plug 1 seems te be a smart plug. We cannot include this LUT file in the repository as everyone will have another appliance attached to the plug with other power consumption.

Osram Plug was first device I've tested, it is not dimmable (so LUT method of course is not proper), but I've made some observation - it itself uses 0.44W when off and 0.98W when on, so for future this integration could provide ready made database also for devices like that (it just could be simple definition, so user in configuration.yaml could provide only load wattage (without smart plug).

Let me know if you have any problems with te script. I have added support for brightness to the measure script as well

I don't have hardware like Shelly Plug (so I can measure "by hand" dimmable lights only, like TRADFRI bulb E27 opal 1000lm because I own Zhurui PR10 which is manual only), so I can't test script now.

For the Signify manufacturer I made a mapping in code so the directory name does not need any uppercase characters and dots etc.

If upper/lower case is so important I've prepared 2 lines in const.py

But as I know all Ikea Tradfri models (Zigbee hardware) look similar like this one - so any change rather is impossible (when I'll be able to provide LUT for more models ) so in case of models mapppings are rather excluded.

bramstroker commented 3 years ago

Osram Plug was first device I've tested, it is not dimmable (so LUT method of course is not proper), but I've made some observation - it itself uses 0.44W when off and 0.98W when on, so for future this integration could provide ready made database also for devices like that (it just could be simple definition, so user in configuration.yaml could provide only load wattage (without smart plug).

It's not supported yet to only supply standby usage in the model library/database, and I don't think I will support that because it needs a lot of code refactoring (changes in the code). You can simply define like this:

sensor:
  - platform: powercalc
    entity_id: light.outdoor_light
    mode: fixed
    watt: 0.98
    standby_usage: 0.44

Let me know if you have any problems with te script. I have added support for brightness to the measure script as well

I don't have hardware like Shelly Plug (so I can measure "by hand" dimmable lights only, like TRADFRI bulb E27 opal 1000lm because I own Zhurui PR10 which is manual only), so I can't test script now.

The "TRADFRI bulb E27 opal 1000lm" seem to be a light where you can modify the color temperature. If this is the case you will need to measure different brightness levels and different mireds (color temperatures). This would be like 600-1000 data points, which is too much to do manual I assume.

For the Signify manufacturer I made a mapping in code so the directory name does not need any uppercase characters and dots etc.

If upper/lower case is so important I've prepared 2 lines in const.py

But as I know all Ikea Tradfri models (Zigbee hardware) look similar like this one - so any change rather is impossible (when I'll be able to provide LUT for more models ) so in case of models mapppings are rather excluded.

I have read this sentence multiple times, but I don't really understand what you mean, sorry. Could you elaborate?

nepozs commented 3 years ago

The "TRADFRI bulb E27 opal 1000lm" seem to be a light where you can modify the color temperature.

I'm sure it is brightness only, Model with color temperature has added 2 letters inside - I will check it in a minutes. Edit: TRADFRI bulb E27 WS opal 1000lm has color temperature, but it is different model.

I have read this sentence multiple times, but I don't really understand what you mean, sorry. Could you elaborate?

I've missed quote:

I was hoping they had some unique model id like the Hue lights, to diffentiate them.

but in short - names of Ikea models must be very long.

bramstroker commented 3 years ago
Screenshot 2021-06-21 at 22 56 05

You can just use the full zigbee ID as the folder name for the model. The zigbee id will be unique for every light. It does not matter that it is rather long, but it need to be exact.

bramstroker commented 3 years ago

The "TRADFRI bulb E27 opal 1000lm" seem to be a light where you can modify the color temperature.

I'm sure it is brightness only, Model with color temperature has added 2 letters inside - I will check it in a minutes. Edit: TRADFRI bulb E27 WS opal 1000lm has color temperature, but it is different model.

Ok nice. Than you can do that one manual and get the light supported in the database