I found this script on some russian forum ( https://translate.googleusercontent.com ... ry58660929 ) and adapted it with my own yeelights, but i dont realy know what i am doing

When i select off it only shuts down the firs light in " local Light = domoticz.devices('Yeelight bank links', 'Yeelight tv links', 'Yeelight lantaarn', 'Yeelight bank rechts', 'Yeelight tv rechts')"
Code: Select all
return {
on = {
devices = {
'Lights-Selector',
'Dimmer',
'WhiteTemp',
'Hue',
'Sat',
'Bri',
'Duration'
}
},
logging = {
level = domoticz.LOG_DEBUG
},
execute = function(domoticz, device)
local Light = domoticz.devices('Yeelight bank links', 'Yeelight tv links', 'Yeelight lantaarn', 'Yeelight bank rechts', 'Yeelight tv rechts') -- Yeelight Bulb
local PORT = '55443'
local IPs = {'192.168.179.88', '192.168.179.19','192.168.179.178','192.168.179.104','192.168.179.48'} -- group --> {'192.168.0.1', '192.168.0.2', '192.168.0.3'} -- group --> {'192.168.0.1', '192.168.0.2', '192.168.0.3'}
local switch = domoticz.devices
local sceneWhite = {}
sceneWhite[#sceneWhite+1] = {'Energize', 99, 90}
sceneWhite[#sceneWhite+1] = {'Concentrate', 77, 80}
sceneWhite[#sceneWhite+1] = {'Reading', 44, 70}
sceneWhite[#sceneWhite+1] = {'Normal', 37, 60}
sceneWhite[#sceneWhite+1] = {'Movie', 100, 30}
sceneWhite[#sceneWhite+1] = {'Relax', 16, 10}
sceneWhite[#sceneWhite+1] = {'Romantic', 12, 10}
local sceneRGB = {}
sceneRGB[#sceneRGB+1] = {'Warm', 4, 60, 42}
sceneRGB[#sceneRGB+1] = {'Warm-Dimmed', 99, 65, 19}
sceneRGB[#sceneRGB+1] = {'NightBlue', 76, 65, 19}
debug = true
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function YeelightOff()
Light.switchOff().checkFirst()
switch('Dimmer').switchOff().checkFirst().silent()
switch('WhiteTemp').switchOff().checkFirst().silent()
switch('Hue').switchOff().checkFirst().silent()
switch('Sat').switchOff().checkFirst().silent()
switch('Bri').switchOff().checkFirst().silent()
switch('Lights-Selector').switchOff().checkFirst().silent()
end
function YeelightTemperature(WhiteValue, DimValue, DurationYeeValue)
Light.switchOn().checkFirst()
for n, IP in pairs(IPs) do
runcommandYeelight = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\",\"params\":[\"ct\", " .. WhiteValue .. "," .. DimValue .. "]}\\r\\n' | nc -w1 " ..IP.." " ..PORT..""
if debug then print(runcommandYeelight) end
os.execute(runcommandYeelight)
end
switch('Dimmer').switchOn().checkFirst().silent()
switch('WhiteTemp').switchOn().checkFirst().silent()
switch('Hue').switchOff().checkFirst().silent()
switch('Sat').switchOff().checkFirst().silent()
switch('Bri').switchOff().checkFirst().silent()
end
function YeeHue(HueValue, SatValue, BriValue, DurationYeeValue)
Light.switchOn().checkFirst()
for n, IP in pairs(IPs) do
runcommandYeelight = "sudo echo -ne '{\"id\":"..n..", \"method\":\"set_hsv\", \"params\":[" .. HueValue .. ", " .. SatValue .. ", \"smooth\", "..DurationYeeValue.."]}\\r\\n' | nc -w1 " ..IP.." " ..PORT..""
if debug then print(runcommandYeelight) end
os.execute(runcommandYeelight)
runcommandYeelight = "sudo echo -ne '{\"id\":"..n..", \"method\":\"set_bright\", \"params\":[" .. BriValue .. ", \"smooth\", "..DurationYeeValue.."]}\\r\\n' | nc -w1 " ..IP.." " ..PORT..""
if debug then print(runcommandYeelight) end
os.execute(runcommandYeelight)
end
switch('Hue').switchOn().checkFirst().silent()
switch('Sat').switchOn().checkFirst().silent()
switch('Bri').switchOn().checkFirst().silent()
switch('Dimmer').switchOff().checkFirst().silent()
switch('WhiteTemp').switchOff().checkFirst().silent()
end
DimValue = switch('Dimmer').level
TempValue = switch('WhiteTemp').level
WhiteValue = ((TempValue - 1) * 48) + 1700
HueValue = round(switch('Hue').level * 3.59),0
SatValue = switch('Sat').level
BriValue = switch('Bri').level
DurationValue = switch('Duration').level
if DimValue == nil then DimValue = 0 end
if TempValue == nil then TempValue = 0 end
if HueValue == nil then HueValue = 0 end
if SatValue == nil then SatValue = 0 end
if BriValue == nil then BriValue = 0 end
if DurationValue == nil then DurationValue = 0 end
if debug then print("Temp = " ..TempValue.." Dim = "..DimValue.." Bri = "..BriValue.." Sat = "..SatValue.." Hue = "..HueValue.." Duration = "..DurationValue) end
if DurationValue == 0 or DurationValue == nil then
DurationYeeValue = 400
else
DurationYeeValue = DurationValue * 1000
end
if ((device.name == 'Dimmer' or device.name == 'WhiteTemp') and device.state ~= 'Off') then
YeelightTemperature(WhiteValue, DimValue, DurationYeeValue)
end
if ((device.name == 'Hue' or device.name == 'Sat' or device.name == 'Bri') and device.state ~= 'Off') then
YeeHue(HueValue, SatValue, BriValue, DurationYeeValue)
end
if ((device.name == 'Dimmer' or device.name == 'WhiteTemp' or device.name == 'Hue' or device.name == 'Sat' or device.name == 'Bri') and device.state == 'Off') then
YeelightOff()
end
if (device.name == 'Lights-Selector') then
if (device.levelName == 'Off') then
YeelightOff()
end
for i in pairs(sceneWhite) do
if (device.levelName == sceneWhite[i][1] ) then
switch('WhiteTemp').dimTo(sceneWhite[i][2])
switch('Dimmer').dimTo(sceneWhite[i][3])
end
end
for i in pairs(sceneRGB) do
if (device.levelName == sceneRGB[i][1] ) then
switch('Hue').dimTo(sceneRGB[i][2])
switch('Sat').dimTo(sceneRGB[i][3])
switch('Bri').dimTo(sceneRGB[i][4])
end
end
end
end
}
Code: Select all
2019-09-17 11:53:47.156 (Dummy) Light/Switch (Lights-Selector)
2019-09-17 11:53:47.641 (Yeelight) Color Switch (Yeelight bank links)
2019-09-17 11:53:47.653 (Dummy) Light/Switch (Dimmer)
2019-09-17 11:53:47.663 (Dummy) Light/Switch (WhiteTemp)
2019-09-17 11:53:47.155 Status: User: Admin initiated a switch command (108/Lights-Selector/Set Level)
2019-09-17 11:53:47.179 Status: dzVents: Info: Handling events for: "Lights-Selector", value: "Off"
2019-09-17 11:53:47.179 Status: dzVents: Info: ------ Start internal script: Yeelight: Device: "Lights-Selector (Dummy)", Index: 108
2019-09-17 11:53:47.179 Status: dzVents: Debug: Processing device-adapter for Yeelight bank links: RGB(W) device adapter
2019-09-17 11:53:47.179 Status: dzVents: Debug: Processing device-adapter for Yeelight bank links: Switch device adapter
2019-09-17 11:53:47.179 Status: dzVents: Debug: Processing device-adapter for Dimmer: Switch device adapter
2019-09-17 11:53:47.180 Status: dzVents: Debug: Processing device-adapter for WhiteTemp: Switch device adapter
2019-09-17 11:53:47.180 Status: dzVents: Debug: Processing device-adapter for Hue: Switch device adapter
2019-09-17 11:53:47.180 Status: dzVents: Debug: Processing device-adapter for Sat: Switch device adapter
2019-09-17 11:53:47.180 Status: dzVents: Debug: Processing device-adapter for Bri: Switch device adapter
2019-09-17 11:53:47.180 Status: dzVents: Debug: Processing device-adapter for Duration: Switch device adapter
2019-09-17 11:53:47.180 Status: dzVents: Temp = 12 Dim = 10 Bri = 0 Sat = 0 Hue = 0 Duration = 0
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off NOTRIGGER
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off NOTRIGGER
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-17 11:53:47.180 Status: dzVents: Info: ------ Finished Yeelight