Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. --[[
  2. %% properties
  3. 249 sceneActivation
  4. %% globals
  5. --]]
  6.  
  7. local tasterID = 249
  8. local led = 122
  9.  
  10. function RgbToTable (string)
  11.   rgbw = {0,0,0,0}
  12.   rgbw[0],rgbw[1],rgbw[2],rgbw[3]= string.match(string, "(%d+),(%d+),(%d+),(%d+)")
  13.   return rgbw
  14. end
  15.  
  16. function setcolor (rgbw)
  17.   fibaro:call(led, "setColor", rgbw[0], rgbw[1], rgbw[2], 0)
  18. end
  19.  
  20. function checkmax(value)
  21.   if value > 255 then
  22.     fibaro:call(122, "turnOff")
  23.     fibaro:sleep(200)
  24.     fibaro:call(122, "turnOn")
  25.     fibaro:sleep(200)
  26.     value = 255
  27.   end
  28.   return value
  29. end
  30.  
  31. local button = tonumber(fibaro:getValue(tasterID, "sceneActivation"));
  32. fibaro:debug('es wurde gedrückt: '..button)
  33.  
  34. local color = fibaro:getValue(122, "color")
  35. local rgbw = RgbToTable(color)
  36.  
  37. ---while 1,2,3 long, dimm color up ---
  38. while tonumber(fibaro:getValue(tasterID, "sceneActivation")) == 13 do
  39.     rgbw[0] = rgbw[0] + 10
  40.     rgbw[0] = checkmax(rgbw[0])
  41.     setcolor(rgbw)
  42.     fibaro:sleep(200)
  43. end
  44. while tonumber(fibaro:getValue(tasterID, "sceneActivation")) == 23 do
  45.     rgbw[1] = rgbw[1] + 10
  46.     rgbw[1] = checkmax(rgbw[1])
  47.     setcolor(rgbw)
  48.     fibaro:sleep(200)
  49. end
  50. while tonumber(fibaro:getValue(tasterID, "sceneActivation")) == 33 do
  51.     rgbw[2] = rgbw[2] + 10
  52.     rgbw[2] = checkmax(rgbw[2])
  53.     setcolor(rgbw)
  54.     fibaro:sleep(200)  
  55. end
  56.  
  57. ---button 4 long = all off, short = all on ---
  58. if button == 41 or button == 42 then
  59.   fibaro:call(led, "setColor", 255, 255, 255, 0)
  60. end
  61. if button == 43 or button == 45 then
  62.   fibaro:call(led, "setColor", 0, 0, 0, 0)
  63. end
  64.  
  65. -----reset color on button press 1=r 2=g 3=b-----
  66. if button == 11 or button == 12 then
  67.     rgbw[0] = 0
  68.     setcolor(rgbw)
  69. end
  70. if button == 21 or button == 22 then
  71.     rgbw[1] = 0
  72.     setcolor(rgbw)
  73. end
  74. if button == 31 or button == 32 then
  75.     rgbw[2] = 0
  76.     setcolor(rgbw)
  77. end
  78.  
  79. fibaro:debug("ende")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement