Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. --[[
  2. %% autostart
  3. %% properties
  4. %% globals
  5. ​AlarmClockStatus
  6. --]]
  7.  
  8. -- REFERENCE
  9. -- forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se
  10. -- Thanks to robmac, stevenvd for good LUA functions code.
  11. -- 2015-02-26 ver 0.0.1
  12. -- 2015-02-27 ver 0.0.2 softLightUp function is made by stevenvd, thanks! :-)
  13. -- 2015-02-28 ver 0.0.3 adjustment in wakeUpLight function
  14. -- 2015-02-28 ver 0.0.4 sortTable function, result will be blind, binarySwitch, multilevelSwitch
  15. -- 2015-03-01 ver 0.0.5 added "com.fibaro.FGRM222"
  16. -- 2015-03-04 ver 0.0.6 added "com.fibaro.rollerShutter" (qubino)
  17. -- 2015-03-05 ver 0.0.6 fixed bug in lua code
  18. -- 2015-03-11 ver 0.0.7 bugg fixed and new function added to virtual device
  19. -- 2015-03-11 ver 0.0.8 changed from 2 lines of devices to 1 line that will have both lights and blinds
  20. -- 2015-03-11 ver 1.0.0 added extra options,
  21. -- 1. Start Sonos Radio (virtual device from Krikroff)
  22. -- 2. Set other wanted dimmers to fixed value
  23. -- 3. Activate/Deactivate wakeUp scene from AlarmClock virtual device
  24. --
  25.  
  26. -- SCENE SCENARIO
  27. -- Simple wakeup scene to turnOn lights at specified time that you set with the
  28. -- alarm clock virtual device
  29. -- Set value for how much the blinds should open with the slider in VD.
  30.  
  31.  
  32.  
  33. -------------------- USER SETTINGS -----------------------
  34. devices = {56,17} -- Lights, dimmers and blinds
  35. _maxValue = 90 -- When dimmer reach this value it will stop there
  36. _duration = 2 -- Time in minutes for how long wakeUp should be active
  37. debug = true -- set debug to true or false
  38.  
  39.  
  40. -- EXTRA FUNCTIONS, OPTIONS
  41. -- Start Sonos/Internet Radio
  42. vDeviceID = 94 -- Id of Sonos virtual device
  43. vDeviceButton = 1 -- Play
  44. vDeviceFunc = true -- set to true to activate Sonos/Internet Radio
  45.  
  46. -- Dimmers to set to fixed value when alarmWakeup
  47. Dimdevices = {97} -- Dimmers to set to fixed value
  48. fixedValue = 50 -- Dimmer value
  49. DimdevicesFunc = true -- set to true or false
  50.  
  51. --TimeOfDay variable --
  52. varTOD = "TimeOfDay" -- TOD translate
  53. varTODMorning = "Morgon" -- TOD Morning translate
  54.  
  55. -----------------------------------------------------------
  56.  
  57.  
  58. ------------- DO NOT CHANGE LINES BELOW -------------------
  59. startSource = fibaro:getSourceTrigger();
  60. version = "1.0.0"
  61. sortedtbl = {}
  62. -- Give debug a fancy color
  63. Debug = function ( color, message )
  64. fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
  65. end
  66.  
  67. Debug( "orange", "WakeUpTime scene - LUA Scripting by Jonny Larsson 2015" );
  68. Debug( "orange", "Version: "..version);
  69.  
  70. alarmTime1 = fibaro:getGlobal("alarmTime1")
  71. alarmDay1 = fibaro:getGlobal("alarmDays1")
  72. Debug( "lightgreen", "-- Set alarmtime in virtual device --");
  73. Debug( "lightgreen", "-- Set slider to how much blinds should open --");
  74.  
  75.  
  76.  
  77.  
  78. function timerFunction()
  79. alarmTime1 = fibaro:getGlobal("alarmTime1")
  80. alarmDay1 = fibaro:getGlobal("alarmDays1")
  81. blindUpLevel = fibaro:getGlobal("openBlinds")
  82.  
  83. timeNow = os.date("%H:%M")
  84. dayName = os.date("%A")
  85.  
  86.  
  87. if alarmDay1 == "Weekdays" and (dayName ~= "Saturday" or dayName ~= "Sunday") then
  88. alarmDay1 = dayName
  89. end
  90.  
  91.  
  92. if alarmDay1 == dayName and alarmTime1 == timeNow then
  93. fibaro:setGlobal(varTOD, varTODMorning) --Enable to set TimeOfDay
  94. sortTable()
  95. else
  96. if (debug) then
  97. Debug( "grey", "Next alarmTime is set to next "..alarmDay1..":"..alarmTime1);
  98. end
  99. end
  100.  
  101. setTimeout(timerFunction, 60*1000)
  102. end
  103.  
  104.  
  105. sortTable = function()
  106. for i = 1,#devices do
  107. lightItems = devices[i];
  108. if fibaro:getType(lightItems) == "com.fibaro.FGR221" or fibaro:getType(lightItems) == "com.fibaro.FGRM222" or fibaro:getType(lightItems) == "com.fibaro.rollerShutter" then
  109. table.insert(sortedtbl,lightItems)
  110. elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
  111. table.insert(sortedtbl,lightItems)
  112. elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" or fibaro:getType(lightItems) == "com.fibaro.FGRGBW441M" then
  113. table.insert(sortedtbl,lightItems)
  114. end
  115. end
  116. turnLightOn()
  117. end
  118.  
  119.  
  120. -- TurnOn lights, functions
  121. turnLightOn = function()
  122. for i = 1,#sortedtbl do
  123. lightItems = sortedtbl[i];
  124. if fibaro:getType(lightItems) == "com.fibaro.FGR221" or fibaro:getType(lightItems) == "com.fibaro.FGRM222" or fibaro:getType(lightItems) == "com.fibaro.rollerShutter" then
  125. fibaro:call(lightItems, "setValue", blindUpLevel)
  126. elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
  127. fibaro:call(lightItems, "turnOn")
  128. elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" or fibaro:getType(lightItems) == "com.fibaro.FGRGBW441M" then
  129. wakeUpFunc(lightItems)
  130. end
  131. end
  132. if (vDeviceFunc) then
  133. fibaro:call(vDeviceID, "pressButton", vDeviceButton)
  134. end
  135. if (DimdevicesFunc) then
  136. for i = 1,#Dimdevices do
  137. DimItems = Dimdevices[i];
  138. fibaro:call(DimItems, "setValue", fixedValue);
  139. end
  140. end
  141. end
  142.  
  143. wakeUpFunc = function(lightItems)
  144. fibaro:call(lightItems, "setValue", "0");
  145. fibaro:sleep(200);
  146. if (debug) then
  147. Debug( "green",'Start soft wakeup light')
  148. end
  149. addValue = _maxValue / tonumber(_duration);
  150. for variable = 0, _maxValue - 1, addValue do
  151. local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
  152. if (variable ~= 0 and currentValueLights == 0 ) then
  153. if (debug) then
  154. Debug( "blue","timer stop, lights turned off");
  155. end
  156. break;
  157. end
  158. local newValue = currentValueLights + addValue;
  159. if (debug) then
  160. Debug( "yellow",'Increase value to ' .. newValue)
  161. end
  162. --Increases the value of the lamp
  163. fibaro:call(lightItems, "setValue", newValue);
  164. --Waits before the next step
  165. fibaro:sleep(60*1000);
  166. end
  167. end
  168.  
  169.  
  170. ------------------ START OF SCENE ----------------------
  171. if ( startSource["type"] == "autostart" ) or ( startSource["type"] == "global" ) then
  172. if fibaro:getGlobal("AlarmClockStatus") == "On" then
  173. timerFunction()
  174. else fibaro:debug("Scene is not active until you set AlarmClock to On")
  175. end
  176. else
  177. fibaro:debug('Scene manuell')
  178. sortTable()
  179. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement