syssi / philipslight

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

Add RGB support to the Moonlight #21

Closed syssi closed 5 years ago

syssi commented 5 years ago

Added.

syssi commented 5 years ago

@jake661 You've reported the following issue: Setting color failed: {'code': -5001, 'message': 'param error'}

Thanks for your support! Could you enable the debug output of the component and provide some logs? I'm looking for the miIO request set_rgb and your response (param error):

Just enable the logger:

logger:
  default: warn
  logs:
    custom_components.light.xiaomi_miio: debug
    miio: info

And provide the content of your home-assistant.log

jake661 commented 5 years ago

Glad to help, thanks for your work! I'm attempting to set the color using the native HA color.py utility. Curious if sertting the color this way is supported? Here is the requested debug log output:

2018-12-10 07:32:08 DEBUG (MainThread) [custom_components.light.xiaomi_miio] Got new state: <PhilipsMoonlightStatus power=on, brightness=85, color_temperature=22, rgb=(240, 10, 255), scene=0> 2018-12-10 07:32:08 DEBUG (MainThread) [custom_components.light.xiaomi_miio] Setting color: <module 'homeassistant.util.color' from '/usr/src/app/homeassistant/util/color.py'> 2018-12-10 07:32:08 ERROR (MainThread) [custom_components.light.xiaomi_miio] Setting color failed: {'code': -5001, 'message': 'param error'} cct"

Screenshot of color.py utility: image

syssi commented 5 years ago

This is a bug! I will care about.

syssi commented 5 years ago

I've fixed the log message. Could you update this configuration to:

logger:
  default: warn
  logs:
    custom_components.light.xiaomi_miio: debug
    miio: info

I'm looking for this lines:

2018-12-11 08:33:36 DEBUG (MainThread) [custom_components.light.xiaomi_miio] Setting color: (255, 0, 0)
2018-12-11 08:33:36 DEBUG (Thread-5) [miio.device] 192.168.130.80:54321 >>: {'method': 'set_rgb', 'id': 4, 'params': [16711680]}
2018-12-11 08:33:36 DEBUG (Thread-5) [miio.device] 192.168.130.80:54321 (ts: 1970-01-01 00:12:51, id: 4) << {'id': 4, 'error': ... }
2018-12-11 08:33:36 ERROR (MainThread) [custom_components.light.xiaomi_miio] Setting color failed: ...
jake661 commented 5 years ago

Thanks for looking into this. Here are the requested debug logs:

2018-12-11 12:14:08 DEBUG (MainThread) [custom_components.light.xiaomi_miio] Setting color: (0, 127, 255)
2018-12-11 12:14:08 DEBUG (SyncWorker_8) [miio.device] 192.168.29.8:54321 >>: {'id': 18, 'method': 'set_rgb', 'params': [32767]}
2018-12-11 12:14:08 DEBUG (SyncWorker_8) [miio.device] 192.168.29.8:54321 (ts: 1970-01-11 19:22:21, id: 18) << {'error': {'code': -5001, 'message': 'param error'}, 'id': 18}
2018-12-11 12:14:08 ERROR (MainThread) [custom_components.light.xiaomi_miio] Setting color failed: {'code': -5001, 'message': 'param error'}
syssi commented 5 years ago

Cool. I know what's going on here. Could you try to control the light by the miiocli command line tool (part of python-miio: pip3 install python-miio):

miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
miiocli device --ip IP --token TOKEN raw_command set_rgb "[255,255,255]"
miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
miiocli device --ip IP --token TOKEN raw_command set_rgb "[255,0,0]"
miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
miiocli device --ip IP --token TOKEN raw_command set_rgb "[0,255,0]"
miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
miiocli device --ip IP --token TOKEN raw_command set_rgb "[0,0,255]"
miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"

Please provide the output of each command.

jake661 commented 5 years ago

Here you go:

miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
Running command raw_command
[15731455]

miiocli device --ip IP --token TOKEN raw_command set_rgb "[255,255,255]"
Running command raw_command
['ok']

miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
Running command raw_command
[16777215]

miiocli device --ip IP --token TOKEN raw_command set_rgb "[255,0,0]"
Running command raw_command
['ok']

miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
Running command raw_command
[16711680]

miiocli device --ip IP --token TOKEN raw_command set_rgb "[0,255,0]"
Running command raw_command
['ok']

miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
Running command raw_command
[65280]

miiocli device --ip IP --token TOKEN raw_command set_rgb "[0,0,255]"
Running command raw_command
['ok']

miiocli device --ip IP --token TOKEN raw_command get_prop "['rgb']"
Running command raw_command
[255]
syssi commented 5 years ago

Perfect! I've updated the component. Plesse give it a try.

jake661 commented 5 years ago

Excellent, confirmed working now! Thanks again!

syssi commented 5 years ago

Awesome!