Facebook
From Christian , 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 122
  1.  
  2. local deBug = true;
  3. local Hueid = 63
  4. local dim_time = 5 -- seconds from min to max dimlevel
  5. local dim_step = 10 -- Size of each dimming step on a scale from 0 to 255. Making this too small increases zwave traffic
  6. local dimlevel = 255
  7. local button_source=json.encode(sourceTrigger.value.keyId)
  8. --fibaro.debug("button_source", button_source)
  9. local keyAttribute=json.encode(sourceTrigger.value.keyAttribute)
  10. --fibaro.debug("keyAttribute", keyAttribute)
  11. if keyAttribute == '"Pressed"' then fibaro.debug("Trigger","SingleClick")
  12. if((tonumber(fibaro.getValue(Hueid, 'value'))) > 0) then
  13. fibaro.call(Hueid, 'turnOff')
  14. else
  15. fibaro.call(Hueid, 'turnOn')
  16. end
  17. -- TrippleClick Brightness til 255
  18. elseif keyAttribute == '"Pressed3"' then
  19. fibaro.debug("Trigger","TrippleClick")
  20. fibaro.call(Hueid, "changeBrightness", 255)
  21. elseif keyAttribute == '"Pressed2"' then
  22. fibaro.debug("Trigger","DoubleClick")
  23. --fibaro.call(Hueid, "changeBrightness", 80)
  24. if(tonumber(fibaro.getValue(Hueid, "brightness")) > 240) then
  25. fibaro.call(Hueid, "changeBrightness", 80)
  26. elseif ((tonumber(fibaro.getValue(Hueid, "brightness")) > 140) and (tonumber(fibaro.getValue(Hueid, "brightness")) < 240)) then
  27. fibaro.call(Hueid, "changeBrightness", 255)
  28. else
  29. fibaro.call(Hueid, "changeBrightness", 150)
  30. end
  31. elseif keyAttribute == '"Released"' then
  32. fibaro.debug("Trigger","Release")
  33. elseif keyAttribute == '"HeldDown"' then
  34. fibaro.debug("Trigger","HeldDown")
  35. if((tonumber(fibaro.getValue(Hueid, 'value'))) <= 0) then
  36. fibaro.call(Hueid, "turnOn")
  37. end
  38. dimDirection = "up"
  39. dimlevel = tonumber(fibaro.getValue(Hueid, "brightness"))
  40. fibaro.debug("Hueid",Hueid)
  41. fibaro.debug("dimlevel",dimlevel)
  42. while true do
  43. if dimlevel == 255 then dimDirection = "down" end
  44. if dimlevel == 0 then dimDirection = "up" end
  45. if dimDirection == "up" then
  46. dimlevel = math.min(dimlevel + dim_step,255)
  47. else
  48. dimlevel = math.max(dimlevel - dim_step,0)
  49. end
  50. fibaro.call(Hueid, "changeBrightness", dimlevel)
  51. --  fibaro.debug('Dimlevel', tostring(dimlevel))
  52. -- Suspends execution of a script for a specified time in milliseconds.
  53. -- 3 x 1000 / (255/10) = 120ms/step
  54. fibaro.sleep(dim_time*1000/(255/dim_step))
  55. end
  56. end
  57.  
  58.  
  59. {
  60.   conditions = { {
  61.       id = 25,
  62.       isTrigger = true,
  63.       operator = "==",
  64.       property = "centralSceneEvent",
  65.       type = "device",
  66.       value = {
  67.         keyAttribute = "HeldDown",
  68.         keyId = 1
  69.       }
  70.     }, {
  71.       id = 25,
  72.       isTrigger = true,
  73.       operator = "!=",
  74.       property = "centralSceneEvent",
  75.       type = "device",
  76.       value = {
  77.         keyAttribute = "Released",
  78.         keyId = 1
  79.       }
  80.     } },
  81.   operator = "any"
  82. }
  83.