syssi / philipslight

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

Add support for Xiaomi Philips Eyecare Smart Lamp 2 #3

Closed ghost closed 6 years ago

ghost commented 6 years ago

@syssi Please add support for Xiaomi Philips Eyecare Smart Lamp 2. It is already supported upstream and is working fine on the command line via the same python-mirobo. Next step should be integration into the home assistant panel.

Easy peasy for you as expert :)

Thanks.

syssi commented 6 years ago

If you care about some testing I will implement the additional device soon!

ghost commented 6 years ago

@syssi sure, I have a test raspberry all in one (home assistant) ready for liftoff. Lets start with the feature power on, power off.

syssi commented 6 years ago

The current implementation should support turning the lamp on and off already. Just give it a try!

ghost commented 6 years ago

Great. Thanks for your effort. I've tried it, but unfortunately I have to report to you that it does not work. The light does not show up in the home assistant panel + error warning as written below. Has been tried with Hass.io: Supervisor 0.64, Host OS 1.1, Home Assistant 0.54.

Because Xiaomi_miio.py from home assistant upstream seems to be almost the same.

Controlling the light via python-mirobo 0.2.0 on the command line is just working fine.

If the case is to use the Raspberry all in one instead of Hass.io, the exact files from your repo. Or something else. Please let me know. My test system is as always ready to liftoff.

Config:

light:
  - platform: xiaomi_miio
    name: Xiaomi Philips Eyecare Smart Lamp 2
    host: 12.12.12.16
    token: ea9405da516b567327f7ccd379116c14

Error:

Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/tasks.py", line 179, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 210, in async_add_entity
    yield from entity.async_update()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/xiaomi_miio.py", line 216, in async_update
    self.max_mireds, self.min_mireds)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/xiaomi_miio.py", line 226, in translate
    value_scaled = float(value - left_min) / float(left_span)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
syssi commented 6 years ago

You are right. The update method isn't compatible. Could you provide the output of:

mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command set_power '["off"]'
mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command get_prop '["power", "bright", "notifystatus", "ambstatus", "ambvalue", "eyecare", "scene_num", "bls", "dvalue" ]'
mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command set_power '["on"]'
mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command get_prop '["power", "bright", "notifystatus", "ambstatus", "ambvalue", "eyecare", "scene_num", "bls", "dvalue" ]'

Thanks!

PS. You are right. The light.xiaomi_miio component is the official version of this philipslight component. I will port new features as far as they are stable.

ghost commented 6 years ago

Switched back to Raspberry All in one as Hass.io is to closed to test it open and easy. Please note that Github is an open platform, so I anonymized the token. If, for whatever reason, you need the real one. Please let me know.

These are the results:

mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command set_power '["off"]'

ERROR:mirobo.vacuum_cli:Unable to read the stored msgid: [Errno 2] No such file or directory: '/tmp/python-mirobo.seq'
Sending cmd set_power with params ['off']
['ok']

Again to verify whether the error message is gone.

mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command set_power '["off"]'

Sending cmd set_power with params ['off']
['ok']

mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command get_prop '["power", "bright", "notifystatus", "ambstatus", "ambvalue", "eyecare", "scene_num", "bls", "dvalue" ]'

Sending cmd get_prop with params ['power', 'bright', 'notifystatus', 'ambstatus', 'ambvalue', 'eyecare', 'scene_num', 'bls', 'dvalue']
['off', 100, 'off', 'on', 41, 'on', 1, 'on', 0]

mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command set_power '["on"]'

Sending cmd set_power with params ['on']
['ok']

mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command get_prop '["power", "bright", "notifystatus", "ambstatus", "ambvalue", "eyecare", "scene_num", "bls", "dvalue" ]'

Sending cmd get_prop with params ['power', 'bright', 'notifystatus', 'ambstatus', 'ambvalue', 'eyecare', 'scene_num', 'bls', 'dvalue']
['on', 39, 'off', 'on', 41, 'on', 1, 'on', 0]

mirobo --ip 12.12.12.16 --token ea9405da516b567327f7ccd379116c14 raw_command set_power '["off"]'

Sending cmd set_power with params ['off']
['ok']
syssi commented 6 years ago

Thanks! The token isn't important.

ghost commented 6 years ago

Ok. Thanks for the clarification. Looking forward to your Xiaomi Philips Eyecare Smart Lamp 2 implementation.

syssi commented 6 years ago

Could you please test the current development branch: https://github.com/syssi/philipslight/tree/develop

ghost commented 6 years ago

Tested. Sorry to report but it does not work. No activity or what so ever on the home assistant states screen.

Error log:

  File "/home/homeassistant/.homeassistant/custom_components/light/xiaomi_philipslight.py", line 228, in async_update
    self._brightness = int(255 * 0.01 * state.brightness)
AttributeError: 'PhilipsEyecareStatus' object has no attribute 'brightness'

Config:

light:
  - platform: xiaomi_philipslight
    name: Xiaomi Philips Eyecare Lamp 2
    host: 12.12.12.16
    token: ea9405da516b567327f7ccd379116c14
syssi commented 6 years ago

Alright. I remember again... I'm waiting for a release of python-mirobo/python-miio. The component needs some fixes of the underlying library.

ghost commented 6 years ago

Ok. Is there a development version of python-mirobo with 'some fixes of the underlying library' available?

syssi commented 6 years ago

python-miio 0.3.0 was released tonight. The new release of the custom component supports your device!