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

Python and python framework

Moderator: leecollings

Post Reply
Charger
Posts: 1
Joined: Sunday 21 October 2018 13:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post 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?
StasDemydiuk
Posts: 59
Joined: Saturday 14 January 2017 21:37
Target OS: Linux
Domoticz version: Beta
Location: Ukraine
Contact:

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

Post 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.
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
elgringo
Posts: 96
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

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

Post 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...
StasDemydiuk
Posts: 59
Joined: Saturday 14 January 2017 21:37
Target OS: Linux
Domoticz version: Beta
Location: Ukraine
Contact:

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

Post 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)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest