Page 1 of 1

Yeelights Scene Selector (RGBW)

Posted: Friday 08 March 2019 11:47
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
}

Re: Yeelights Scene Selector (RGBW)

Posted: Monday 22 April 2019 0:47
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?

Re: Yeelights Scene Selector (RGBW)

Posted: Thursday 20 June 2019 13:59
by schumi2004
Any help, suggestions?

Re: Yeelights Scene Selector (RGBW)

Posted: Thursday 20 June 2019 14:39
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


Re: Yeelights Scene Selector (RGBW)

Posted: Thursday 20 June 2019 16:03
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 ?

Re: Yeelights Scene Selector (RGBW)

Posted: Thursday 20 June 2019 17:15
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.

Re: Yeelights Scene Selector (RGBW)

Posted: Thursday 20 June 2019 17:24
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 ;)

Re: Yeelights Scene Selector (RGBW)

Posted: Wednesday 26 June 2019 19:07
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

Re: Yeelights Scene Selector (RGBW)

Posted: Friday 15 January 2021 22:21
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\"]'

Re: Yeelights Scene Selector (RGBW)

Posted: Friday 15 January 2021 22:32
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.