Page 1 of 1

Howto set color of Color switch, RGBWW, Dimmer from Python?

Posted: Sunday 21 October 2018 14:25
by Charger
I can control Yeelight color bulb from Domoticz web UI using "Color switch, RGBWW, Dimmer."
But I want to control this from the Python.
I can turn on/off the bulb and change its brighness:

Code: Select all

import DomoticzEvents as DE

device = DE.changed_device
if device.name == "Xiaomi Wireless Switch":
    DE.Log(DE.Devices["Bulb 1"].Describe())
    DE.Command('Bulb 1', 'On')
    DE.Command('Bulb 1', 'Set Level 100 AFTER 0')
The code works and print in log:

Code: Select all

ID: 1 Name: Bulb 1, Type: 241, subType: 4, switchType: 7, s_value: 24, n_value: 1, n_value_string: On, last_update_string: 2
But how to change the bulb's color? Desirable without sending HTTP requests.

I can change color via the web interface, so I believe there must be the way do this via DE.Command('Bulb 1', '...') but which command should be there?

Re: Howto set color of Color switch, RGBWW, Dimmer from Python?

Posted: Saturday 27 October 2018 17:55
by StasDemydiuk
Wow, @Charger where have you found this DomoticzEvents lib, I haven't imagine that it even exist.
I wonder if could share some docs how to use it.

Re: Howto set color of Color switch, RGBWW, Dimmer from Python?

Posted: Sunday 04 November 2018 6:43
by tixi7
Hi,

Not sure to understand your question. Do you want to update the graphical representation of the dimmer switch? or do you want to update the bulb itself?
For the former, I m looking at this also.
For the latter, you can get the rgb info from the Hue onCommand like that:

Code: Select all

color_info=json.loads(Hue)
r=color_info["r"]
g=color_info["g"]
b=color_info["b"]
m=color_info["m"]
the color mode should be equal to 3 for color request.

Re: Howto set color of Color switch, RGBWW, Dimmer from Python?

Posted: Tuesday 13 November 2018 20:19
by elgringo
I have the same problem; I want a python plugin to update a RGBWW device. I tried it via a JSON URL but the web interface remains the same...

Re: Howto set color of Color switch, RGBWW, Dimmer from Python?

Posted: Tuesday 13 November 2018 21:05
by StasDemydiuk
You can update switch color by passing Color property to Device.Update

Code: Select all

n_value = 1
s_value = '1'
color = json.dumps({
  'ColorMode': 3, #mode 3: RGB
  'r': 255,
  'g': 255,
  'b': 255
})
Devices[0].Update(nValue=n_value, sValue=s_value, Color=color)