Advertisement
boomx

rgbw-sync2

Jan 17th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. --[[
  2. %% properties
  3. 603 color
  4. 603 currentProgram
  5. %% globals
  6. --]]
  7.  
  8. local fromID = 603;   -- ID des setzenden RGBW-device (bitte auch 2x unter den properties ändern)
  9. local toID = 917;     -- ID des zu syncenden RGBW-device
  10. local toID2 = 917;     -- ID2 des zu syncenden RGBW-device
  11.  
  12. -- Allows us to set the colour from a string like 'r,g,b,w'
  13. function setTheColour (deviceID, colourString)
  14.   local RGBWTable= {}
  15.   local i = 1
  16.  
  17.   for value in string.gmatch(colourString,"(%d+)") do
  18.     RGBWTable[i] = value
  19.     i = i + 1
  20.   end
  21.  
  22.   fibaro:call(deviceID, "setColor", RGBWTable[1], RGBWTable[2], RGBWTable[3], RGBWTable[4])
  23. end
  24.  
  25. local trigger = fibaro:getSourceTrigger()
  26. if (trigger['type'] == 'property') then
  27.   if (trigger['propertyName'] == 'currentProgram') then
  28.     fibaro:debug('RGBW-Programm gestartet. Sync')
  29.     fibaro:call(toID, 'startProgram', fibaro:getValue(fromID, 'currentProgramID'))
  30.     fibaro:call(toID2, 'startProgram', fibaro:getValue(fromID, 'currentProgramID'))
  31.     if (fibaro:getValue(fromID, 'currentProgramID') == '0') then
  32.       fibaro:debug('ProgrammID = 0. Setze Farbe')
  33.       setTheColour(toID, fibaro:getValue(fromID, 'color'));
  34.       setTheColour(toID2, fibaro:getValue(fromID, 'color'));
  35.     end
  36.   elseif (trigger['propertyName'] == 'color') then
  37.     if (fibaro:getValue(fromID, 'currentProgramID') == '0') then
  38.       fibaro:debug('Color gesetzt. Sync')
  39.       setTheColour(toID, fibaro:getValue(fromID, 'color'));
  40.       setTheColour(toID2, fibaro:getValue(fromID, 'color'));
  41.     end
  42.   end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement