Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- %% autostart
- %% properties
- %% globals
- AlarmClockStatus
- --]]
- -- REFERENCE
- -- forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se
- -- Thanks to robmac, stevenvd for good LUA functions code.
- -- 2015-02-26 ver 0.0.1
- -- 2015-02-27 ver 0.0.2 softLightUp function is made by stevenvd, thanks! :-)
- -- 2015-02-28 ver 0.0.3 adjustment in wakeUpLight function
- -- 2015-02-28 ver 0.0.4 sortTable function, result will be blind, binarySwitch, multilevelSwitch
- -- 2015-03-01 ver 0.0.5 added "com.fibaro.FGRM222"
- -- 2015-03-04 ver 0.0.6 added "com.fibaro.rollerShutter" (qubino)
- -- 2015-03-05 ver 0.0.6 fixed bug in lua code
- -- 2015-03-11 ver 0.0.7 bugg fixed and new function added to virtual device
- -- 2015-03-11 ver 0.0.8 changed from 2 lines of devices to 1 line that will have both lights and blinds
- -- 2015-03-11 ver 1.0.0 added extra options,
- -- 1. Start Sonos Radio (virtual device from Krikroff)
- -- 2. Set other wanted dimmers to fixed value
- -- 3. Activate/Deactivate wakeUp scene from AlarmClock virtual device
- --
- -- SCENE SCENARIO
- -- Simple wakeup scene to turnOn lights at specified time that you set with the
- -- alarm clock virtual device
- -- Set value for how much the blinds should open with the slider in VD.
- -------------------- USER SETTINGS -----------------------
- devices = {56,17} -- Lights, dimmers and blinds
- _maxValue = 90 -- When dimmer reach this value it will stop there
- _duration = 2 -- Time in minutes for how long wakeUp should be active
- debug = true -- set debug to true or false
- -- EXTRA FUNCTIONS, OPTIONS
- -- Start Sonos/Internet Radio
- vDeviceID = 94 -- Id of Sonos virtual device
- vDeviceButton = 1 -- Play
- vDeviceFunc = true -- set to true to activate Sonos/Internet Radio
- -- Dimmers to set to fixed value when alarmWakeup
- Dimdevices = {97} -- Dimmers to set to fixed value
- fixedValue = 50 -- Dimmer value
- DimdevicesFunc = true -- set to true or false
- --TimeOfDay variable --
- varTOD = "TimeOfDay" -- TOD translate
- varTODMorning = "Morgon" -- TOD Morning translate
- -----------------------------------------------------------
- ------------- DO NOT CHANGE LINES BELOW -------------------
- startSource = fibaro:getSourceTrigger();
- version = "1.0.0"
- sortedtbl = {}
- -- Give debug a fancy color
- Debug = function ( color, message )
- fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
- end
- Debug( "orange", "WakeUpTime scene - LUA Scripting by Jonny Larsson 2015" );
- Debug( "orange", "Version: "..version);
- alarmTime1 = fibaro:getGlobal("alarmTime1")
- alarmDay1 = fibaro:getGlobal("alarmDays1")
- Debug( "lightgreen", "-- Set alarmtime in virtual device --");
- Debug( "lightgreen", "-- Set slider to how much blinds should open --");
- function timerFunction()
- alarmTime1 = fibaro:getGlobal("alarmTime1")
- alarmDay1 = fibaro:getGlobal("alarmDays1")
- blindUpLevel = fibaro:getGlobal("openBlinds")
- timeNow = os.date("%H:%M")
- dayName = os.date("%A")
- if alarmDay1 == "Weekdays" and (dayName ~= "Saturday" or dayName ~= "Sunday") then
- alarmDay1 = dayName
- end
- if alarmDay1 == dayName and alarmTime1 == timeNow then
- fibaro:setGlobal(varTOD, varTODMorning) --Enable to set TimeOfDay
- sortTable()
- else
- if (debug) then
- Debug( "grey", "Next alarmTime is set to next "..alarmDay1..":"..alarmTime1);
- end
- end
- setTimeout(timerFunction, 60*1000)
- end
- sortTable = function()
- for i = 1,#devices do
- lightItems = devices[i];
- if fibaro:getType(lightItems) == "com.fibaro.FGR221" or fibaro:getType(lightItems) == "com.fibaro.FGRM222" or fibaro:getType(lightItems) == "com.fibaro.rollerShutter" then
- table.insert(sortedtbl,lightItems)
- elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
- table.insert(sortedtbl,lightItems)
- elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" or fibaro:getType(lightItems) == "com.fibaro.FGRGBW441M" then
- table.insert(sortedtbl,lightItems)
- end
- end
- turnLightOn()
- end
- -- TurnOn lights, functions
- turnLightOn = function()
- for i = 1,#sortedtbl do
- lightItems = sortedtbl[i];
- if fibaro:getType(lightItems) == "com.fibaro.FGR221" or fibaro:getType(lightItems) == "com.fibaro.FGRM222" or fibaro:getType(lightItems) == "com.fibaro.rollerShutter" then
- fibaro:call(lightItems, "setValue", blindUpLevel)
- elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
- fibaro:call(lightItems, "turnOn")
- elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" or fibaro:getType(lightItems) == "com.fibaro.FGRGBW441M" then
- wakeUpFunc(lightItems)
- end
- end
- if (vDeviceFunc) then
- fibaro:call(vDeviceID, "pressButton", vDeviceButton)
- end
- if (DimdevicesFunc) then
- for i = 1,#Dimdevices do
- DimItems = Dimdevices[i];
- fibaro:call(DimItems, "setValue", fixedValue);
- end
- end
- end
- wakeUpFunc = function(lightItems)
- fibaro:call(lightItems, "setValue", "0");
- fibaro:sleep(200);
- if (debug) then
- Debug( "green",'Start soft wakeup light')
- end
- addValue = _maxValue / tonumber(_duration);
- for variable = 0, _maxValue - 1, addValue do
- local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
- if (variable ~= 0 and currentValueLights == 0 ) then
- if (debug) then
- Debug( "blue","timer stop, lights turned off");
- end
- break;
- end
- local newValue = currentValueLights + addValue;
- if (debug) then
- Debug( "yellow",'Increase value to ' .. newValue)
- end
- --Increases the value of the lamp
- fibaro:call(lightItems, "setValue", newValue);
- --Waits before the next step
- fibaro:sleep(60*1000);
- end
- end
- ------------------ START OF SCENE ----------------------
- if ( startSource["type"] == "autostart" ) or ( startSource["type"] == "global" ) then
- if fibaro:getGlobal("AlarmClockStatus") == "On" then
- timerFunction()
- else fibaro:debug("Scene is not active until you set AlarmClock to On")
- end
- else
- fibaro:debug('Scene manuell')
- sortTable()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement