syssi / philipslight

Xiaomi Philips Lights integration for Home Assistant
Apache License 2.0
70 stars 19 forks source link

philips.light.hbulb not working anymore supervisor-2021.12.1 #53

Closed rotrials closed 2 years ago

rotrials commented 2 years ago

Hello,

I have 2 xiaomi philips bulbs, working for one and half year. Yesterday I have updated supervisor to version 2021.12.1 and the bulbs are not working anymore. I have tried to remove them from the Xiaomi Home in order to get a new token and still nothing. Also I have tried several restarts of HA...

# configuration.yaml
light:
  - platform: xiaomi_miio_philipslight
    name: Kitchen Table
    host: 192.168.xx.xx
    token: !secret Kitchen_Table_token
    model: philips.light.bulb
# log
Logger: homeassistant.components.light
Source: custom_components/xiaomi_miio_philipslight/light.py:552
Integration: Light (documentation, issues)
First occurred: 10:23:56 PM (2 occurrences)
Last logged: 10:23:56 PM

xiaomi_miio_philipslight: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 684, in async_device_update
    await task
  File "/config/custom_components/xiaomi_miio_philipslight/light.py", line 533, in async_update
    self._color_temp = self.translate(
  File "/config/custom_components/xiaomi_miio_philipslight/light.py", line 552, in translate
    value_scaled = float(value - left_min) / float(left_span)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

Thanks

witasekl commented 2 years ago

Hi, I've noticed the same problem. And I think it's caused by the fact, that I use a model philips.light.hbulb (which is almost the same as philips.light.bulb, but it does not support light color). Someone will have to add a support for this model, which IMHO should be quite simple task. I want to try that, but I haven't found a time for that yet. Meantime you can try to use a temporary "hack": Just replace all occurences of "state.color_temperature" by a numeric value "0" in light.py. For example: sed -i 's/state.color_temperature/0/' /usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py

rotrials commented 2 years ago

@witasekl It's with the core version 2021.11.5 and with 2021.12.2 not. Anyway, it seems that this repository is not maintained anymore. My plan was to create a issue for this, to include the hbulb also. I will try your hack. On your side it's working with 2021.12.2? or not? With or without the hack? Thanks

syssi commented 2 years ago

Please don't expect updates/fixes as soon a new HA core version is released. Please contribute and help to improve this component!

rotrials commented 2 years ago

@syssi sure, sorry If I sound bossy. I only wanted you to take this into account. Unfortunately, I'm a hardware engineer and my software skills are limited otherwise I would come with the solution. Sorry for the off-topic.

rotrials commented 2 years ago

@witasekl you are a genius your command works like a charm, after a couple of days digging into the code I finally made it. It works.

@syssi it seems that this is the solution. Thanks to @witasekl

For the people which are using docker, on my side the command was: sudo sed -i 's/state.color_temperature/0/' ./var/lib/docker/overlay2/a8913dcb6909c7715b498670bddb7e60e8f873c45f59000e0efa7a75a2026107/merged/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py

syssi commented 2 years ago

Off-topic: As hardware engineer you should opt to this solution to get rid of the stock firmware: https://github.com/syssi/esphome-xiaomi-philips-light ;-)

rotrials commented 2 years ago

Mannnn!!! Yesterday I wonder if there is anot5her way to control this kind of bulb. I did not know about this repository, thanks for the hint. I will have a look over it. Best would be to make them work with zifbee2mqtt :))

syssi commented 2 years ago

The issue should be fixed in HA core 2021.12 at the official xiaomi_miio component. If this component doesn't work out of the box (must be configured via config flow) please install this custom component and give it another try. This custom component must be added to the configuration.yaml (there is no config flow available!). I've prepared a new relase.

rotrials commented 2 years ago

The issue is because 2021.12 ( until 2021.11.5 worked) I have tried to add it to configuration.yaml also, I have tried to delete it (entity and device), disable some addons which I assumed uses python-miio ... If my understanding is correctly the solution is to add philips.light.hbulb for a part of us, for others the 2021.12.2 solved this issue...

syssi commented 2 years ago

This is a workaround. In all cases the color temperature support of the device is omitted. Your device supports color temperature in general. Please update to 2021.12.2 and try the official component first. Please provide the errors from the log if it doesn't work. Next step is to use this custom component. Please provide possible errors too. Without any error logs of the most recent releases I cannot help.

rotrials commented 2 years ago
Logger: homeassistant.components.light
Source: components/xiaomi_miio/light.py:521
Integration: Light (documentation, issues)
First occurred: 1:42:26 AM (3 occurrences)
Last logged: 1:48:39 AM

xiaomi_miio: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 684, in async_device_update
    await task
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 502, in async_update
    self._color_temp = self.translate(
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 521, in translate
    value_scaled = float(value - left_min) / float(left_span)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

and

Logger: homeassistant.config_entries
Source: components/xiaomi_miio/init.py:465
First occurred: 1:48:06 AM (2 occurrences)
Last logged: 1:51:10 AM

Error unloading entry Living bulb for xiaomi_miio
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 452, in async_unload
result = await component.async_unload_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/init.py", line 465, in async_unload_entry
hass.data[DOMAIN].pop(config_entry.entry_id)
KeyError: '272d4df9994ceca5a72dd0340abf0120'
syssi commented 2 years ago

This is in both cases the official component right?

rotrials commented 2 years ago

If by component you mean xiaomi_miio, then yes. I don't know how I can use un official one. After I have updated to 2021.12.2, there were two error entries which grabbed by attention.

jekakmail commented 2 years ago

Logger: homeassistant.components.light Source: components/xiaomi_miio/light.py:521 Integration: Light (documentation, issues) First occurred: 1:42:26 AM (3 occurrences) Last logged: 1:48:39 AM

xiaomi_miio: Error on device update! Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 684, in async_device_update await task File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 502, in async_update self._color_temp = self.translate( File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 521, in translate value_scaled = float(value - left_min) / float(left_span) TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

and

Logger: homeassistant.config_entries Source: components/xiaomi_miio/init.py:465 First occurred: 1:48:06 AM (2 occurrences) Last logged: 1:51:10 AM

Error unloading entry Living bulb for xiaomi_miio Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 452, in async_unload result = await component.async_unload_entry(hass, self) # type: ignore File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/init.py", line 465, in async_unload_entry hass.data[DOMAIN].pop(config_entry.entry_id) KeyError: '272d4df9994ceca5a72dd0340abf0120'

I've the same issue. After upgrade to 2021.12.1, 2021.12.2 and 2012.12.3, log got 2 errors. Rollback to 2021.11.5 solved problem

syssi commented 2 years ago

I've made a fresh HA core installation (2021.12.3) and added a philips.light.candle via the xiaomi_miio integration. The device cannot be auto-discovered because it's not advertised at the network. I've used the IP address and token at the config flow without issues.

syssi commented 2 years ago

Could everybody make sure HA core 2012.12.3 is in use and there are no custom_components in place which requires an outdated python-miio version? Please check all manifest.jsons of the custom_components folder.

This is fine:

{
  [...]
  "requirements": [
    "construct==2.10.56",
    "python-miio>=0.5.9.2"
  ],
[...]

This would downgrade the python-miio version on HA startup:

{
  [...]
  "requirements": [
    "construct==2.10.56",
    "python-miio>=0.5.8"
  ],
[...]
Benny2102 commented 2 years ago

@witasekl zseni vagy a parancsod úgy működik, mint egy bűbáj, pár napos beleásás után a kódba végre sikerült. Működik.

@syssi úgy tűnik, ez a megoldás. Köszönöm @witasekl

A dockert használók számára a parancs a következő volt: sudo sed -i 's/state.color_temperature/0/' ./var/lib/docker/overlay2/a8913dcb6909c7715b498670bddb7e60e8f873c45f5ahosimers /components/xiaomi_miio/light.py

It works, thanks (HA OS - philips.light.bulb).

rotrials commented 2 years ago

I updated to 2021.12.3 and I got the same error on the bulbs.

I made a search for "pythin-miio" under "component" and I found only this:

{
  "domain": "xiaomi_miio",
  "name": "Xiaomi Miio",
  "config_flow": true,
  "documentation": "https://www.home-assistant.io/integrations/xiaomi_miio",
  "requirements": ["construct==2.10.56", "micloud==0.4", "**python-miio==0.5.9.2**"],
  "codeowners": ["@rytilahti", "@syssi", "@starkillerOG", "@bieniu"],
  "zeroconf": ["_miio._udp.local."],
  "iot_class": "local_polling"
}

I check the "custom_components" folder and I found under for "miio_yeelight" the following:

  "requirements": [
    "construct==2.10.56",
    "python-miio>=0.5.6"

This could be the problem...

And for xiaomi_cloud_map_extractor I found:

  "requirements": [
    "pillow",
    "pybase64",
    "python-miio",
    "requests"

rotrials commented 2 years ago
  1. I have changed the "python-miio>=0.5.6" to "python-miio>=0.5.9.2" for miio_yeelight
  2. I keept ""requirements": ["construct==2.10.56", "micloud==0.4", "python-miio==0.5.9.2"]," from xiaomi_miio
  3. I have reseted the light.py from /usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py to default value (no 0 isntead of state.color_temperature)

And the result is the same, my 2 bulbs entities are unavailable again.

-------------after first restart------------------

Logger: homeassistant.components.light
Source: components/xiaomi_miio/light.py:521
Integration: Light (documentation, issues)
First occurred: 1:01:00 AM (2 occurrences)
Last logged: 1:01:00 AM

xiaomi_miio: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 684, in async_device_update
    await task
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 502, in async_update
    self._color_temp = self.translate(
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 521, in translate
    value_scaled = float(value - left_min) / float(left_span)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

-----------after second restart -------------------

Logger: homeassistant.helpers.service
Source: helpers/service.py:129
First occurred: 1:07:36 AM (2 occurrences)
Last logged: 1:07:37 AM

Unable to find referenced entities light.living_bulb
rotrials commented 2 years ago

I've made a fresh HA core installation (2021.12.3) and added a philips.light.candle via the xiaomi_miio integration. The device cannot be auto-discovered because it's not advertised at the network. I've used the IP address and token at the config flow without issues.

Should I try to add the my bulbs to the configuration.yaml?

syssi commented 2 years ago

Did you restart your HA after doing the changes? Could you SSH into the HA container and check the installated python-miio version? I can provide some instructions if needed.

rotrials commented 2 years ago

Of course I have restarted. I have not found any python miio on my containers :(

syssi commented 2 years ago

There is one for sure. ;-) Please SSH into the HA core container and search for airconditioningcompanion.py:

find / -name airconditioningcompanion.py

Please provide the hits. If there are none you are in the wrong container.

witasekl commented 2 years ago

@rotrials could you please verify, what's your bulb model? Is it philips.light.bulb or philips.light.hbulb? If it's philips.light.hbulb, I've tried to prepare a draft for supporting of this model: https://github.com/witasekl/core/commit/018545b3cf4fda342a6e06754ee9242280c853f7 This is not PR yet. Please be lenient I'm not a Python developer. I would appreciate any feedback. You can adopt this as you wish. I haven't managed to do all the PR ceremonies yet.

syssi commented 2 years ago

This is a very good idea. The exact device model can be retrieved by:

miiocli device --ip <IP> --token <TOKEN> info
rotrials commented 2 years ago

There is one for sure. ;-) Please SSH into the HA core container and search for airconditioningcompanion.py:

find / -name airconditioningcompanion.py

Please provide the hits. If there are none you are in the wrong container.

I agree there should be a python-miio, otherwise it cannot work, but I was not able to find it...

/var/lib/private/hass/deps/lib/python3.9/site-packages/miio/airconditioningcompanion.py
/var/lib/docker/overlay2/34e6313e1a73b21aa389d5775be4f05f61a8e0061f06538d3c6700027011c990/merged/usr/local/lib/python3.9/site-packages/miio/airconditioningcompanion.py
/var/lib/docker/overlay2/dcb96f32e75c8d43136a440cd10920f6e39384715f66abd52c9beaef2b38fa4e/diff/usr/local/lib/python3.9/site-packages/miio/airconditioningcompanion.py
/var/lib/docker/overlay2/673d1943ba789864350c049fb4327bd860e7e01ec725fe90a02a04ec19278a74/diff/usr/local/lib/python3.9/site-packages/miio/airconditioningcompanion.py

The good one I think it's in the merged folder... What is this file?

Thanks

rotrials commented 2 years ago

ou please verify, what's your bulb model? Is it philips.light.bulb or philips

Normally it's detected as a philips.light.hbulb by the XiaomiGatewat3 integration (and also a hbulb by xiaomii_miio) . First of all, thanks a lot for the PR... Let me know what kind of feedback you need, or how can I help.

I will try to integrate your PR, but first I have to understand how. I think I can overwrite the the following file: homeassistant/components/xiaomi_miio/const.py and homeassistant/components/xiaomi_miio/light.py right?

later edit: I have overwrite the 2 files and my two bulbs are not working, should I delete the device and entity? and reassigned them back?

Log details:

Logger: homeassistant.components.light
Source: components/xiaomi_miio/light.py:525
Integration: Light (documentation, issues)
First occurred: 11:09:00 PM (2 occurrences)
Last logged: 11:09:00 PM

xiaomi_miio: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 684, in async_device_update
    await task
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 506, in async_update
    self._color_temp = self.translate(
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/light.py", line 525, in translate
    value_scaled = float(value - left_min) / float(left_span)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
rotrials commented 2 years ago

sorry, the miiocli is not working on the ssh. (-bash: miiocli: command not found) Am I doing something wrong?

My system is an Odroid H2 (Intel Celeron CPU) with arch linux. Running home assistant on a docker. Probably this should be specified in the first post.

syssi commented 2 years ago

Let's continue here. ;-) @rotrials owns a hbulb which isn't supported right now. This device doesn't support color temperature so it's no surprise this feature is failing at the moment.

rotrials commented 2 years ago

before it worked. Anyway, is it in plan to implement it? Thanks

for the people which are reaching this post, you can use philips.light.mono1 (see https://github.com/rytilahti/python-miio/issues/1231#issuecomment-994917740)

syssi commented 2 years ago

Please install this custom component. The hbulb is supported now.

syssi commented 2 years ago

@rotrials Could you provide a photo or all details of the device type label? I would like to add some details about the device to the docs.

syssi commented 2 years ago

@witasekl Thanks for your support here. It was hard to understand you was always on right track. :-)

rotrials commented 2 years ago

@rotrials Could you provide a photo or all details of the device type label? I would like to add some details about the device to the docs. 20211220_223734_1

syssi commented 2 years ago

I've extended the README.