Yeelights Scene Selector (RGBW)

Moderator: leecollings

Post Reply
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Yeelights Scene Selector (RGBW)

Post by DewGew »

I made a script to select a custom scene for my Yeelight Color bulbs. Works with multiple bulbs.
Premade scenes in the script is: Sunrise, Sunset, Calm, Alarm, Notify, Police 1, Police 2, Candle Flicker, Birthday Party.

Creata a dummy selector switch.
Copy script below to Eventseditor.
Change settings part to suit your needs.
Add level names to selector switch.

Code: Select all

--[[
    Yeelight Scene Selector
    Project: Domoticz
    Interpreter: dzVents, Device
    Author: DewGew
    Version: 20190308
]]--
-- Settings
local selector= 123 --Selector Switch IDX
local yeelights = {'192.168.xxx.xxx', '192.168.xxx.xx'} -- yeelights ipnumbers
local port = '55443'
-- Put the level names here:
local level10 = 'Sunrise'
local level20 = 'Sunset'
local level30 = 'Calm'
local level40 = 'Alarm'
local level50 = 'Notify'
local level60 = 'Police 1'
local level70 = 'Police 2'
local level80 = 'Candle'
local level90 = 'Birthday Party'
-- End Settings

local sunrise = '[\"cf\",2,1,\"50,2,4000,1,900000,2,4000,100\"]'
local sunset = '[\"cf\",2,2,\"50,2,4000,75,900000,2,4000,1\"]'
local alarm = '[\"cf\",0,0,\"500,1,16711696,100,500,1,16711696,10\"]'
local calm = '[\"cf",0,0,\"2000,1,255,70,2000,1,255,100,5000,1,255,70,3000,1,13369548,100,3000,1,13369548,10\"]'
local notify = '[\"cf",0,0,\"1000,2,2700,100,1000,7,0,0,1000,2,2700,10,1000,7,0,0\"]'
local police_1 = '[\"cf",0,0,\"1000,1,1002236,100,1000,7,0,0,1000,1,16711696,10,1000,7,0,0\"]'
local police_2 = '[\"cf",0, 0,\"1000,1,1002236,100,1000,1,1002236,10,1000,1,16711696,50,1000,1,1002236,30,1000,7,0,0,1000,1,16711696,10,1000,7,0,0\"]'
local candle_flicker = '[\"cf",0,0,\"800,2,2700,50,800,2,2700,30,1200,2,2700,80,800,2,2700,60,1200,2,2700,90,2400,2,2700,50,1200,2,2700,80,800,2,2700,60,400,2,2700,70\"]'
local birthday_party = '[\"cf",0,0,\"1996,1,14438425,80,1996,1,14448670,80,1996,1,11153940,80\"]'

return {
    on = {
        devices = {selector}
    },
    execute = function(domoticz, device)
        for ix, ipadress in ipairs(yeelights) do
            if (device.state == 'Off') then
                runcommandoff = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommandoff)
            elseif (device.state == level10) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..sunrise.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
            elseif (device.state == level20) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..sunset.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            elseif (device.state == level30) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..calm.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            elseif (device.state == level40) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..alarm.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            elseif (device.state == level50) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..notify.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            elseif (device.state == level60) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..police_1.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            elseif (device.state == level70) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..police_2.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            elseif (device.state == level80) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..candle_flicker.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            elseif (device.state == level90) then
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":" ..birthday_party.. "}\\r\\n' | nc -w1 " ..ipadress.." " ..port.."" 
                os.execute(runcommand)
            end
            domoticz.log('Set light to ' ..device.state..' mode',domoticz.LOG_FORCE)
        end
    end
}
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
schumi2004
Posts: 24
Joined: Tuesday 17 October 2017 19:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10603
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by schumi2004 »

Nice script but i'm having a issue that the lights won't react on the Dummy switch selector.
Changed the settings to my needs, changed IP';s and Idx.
When selected and changing scene i see it in log but the lights itself don;t respond.

Any ideas, did i missed a step?
schumi2004
Posts: 24
Joined: Tuesday 17 October 2017 19:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10603
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by schumi2004 »

Any help, suggestions?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by waaren »

schumi2004 wrote:Any help, suggestions?
What happens if you enter the nc command on the CLI as the domoticz user?

Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
schumi2004
Posts: 24
Joined: Tuesday 17 October 2017 19:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10603
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by schumi2004 »

waaren wrote: Thursday 20 June 2019 14:39
schumi2004 wrote:Any help, suggestions?
What happens if you enter the nc command on the CLI as the domoticz user?

Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
I think i understand where you're heading at.
NC is not available on my Synology (a find did not gave any results) or it should be an abbreviation for something else.
NC stands for ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by waaren »

schumi2004 wrote: Thursday 20 June 2019 16:03
waaren wrote: Thursday 20 June 2019 14:39
schumi2004 wrote:Any help, suggestions?
What happens if you enter the nc command on the CLI as the domoticz user?

Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
I think i understand where you're heading at.
NC is not available on my Synology (a find did not gave any results) or it should be an abbreviation for something else.
NC stands for ?
if you don't have the nc program on your system this script will not work.
nc is short for netcat. I have it on my Synology now but I had to install it separately with

Code: Select all

sudo /opt/bin/ipkg install netcat
first.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
schumi2004
Posts: 24
Joined: Tuesday 17 October 2017 19:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10603
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by schumi2004 »

Mmmm that explains although i expected some errors.
I'll need to do some reading on how to bootstrap my DS715 first to get ipkg and continue.

Thanks for your help ;)
User avatar
Thuis
Posts: 272
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by Thuis »

DewGew wrote: Friday 08 March 2019 11:47 I made a script to select a custom scene for my Yeelight Color bulbs. Works with multiple bulbs.
Premade scenes in the script is: Sunrise, Sunset, Calm, Alarm, Notify, Police 1, Police 2, Candle Flicker, Birthday Party.
Thank you so much for sharing this :-D
I Love Domoticz ! And the community around it :-)
snuiter
Posts: 67
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by snuiter »

Great script is it possible to do this also with the dzvents command like

Code: Select all

setColor(r, g, b, br, cw, ww, m, t), 
so I can easily integrate an action like the notify

Code: Select all

local notify = '[\"cf",0,0,\"1000,2,2700,100,1000,7,0,0,1000,2,2700,10,1000,7,0,0\"]'
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yeelights Scene Selector (RGBW)

Post by waaren »

snuiter wrote: Friday 15 January 2021 22:21 Great script is it possible to do this also with the dzvents command like

Code: Select all

setColor(r, g, b, br, cw, ww, m, t), 
so I can easily integrate an action like the notify

Code: Select all

local notify = '[\"cf",0,0,\"1000,2,2700,100,1000,7,0,0,1000,2,2700,10,1000,7,0,0\"]'
No this it too specific for yeelights.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest