The script below is what I found, combined, tried myself with the purpose
-- Lua script to set Philips Hue and Yeelights to the same Brightness, HUE and saturation parameters
-- First to adjust all the bulbs to the same values
-- Second to find out what values will suite me, debug = true and in the log file the commands are printed
-- copy paste the values you like and use them in your more "final" program
I hope this will others help also
I created a few "virtual" dimmer switches
and a selector switch
In the code you see a lot of comment, I do this for myself to document the code with explanation
and this is the code for the script:
Code: Select all
-- Lights
-- Lua script to set Philips Hue and Yeelights to the same Brightness, HUE and saturation parameters
-- First to adjust all the bulbs to the same values
-- Second to find out what values will suite me, debug = true and in the log file the commands are printed
-- copy paste the ones you like and use them in your more "final" program
--[[
YEELIGHTS
PART OF YEELIGHT MANUAL (for Reference pasted here)
complete manual can be found at http://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf
Method: set_hsv
Usage: This method is used to change the color of a smart LED.
Parameters: 4.
"hue" is the target hue value, whose type is integer. It should be
expressed in decimal integer ranges from 0 to 359.
"sat" is the target saturation value whose type is integer. It's range is 0
to 100.
"effect": Refer to "set_ct_abx" method.
"duration": Refer to "set_ct_abx" method.
Request Example: {"id":1,"method":"set_hsv","params":[255, 45, "smooth", 500]}
Method: set_bright
Usage: This method is used to change the brightness of a smart LED.
Parameters: 3.
"brightness" is the target brightness. The type is integer and ranges
from 1 to 100. The brightness is a percentage instead of a absolute value. 100 means
maximum brightness while 1 means the minimum brightness.
"effect": Refer to "set_ct_abx" method.
"duration": Refer to "set_ct_abx" method.
Request Example: {"id":1,"method":"set_bright","params":[50, "smooth", 500]}
Response Example: {"id":1, "result":["ok"]}
NOTE: Only accepted if the smart LED is currently in "on" state.
Method: set_power
Usage: This method is used to switch on or off the smart LED (software
managed on/off).
Parameters: 3.
"power" can only be "on" or "off". "on" means turn on the smart LED,
"off" means turn off the smart LED.
"effect": Refer to "set_ct_abx" method.
"duration": Refer to "set_ct_abx" method.
Request Example: {"id":1,"method":"set_power","params":["on", "smooth", 500]}
Response Example: {"id":1, "result":["ok"]}
Method: start_cf
Usage: This method is used to start a color flow. Color flow is a series of smart
LED visible state changing. It can be brightness changing, color changing or color
temperature changing. This is the most powerful command. All our recommended scenes,
e.g. Sunrise/Sunset effect is implemented using this method. With the flow expression, user
can actually “program” the light effect.
Parameters: 3.
"count" is the total number of visible state changing before color flow
stopped. 0 means infinite loop on the state changing.
"action" is the action taken after the flow is stopped.
0 means smart LED recover to the state before the color flow started.
1 means smart LED stay at the state when the flow is stopped.
2 means turn off the smart LED after the flow is stopped.
"flow_expression" is the expression of the state changing series.
Request Example: {"id":1,"method":"start_cf","params":[ 4, 2, "1000, 2, 2700, 100, 500, 1,
255, 10, 5000, 7, 0,0, 500, 2, 5000, 1"]
Response Example: {"id":1, "result":["ok"]}
NOTE: Each visible state changing is defined to be a flow tuple that contains 4
elements: [duration, mode, value, brightness]. A flow expression is a series of flow tuples.
So for above request example, it means: change CT to 2700K & maximum brightness
gradually in 1000ms, then change color to red & 10% brightness gradually in 500ms, then
stay at this state for 5 seconds, then change CT to 5000K & minimum brightness gradually in
500ms. After 4 changes reached, stopped the flow and power off the smart LED.
START CF Command explanation
{"id":1,"method":"start_cf","params":[ 4, 2, "1000, 2, 2700, 100, 500, 1, 255, 10, 5000, 7, 0,0, 500, 2, 5000, 1"]
Example explained
{"id":1,"method":"start_cf", --start colour flow
"params":[ 4, --count, after 4 changes stop
2, --action, "action" is the action taken after the flow is stopped.
0 means smart LED recover to the state before the color flow started.
1 means smart LED stay at the state when the flow is stopped.
2 means turn off the smart LED after the flow is stopped.
--the next values in pairs 0f 4 means
--[duration, mode, value, brightness].
--mode = COLOR_MODE": Current light mode. 1 means color mode, 2 means color temperature, mode, 3 means HSV mode.
"1000, --change from present state in 1000ms
2, --color temperature mode
2700, --color temperature 2700
100, --brightness 100
500, 1, 255, 10, 5000, 7, 0,0, 500, 2, 5000, 1"]
Philips HUE Lights
usefull links:
http://192.168.2.8/debug/clip.html
https://developers.meethue.com/documentation/getting-started
https://www.domoticz.com/forum/viewtopic.php?t=10493
https://www.domoticz.com/wiki/Philips_Hue_Lights
http://huelights.com/
values:
Sat = Saturation a value between 0 and 255
Bri = Brightness a value between 0 and 255
Hue = Hue, color a value between 0 and 65535
Yeelight Hue Lights
usefull links:
http://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf
http://forum.yeelight.com/c/wonder
https://www.domoticz.com/wiki/Yeelight
values:
Sat = Saturation a value between 0 and 100
Bri = Brightness a value between 1 and 100
Hue = Hue, color a value between 0 and 359
]]--
--CHANGE BELOW FOR YOUR OWN NEEDS
SelectorDevice1 = 'Lights-Selector'
SelectorDevice2 = "Lights-Scene"
DimDevice = 'Dimmer';
TempDevice = 'WhiteTemp'
HueDevice = 'Hue'
SatDevice ='Sat'
BriDevice ='Bri'
DurationDevice ='Duration' --here you set the duration of the Dimmer Cycle 100% = 100 seconds, 10% = 10 seconds
--YEELIGHT
-- port number for the yeelights
PORT = '55443'
--IP adresses of the bulbs involved,
local IPs = {'192.168.2.80', '192.168.2.81', '192.168.2.82', '192.168.2.83', '192.168.2.84', '192.168.2.85'}
--PHILIPS HUE LIGHTS
--ID of the Philips Hue of the bulbs involved; 1 = hanglamp, 3 = kamer-kast
local BulB = {'1', '3'}
bridge_ip_address ="192.168.2.8"
hue_api_user = "2uZavYOxxxxxxxxxxxxTLGlHxxxxxxNGA"
debug = true
StartColorFlow = false
synology = true
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function HueOff()
-- command Philips Hue Off
for n,bulb_id in pairs(BulB) do
-- concatenate the http part of the command for HUE
http = " http://" .. bridge_ip_address .. "/api/" .. hue_api_user .. "/lights/" ..bulb_id.."/state"
runcommandHue = "curl --request PUT --data '{\"on\":false}'"
os.execute(runcommandHue..http)
end
end
function YeelightOff()
--command Yeelight Off
for n,IP in pairs(IPs) do
runcommandYeelight = "sudo echo -ne '{\"id\":"..n..",\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | /opt/bin/nc -w1 " ..IP.." " ..PORT.."";
os.execute(runcommandYeelight)
end
end
function HueOn()
-- command Philips Hue Off
for n,bulb_id in pairs(BulB) do
-- concatenate the http part of the command for HUE
http = " http://" .. bridge_ip_address .. "/api/" .. hue_api_user .. "/lights/" ..bulb_id.."/state"
runcommandHue = "curl --request PUT --data '{\"on\":true}'"
os.execute(runcommandHue..http)
end
end
function YeelightOn()
--command Yeelight Off
for n,IP in pairs(IPs) do
runcommandYeelight = "sudo echo -ne '{\"id\":"..n..",\"method\":\"set_power\", \"params\":[\"on\", \"smooth\", 500]}\\r\\n' | /opt/bin/nc -w1 " ..IP.." " ..PORT.."";
os.execute(runcommandYeelight)
end
end
function HueTemperature(WhiteHue, DimHue, DurationHue)
--HUE part
for n,bulb_id in pairs(BulB) do
-- concatenate the http part of the command for HUE
http = " http://" .. bridge_ip_address .. "/api/" .. hue_api_user .. "/lights/" ..bulb_id.."/state"
--concatenate the command part of the command for HUE
runcommandHue = "curl --request PUT --data '{\"on\":true, \"transitiontime\":"..DurationHue..", \"ct\":" ..WhiteHue.. ", \"bri\":" ..DimHue .."}'"
if debug then print(runcommandHue..http) end
os.execute(runcommandHue..http)
end
end
function YeelightTemperature(WhiteYee, DimYee, DurationYee)
--Yeelight part
for n,IP in pairs(IPs) do
--runcommandYeelight = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\",\"params\":[\"ct\", " .. WhiteYee .. "," .. DimYee .. "]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
--runcommandYeelight = "sudo echo -ne '{\"id\":1,\"method\":\"set_ct_abx\",\"params\":[" .. WhiteYee .. ",\"smooth\","..DurationYee.."]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
runcommandYeelight ="sudo echo -ne '{\"id\":"..n..",\"method\":\"start_cf\",\"params\":[1,1,\"" ..DurationYee..",2,"..WhiteYee..","..DimYee.."\"]}\\r\\n' | /opt/bin/nc -w1 " ..IP.." " ..PORT.."";
if debug then print(runcommandYeelight) end
os.execute(runcommandYeelight)
end
end
function HueHue(HueHue, SatHue, BriHue, DurationHue)
for n,bulb_id in pairs(BulB) do
-- concatenate the http part of the command for HUE
http = " http://" .. bridge_ip_address .. "/api/" .. hue_api_user .. "/lights/" ..bulb_id.."/state"
--concatenate the command part of the command for HUE
runcommandHue = "curl --request PUT --data '{\"on\":true, \"transitiontime\":"..DurationHue..", \"sat\":" ..SatHueValue.. ", \"bri\":" ..BriHueValue ..",\"hue\":" ..HueHueValue .."}'"
if debug then print(runcommandHue..http) end
os.execute(runcommandHue..http)
end
end
function YeeHue(HueYee, SatYee, BriYee, DurationYee)
--Yeelight part
for n,IP in pairs(IPs) do
if StartColorFlow then
runcommandYeelight = "sudo echo -ne '{\"id\":"..n..", \"method\":\"start_cf\", \"params\":[1,1,\"" ..DurationYee..",3,".. HueYee .. "," .. SatYee ..","..BriYee.."\"]}\\r\\n' | /opt/bin/nc -w1 " ..IP.." " ..PORT.."";
if debug then print(runcommandYeelight) end
os.execute(runcommandYeelight)
else
--since color flow on Yeelight for HSV mode is not working, we need to send 2 commands, 1 for the hue and satuartion and 1 for brightness
--command for the Yeelight Hue Example: {"id":1,"method":"set_hsv","params":[255, 45, "smooth", 500]} --> hue, sat, effect, duration
runcommandYeelight = "sudo echo -ne '{\"id\":"..n..", \"method\":\"set_hsv\", \"params\":[" .. HueYee .. ", " .. SatYee .. ", \"smooth\", "..DurationYee.."]}\\r\\n' | /opt/bin/nc -w1 " ..IP.." " ..PORT.."";
if debug then print(runcommandYeelight) end
os.execute(runcommandYeelight)
--command for the Yeelight brightness Example: {"id":1,"method":"set_bright","params":[50, "smooth", 500]} --> brightness, effect, duration
runcommandYeelight = "sudo echo -ne '{\"id\":"..n..", \"method\":\"set_bright\", \"params\":[" .. BriYee .. ", \"smooth\", "..DurationYee.."]}\\r\\n' | /opt/bin/nc -w1 " ..IP.." " ..PORT.."";
if debug then print(runcommandYeelight) end
os.execute(runcommandYeelight)
end
end
end
commandArray = {}
--see if one of the sliders was changed
if devicechanged[HueDevice] or devicechanged[SatDevice] or devicechanged[BriDevice] or devicechanged[TempDevice] or devicechanged[DimDevice] or devicechanged[DurationDevice]then
--there are changes in the settings, so estimate the values for each type of the bulbs
TempValue = otherdevices_svalues[TempDevice];
BriValue = otherdevices_svalues[BriDevice]
SatValue = otherdevices_svalues[SatDevice]
HueValue = otherdevices_svalues[HueDevice]
DimValue = otherdevices_svalues[DimDevice];
DurationValue = otherdevices_svalues[DurationDevice];
--to prevent errors for nil values when initiated
if TempValue==nil then TempValue=0 end
if BriValue==nil then BriValue=0 end
if SatValue==nil then SatValue=0 end
if HueValue==nil then HueValue=0 end
if DimValue==nil then DimValue=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
--determine the duration of the transation, 100% = 100 seconds, 10% = 10 seconds, 1% = 1 sec
if DurationValue == 0 or DurationValue == nil then
DurationHueValue = 4 --standard transation time Hue = 400 ms
DurationYeeValue = 400 -- make Yeelights have the same value as Philips Hue Lights
else
DurationHueValue = DurationValue * 10 -- Hue Transation time is defined in 0,1 sec
DurationYeeValue = DurationValue * 1000 -- Yee transation time is in ms = 0,001 sec
end
--color changes
BriHueValue = round(tonumber(BriValue * 2.55),0);
SatHueValue = round(tonumber(SatValue * 2.55),0);
HueHueValue = round(tonumber(HueValue * 655.35),0);
BriYeeValue = tonumber(BriValue)
SatYeeValue = tonumber(SatValue)
HueYeeValue = round(tonumber(HueValue * 3.59),0);
--white changes
--Yeelight Temp between 1700 and 6500 Kelvin
WhiteYeeValue = ((TempValue-1) * 48)+1700;
DimYeeValue = tonumber(DimValue)
--Huelight value between the warmest color 2000K is 500 mirek ("ct":500) and the coldest color 6500K is 153 mirek ("ct":153)
WhiteHueValue = 500 - round(tonumber(TempValue * 3.47),0)
DimHueValue = round(tonumber(DimValue * 2.55),0)
if (devicechanged[HueDevice]=='Off' or devicechanged[SatDevice]=='Off' or devicechanged[BriDevice]=='Off' or
devicechanged[TempDevice]=='Off'or devicechanged[DimDevice]=='Off') or
(tonumber(otherdevices_svalues[BriDevice]) ==0 or tonumber(otherdevices_svalues[SatDevice])==0 or tonumber(otherdevices_svalues[HueDevice])==0 or
tonumber(otherdevices_svalues[TempDevice])==0 or tonumber(otherdevices_svalues[DimDevice])==0 ) then
-- the bulb is Off
HueOff()
YeelightOff()
end
if devicechanged[TempDevice] or devicechanged[DimDevice] then
--there was change at Lighttemperature setting so we need to send that commands
HueTemperature(WhiteHueValue, DimHueValue, DurationHueValue)
YeelightTemperature(WhiteYeeValue, DimYeeValue, DurationYeeValue)
else
--there were changes in the color settings so send the proper commands for that case
HueHue(HueHueValue, SatHueValue, BriHueValue, DurationHueValue)
YeeHue(HueYeeValue, SatYeeValue, BriYeeValue, DurationYeeValue)
end
end
if devicechanged[SelectorDevice1] then
if otherdevices['HueSun'] == 'On' then commandArray['HueSun'] = 'Off' end
if otherdevices['Staande schemerlamp'] == 'Off' then commandArray['Staande schemerlamp'] = 'On' end
HueOn()
YeelightOn()
print("selectorswitch")
if otherdevices[SelectorDevice1] == "Energize" then
commandArray[TempDevice]='Set Level 99'
commandArray[DimDevice]='Set Level 90'
end
if otherdevices[SelectorDevice1] == "Concentrate" then
commandArray[TempDevice]='Set Level 77'
commandArray[DimDevice]='Set Level 80'
end
if otherdevices[SelectorDevice1] == "Reading" then
commandArray[TempDevice]='Set Level 44'
commandArray[DimDevice]='Set Level 70'
end
if otherdevices[SelectorDevice1] == "Normal" then
commandArray[TempDevice]='Set Level 37'
commandArray[DimDevice]='Set Level 60'
end
if otherdevices[SelectorDevice1] == "Relax" then
commandArray[TempDevice]='Set Level 16'
commandArray[DimDevice]='Set Level 10'
end
if otherdevices[SelectorDevice1] == "Movie" then
commandArray[TempDevice]='Set Level 100'
commandArray[DimDevice]='Set Level 30'
end
if otherdevices[SelectorDevice1] == "Romantic" then
commandArray[TempDevice]='Set Level 12'
commandArray[DimDevice]='Set Level 10'
end
--[[ some test results for later reference
HUE SAT BRI - description
4 60 42 - rose
7 65 19 - yellow-ish
3 65 19 - orange /red
10 65 19 - yellow/green
20 65 19 - green/yellow
30 65 19 - green
40 65 19 - green/blue
50 65 19 - bue/green - light blue
60 65 19 - blue
70 65 19 - deep blue
76 65 19 - night blue
80 65 19 - purple
90 65 19 - purple / red
100 65 19 - red
]]--
if otherdevices[SelectorDevice1] == "Warm" then
commandArray[HueDevice]='Set Level 4'
commandArray[SatDevice]='Set Level 60'
commandArray[BriDevice]='Set Level 42'
end
if otherdevices[SelectorDevice1] == "NightBlue" then
commandArray[HueDevice]='Set Level 76'
commandArray[SatDevice]='Set Level 65'
commandArray[BriDevice]='Set Level 19'
end
if otherdevices[SelectorDevice1] == "Warm-Dimmed" then
commandArray[HueDevice]='Set Level 99'
commandArray[SatDevice]='Set Level 65'
commandArray[BriDevice]='Set Level 19'
end
if otherdevices[SelectorDevice1] == "Off" then
HueOff()
YeelightOff()
end
end
return commandArray