UPDATE to version 3.1.2 (12 January 2017)
Functions corrected
Scene: Virtual Device: -- SCENE SCENARIO
-- Simple wakeup scene to turnOn lights at specified time that you set with the
-- alarm clock virtual device
1. Import virtual device in zip file
2. add 2 variables, alarmTime1 and alarmDays1
3. add lua code in a new lua scene
4. set alarmtime in virtual device
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
Code: Select all
--[[
REFERENCE
Some code parts are (with permisson) from Sankotronic's scene. Thank you :-)
SOURCES
forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se
2015-02-26 ver 0.0.1
...
2016-12-29 ver 3.0.0 New layout of VD and rebuild of scene code.
2016-12-31 ver 3.0.1 Increase volume by soft wakeup, supports Sonos VD (Krikroff's Sonos Remote 1.0.1 VD)
2017-01-07 ver 3.0.2 Increase your HUE device by soft wakeup (Sankotronic's Philips HUE VD')
2017-01-08 ver 3.0.3 Bug fixes. Added support so it is possibleto use other HUE VD
by entering the slider name and ID
2017-01-08 ver 3.0.4 Corrected bug when start of Sonos VD and corrected line 371 from
"lightItems" to "HueItems"
2017-01-08 ver 3.0.5 More setup options added :-)
2017-01-10 ver 3.1.0 Added support for sleepState variable. Removed unused code and clean up
2017-01-11 ver 3.1.1 Fixed stop functions, timer will stop if lights/dimmers, hue or volume slider is set to 0
2017-01-12 ver 3.1.2 Functions corrected.
-- SCENE SCENARIO
Advanced wakeup scene to turnOn lights at specified time that you set with the AlarmClock VD
Helper function will sort and list all lights like switches and dimmers. The one you want to
use in this scene you need to add to "local devices" in "-- USER PART --" section
Wakeup to soft music/radio. Possible to increase volume same as with lights
Now this scene supports HUE VD. Use it by soft wakeup or fixed value.
Supported setup:
Use only VD, use only HUE, use both VD and HUE, use only Lights/Dim devices, use
Lights/Dim devices by fixed value together with a VD or HUE or both.
Hope i have covered them all, else just report and i will add it.
Enjoy! :-)
--]]
Code: Select all
--[[
%% autostart
%% properties
%% globals
AlarmClockStatus
AlarmClockTime1
AlarmClockTime2
AlarmClockDays1
AlarmClockDays2
--]]
--[[
REFERENCE
Some code parts are (with permisson) from Sankotronic's scene. Thank you :-)
SOURCES
forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se
2015-02-26 ver 0.0.1
...
2016-12-29 ver 3.0.0 New layout of VD and rebuild of scene code.
2016-12-31 ver 3.0.1 Increase volume by soft wakeup, supports Sonos VD (Krikroff's Sonos Remote 1.0.1 VD)
2017-01-07 ver 3.0.2 Increase your HUE device by soft wakeup (Sankotronic's Philips HUE VD')
2017-01-08 ver 3.0.3 Bug fixes. Added support so it is possibleto use other HUE VD
by entering the slider name and ID
2017-01-08 ver 3.0.4 Corrected bug when start of Sonos VD and corrected line 371 from
"lightItems" to "HueItems"
2017-01-08 ver 3.0.5 More setup options added :-)
2017-01-10 ver 3.1.0 Added support for sleepState variable. Removed unused code and clean up
2017-01-11 ver 3.1.1 Fixed stop functions, timer will stop if lights/dimmers, hue or volume slider is set to 0
2017-01-12 ver 3.1.2 Functions corrected.
-- SCENE SCENARIO
Advanced wakeup scene to turnOn lights at specified time that you set with the AlarmClock VD
Helper function will sort and list all lights like switches and dimmers. The one you want to
use in this scene you need to add to "local devices" in "-- USER PART --" section
Wakeup to soft music/radio. Possible to increase volume same as with lights
Now this scene supports HUE VD. Use it by soft wakeup or fixed value.
Supported setup:
Use only VD, use only HUE, use both VD and HUE, use only Lights/Dim devices, use
Lights/Dim devices by fixed value together with a VD or HUE or both.
Hope i have covered them all, else just report and i will add it.
Enjoy! :-)
--]]
if (fibaro:countScenes() > 1) then
fibaro:abort();
end
startSource = fibaro:getSourceTrigger();
--- USER PART ------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
-- SCENE CAN SCAN ALL YOUR LIGHTS/DIMMERS AND SHOW THEM IN A DEBUG LINE
-- loop through all devices and show user
local useHelper = false
--- from helper function, add those lights, dimmers and blinds you want this scene should control.
-- Do you only want to use VD then set this to false
local useDevices = true
-- Lights, dimmers and blinds
local devices = {121,295}
-- When dimmer reach this value it will stop there
local _maxValue = 40
--- FOR HOW LONG TIME SHOULD SOFTWAKEUP RUN BEFORE IT STOPS?
-- Time in minutes for how long the soft wakeUp should run
-- for both Sonos VD and lights
local _duration = 4
--- SUPPORTS PHILIPS HUE VD BY SANKOTRONIC
-- Set to true or false
local useHUE = true
-- HUE VD
local hueDevices = {406}
-- HUE Slider ID name
local hueSlider = "sldBrightness"
-- HUE Slider number (location in VD)
local hueSliderNum = "2"
-- Set to true for fixed HUE value else false
local useHueFixed = false
--- SET DIMMERS TO A FIXED VALUE
-- Set to true for fixed Dim value else false
local useDimFixed = false
-- Dimmers to set to fixed value
local Dimdevices = {295}
-- Dimmer fixed value
local fixedValue = 50
--- SUPPORT SONOS REMOTE 1.0.1
--- START SONOS RADIO CHANNEL, SET VOLUME TO FIXED VALUE OR INCREASE SOFTLY
-- Set to true or false for use of VD
local useVD = true
-- Id of Sonos virtual device
local vDeviceID = 298
-- Play button
local vDevicePlayButton = 7
-- Stop/Pause button
local vDeviceStopButton = 9
-- Volume slider name in VD
local vDeviceVolSlider = "slVolume"
-- Slider number (location in VD)
local vDeviceSliderNum = "15"
-- Radio channel (location in VD)
local vDeviceRadioChannelNum = "24"
-- Fixed volume
local vDeviceFixedVol = 8
-- set to true to increase Sonos/Internet Radio Volume
local vDeviceIncrFunc = false
-- Max volume when increase
local vDevicesMaxVol = 8
-- SET SLEEPSTATE VARIABLE TO AWAKE IF "useSleepState" = true
local sleepState = "SleepState";
local sleepStateMapping = {Sleep="Sleep", Awake="Awake"};
useSleepState = false
--- VARIABLE
local alarmClockStatus = "AlarmClockStatus";
local alarmClockMapping = {Off="Off", On="On"};
local alarmDaysMapping = { Weekdays="Weekdays", Weekends="Weekends",
Monday="Monday", Tuesday="Tuesday",
Wednesday="Wednesday", Thursday="Thursday",
Friday="Friday", Saturday="Saturday",
Sunday="Sunday", Off="Off" };
local weekday = {'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'}
--- WANT TO SHOW DEBUG INFO, SET BELOW VALUE TO TRUE
debug = true
---------------------------------------------------------------------------------------------------
--- END USER PART ---------------------------------------------------------------------------------
--- NO NEED TO MODIFY CODE BELOW ------------------------------------------------------------------
--- FUNCTIONS -------------------------------------------------------------------------------------
version = "3.1.2"
--- DEBUG COLOR -----------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
function Debug(color, message)
fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
end
--- DEBUG LOG EVERY 10 MIN ------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
function runEvery10min()
Debug("yellow","-- Scene is still running, next log event will appear in 10 minutes --")
Debug( "grey", "Next alarm time");
Debug( "grey", "alarmDay1:"..alarmDay1.." alarmTime1:"..alarmTime1);
Debug( "grey", "alarmDay2:"..alarmDay2.." alarmTime2:"..alarmTime2);
end
function startInfo()
Debug( "orange", "Advanced SoftWakeUp scene - (c) LUA Scripting by Jonny Larsson @jompa68 2015-2017" );
Debug( "orange", "Version: "..version);
Debug( "lightgreen", "-- Set wanted AlarmTime in AlarmClock VD --");
timeM = os.date("%M")
timeNow = os.date("%H:%M", os.time());
currentTime = os.date('*t');
currentwday = currentTime['wday'];
alarmStatus = fibaro:getGlobalValue(alarmClockStatus);
alarmTime1 = fibaro:getGlobal("AlarmClockTime1")
alarmTime2 = fibaro:getGlobal("AlarmClockTime2")
alarmDay1 = fibaro:getGlobal("AlarmClockDays1")
alarmDay2 = fibaro:getGlobal("AlarmClockDays2")
blindUpLevel = fibaro:getGlobal("openBlinds")
alarmTimes = {alarmTime1, alarmTime2}
alarmDays = {alarmDay1, alarmDay2}
vDimmertbl = {}
end
--- ID HELPER -------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
function helper()
Debug( "orange", "Advanced SoftWakeUp scene - (c) LUA Scripting by Jonny Larsson @jompa68 2015-2017" );
Debug( "orange", "Version: "..version);
Debug( "lightgreen", "-- Set wanted AlarmTime in AlarmClock VD --");
Debug("green","Helper function started! In few seconds all your ")
Debug("green","devices will be sorted and listed below.")
sortDevicetbl = {}
for i = 1, 500 do
if ("com.fibaro.FGR221" == fibaro:getType(i) or "com.fibaro.FGRM222" == fibaro:getType(i) or "com.fibaro.rollerShutter" == fibaro:getType(i) or "com.fibaro.multilevelSwitch" == fibaro:getType(i) or "com.fibaro.multilevelSwitch" == fibaro:getType(i) or "com.fibaro.binarySwitch" == fibaro:getType(i) or "com.fibaro.FGWP101" == fibaro:getType(i) or "com.fibaro.FGD212" == fibaro:getType(i)) then
table.insert(sortDevicetbl,i)
end
end
Debug("grey","Add your wanted devices in '--- USER PART ---' section")
Debug("grey","--->> local devices = {121,295} <<---")
Debug("grey",json.encode(sortDevicetbl))
end
--- CHECK AND START ACTIONS -----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
function turnLightOn()
if useDevices == true then
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" or fibaro:getType(lightItems) == "com.fibaro.FGWP101" then
fibaro:call(lightItems, "setValue", blindUpLevel)
elseif fibaro:getType(lightItems) == "com.fibaro.FGWP101" then
fibaro:call(lightItems, "turnOn")
if (debug) then
Debug( "yellow", "Lights are now on");
end
elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
fibaro:call(lightItems, "turnOn")
if (debug) then
Debug( "yellow", "Lights are now on");
end
elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" or fibaro:getType(lightItems) == "com.fibaro.FGD212" then
table.insert(vDimmertbl,lightItems)
end
end
end
wakeUpFunc()
end
--- CHECK AND START ACTIONS -----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
function wakeUpFunc()
if (debug) then
Debug( "green"," - START ALL THE ACTIONS - ")
end
-- IF HUE FIXED IS TRUE, SET FIXED VALUE
if useHueFixed == true then
for i = 1,#hueDevices do
HueItems = hueDevices[i];
if fibaro:getType(HueItems) == "virtual_device" then
Debug( "yellow", "HUE fixed value: "..fixedValue);
fibaro:call(HueItems, "setSlider", hueSliderNum, fixedValue)
end
end
end
-- IF HUE FIXED IS FALSE, SET SLIDER TO START POSITION 0
if useHUE == true and useHueFixed == false then
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, "0")
fibaro:sleep(200);
end
end
-- IF DIM FIXED IS TRUE, SET FIXED VALUE
if useDimFixed == true then
for ii = 1,#Dimdevices do
DimItems = Dimdevices[ii];
Debug( "yellow", "DIM fixed value: "..fixedValue);
fibaro:call(DimItems, "setValue", fixedValue);
end
end
-- IF DIM FIXED IS FALSE, SET VALUE TO 0
if useDevices == true and useDimFixed == false then
for i = 1,#Dimdevices do
lightItems = Dimdevices[i];
fibaro:call(lightItems, "setValue", "0");
fibaro:sleep(200);
end
end
-- IF SONOS VOLUME FIXED IS TRUE
if useVD == true and vDeviceIncrFunc == false then
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, vDeviceFixedVol)
fibaro:sleep(10*1000);
Debug( "yellow", "Volume fixed value: "..vDeviceFixedVol);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
end
-- IF SONOS FIXED IS FALSE, SET SLIDER TO START POSITION 0
if useVd == true and vDeviceIncrFunc == true then
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, "0")
end
if vDeviceIncrFunc == false and useDevices == false and useHUE == true and useHueFixed == false then
Debug( "yellow"," - huE function - ")
huE()
end
if useVD == false and useDevices == true and useDimFixed == false and useHUE == false then
Debug( "yellow"," - diM function - ")
diM()
end
if useVD == true and vDeviceIncrFunc == false and useDevices == true and useDimFixed == false and useHUE == true and useHueFixed == true then
Debug( "yellow"," - diM function - ")
diM()
end
if useVD == true and useDevices == false and vDeviceIncrFunc == true and useHUE == true and useHueFixed == true then
Debug( "yellow"," - sonoS function - ")
sonoS()
end
if useVD == true and vDeviceIncrFunc == false and useDevices == true and useDimFixed == false and useHUE == true and useHueFixed == false then
Debug( "yellow"," - huEdiM function - ")
huEdiM()
end
if useVD == true and vDeviceIncrFunc == true and useDevices == false and useHUE == true and useHueFixed == false then
Debug( "yellow"," - huEsonoS function - ")
huEsonoS()
end
if useVD == true and vDeviceIncrFunc == true and useDevices == true and useDimFixed == false and useHueFixed == true then
Debug( "yellow"," - diMsonoS function - ")
diMsonoS()
end
if useVD == true and vDeviceIncrFunc == true and useDevices == true and useDimFixed == true and useHueFixed == true then
Debug( "yellow"," - diMsonoS function - ")
diMsonoS()
end
if useVD == true and vDeviceIncrFunc == true and useDevices == true and useDimFixed == false and useHUE == true and useHueFixed == false then
Debug( "yellow"," - sonoSdiMhuE function - ")
sonoSdiMhuE()
end
end
function sonoSdiMhuE()
-- SONOS VD
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, "0")
fibaro:sleep(10*1000);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
local addValueVol = vDevicesMaxVol / tonumber(_duration);
-- HUE VD
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, "0")
fibaro:sleep(200);
end
local addValueHUE = _maxValue / tonumber(_duration);
-- DIM
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", "0");
fibaro:sleep(200);
end
local addValue = _maxValue / tonumber(_duration);
for variable = 0, _maxValue - 1, addValue do
--for variable = 0, _maxValue - 1, addValueVol, addValue, addValueHUE do
if fibaro:getType(HueItems) == "virtual_device" then
fibaro:call(HueItems, "setSlider", hueSliderNum, "0")
currentValueHUELights = tonumber(fibaro:getValue(HueItems, "ui."..hueSlider..".value"));
end
local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
local currentValueVol = tonumber(fibaro:getValue(vDeviceID, "ui."..vDeviceVolSlider..".value"));
if (variable ~= 0 and currentValueLights == 0) or (variable ~= 0 and currentValueHUELights == 0) or (variable ~= 0 and currentValueVol == 0) then
if (debug) then
Debug( "red","Timer will now stop, lights or volume was turned off");
end
break;
end
local newValue = currentValueLights + addValue;
local newValueHUE = currentValueHUELights + addValueHUE;
local newValueVol = currentValueVol + addValueVol;
if (debug) then
Debug( "yellow",'Increase dimmer value to ' .. newValue)
Debug( "yellow",'Increase HUE dimmer value to ' .. newValueHUE)
Debug( "yellow",'Increase volume value to '..newValueVol)
end
--Increases the value of HUE
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, newValueHUE)
end
--Increases the value of the light
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", newValue);
end
-- Increase volume
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, newValueVol)
--Waits before the next step
fibaro:sleep(55*1000);
end
Debug( "green"," - ALL ACTIONS ARE NOW COMPLETED.")
end
function diMsonoS()
-- DIM
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", "0");
fibaro:sleep(200);
end
local addValue = _maxValue / tonumber(_duration);
-- SONOS VD
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, "0")
fibaro:sleep(5*1000);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
fibaro:sleep(5*1000);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
local addValueVol = vDevicesMaxVol / tonumber(_duration);
for variable = 0, _maxValue - 1, addValue do
local currentValueVol = tonumber(fibaro:getValue(vDeviceID, "ui."..vDeviceVolSlider..".value"));
local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
if (variable ~= 0 and currentValueLights == 0) or (variable ~= 0 and currentValueVol == 0) then
if (debug) then
Debug( "red","Timer will now stop, lights or volume was turned off");
end
break;
end
local newValue = currentValueLights + addValue;
local newValueVol = currentValueVol + addValueVol;
if (debug) then
Debug( "yellow",'Increase dimmer value to ' .. newValue)
Debug( "yellow",'Increase volume value to '..newValueVol)
end
--Increases the value of the lights
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", newValue);
end
-- Increase volume
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, newValueVol)
--Waits before the next step
fibaro:sleep(55*1000);
end
Debug( "green"," - ALL ACTIONS ARE NOW COMPLETED.")
end
function huEsonoS()
-- HUE VD
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, "0")
fibaro:sleep(200);
end
local addValueHUE = _maxValue / tonumber(_duration);
-- SONOS VD
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, "0")
fibaro:sleep(5*1000);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
fibaro:sleep(5*1000);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
local addValueVol = vDevicesMaxVol / tonumber(_duration);
for variable = 0, vDevicesMaxVol - 1, addValueVol do
local currentValueHUELights = tonumber(fibaro:getValue(HueItems, "ui."..hueSlider..".value"));
local currentValueVol = tonumber(fibaro:getValue(vDeviceID, "ui."..vDeviceVolSlider..".value"));
if (variable ~= 0 and currentValueHUELights == 0) or (variable ~= 0 and currentValueVol == 0) then
if (debug) then
Debug( "red","Timer will now stop, hue or volume was turned off");
end
break;
end
local newValueVol = currentValueVol + addValueVol;
local newValueHUE = currentValueHUELights + addValueHUE;
if (debug) then
Debug( "yellow",'Increase volume value to ' .. newValueVol)
Debug( "yellow",'Increase HUE dimmer value to ' .. newValueHUE)
end
--Increases the value of HUE
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, newValueHUE)
end
-- Increase volume
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, newValueVol)
--Waits before the next step
fibaro:sleep(55*1000);
end
Debug( "green"," - ALL ACTIONS ARE NOW COMPLETED.")
end
function huEdiM()
-- HUE VD
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, "0")
fibaro:sleep(200);
end
local addValueHUE = _maxValue / tonumber(_duration);
-- DIM
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", "0");
fibaro:sleep(200);
end
local addValue = _maxValue / tonumber(_duration);
for variable = 0, _maxValue - 1, addValue do
local currentValueHUELights = tonumber(fibaro:getValue(HueItems, "ui."..hueSlider..".value"));
local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
if (variable ~= 0 and currentValueLights == 0) or (variable ~= 0 and currentValueHUELights == 0) then
if (debug) then
Debug( "red","Timer will now stop, lights was turned off");
end
break;
end
local newValue = currentValueLights + addValue;
local newValueHUE = currentValueHUELights + addValueHUE;
if (debug) then
Debug( "yellow",'Increase dimmer value to ' .. newValue)
Debug( "yellow",'Increase HUE dimmer value to ' .. newValueHUE)
end
--Increases the value of HUE
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, newValueHUE)
end
--Increases the value of the lights
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", newValue);
end
--Waits before the next step
fibaro:sleep(55*1000);
end
Debug( "green"," - ALL ACTIONS ARE NOW COMPLETED.")
end
function sonoS()
-- SONOS
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, "0")
fibaro:sleep(5*1000);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
fibaro:sleep(5*1000);
fibaro:call(vDeviceID, "pressButton", vDeviceRadioChannelNum)
local addValueVol = vDevicesMaxVol / tonumber(_duration);
for variable = 0, vDevicesMaxVol - 1, addValueVol do
local currentValueVol = tonumber(fibaro:getValue(vDeviceID, "ui."..vDeviceVolSlider..".value"));
if (variable ~= 0 and currentValueVol == 0) then
if (debug) then
Debug( "red","Timer will now stop, volume was turned off");
end
break;
end
local newValueVol = currentValueVol + addValueVol;
if (debug) then
Debug( "yellow",'Increase volume value to ' .. newValueVol)
end
-- Increase volume
fibaro:call(vDeviceID, "setSlider", vDeviceSliderNum, newValueVol)
--Waits before the next step
fibaro:sleep(55*1000);
end
Debug( "green"," - ALL ACTIONS ARE NOW COMPLETED.")
end
function diM()
-- DIM
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", "0");
fibaro:sleep(200);
end
local 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( "red","Timer will now stop, lights was turned off");
end
break;
end
local newValue = currentValueLights + addValue;
if (debug) then
Debug( "yellow",'Increase dimmer value to ' .. newValue)
end
--Increases the value of the lights
for i = 1,#vDimmertbl do
lightItems = vDimmertbl[i];
fibaro:call(lightItems, "setValue", newValue);
end
--Waits before the next step
fibaro:sleep(55*1000);
end
Debug( "green"," - ALL ACTIONS ARE NOW COMPLETED.")
end
function huE()
-- HUE VD
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, "0")
fibaro:sleep(200);
end
local addValueHUE = _maxValue / tonumber(_duration);
for variable = 0, _maxValue - 1, addValueHUE do
local currentValueHUELights = tonumber(fibaro:getValue(HueItems, "ui."..hueSlider..".value"));
if (variable ~= 0 and currentValueHUELights == 0) then
if (debug) then
Debug( "red","Timer will now stop, HUE was turned off");
end
break;
end
local newValueHUE = currentValueHUELights + addValueHUE;
if (debug) then
Debug( "yellow",'Increase HUE dimmer value to ' .. newValueHUE)
end
--Increases the value of HUE
for i = 1,#hueDevices do
HueItems = hueDevices[i];
fibaro:call(HueItems, "setSlider", hueSliderNum, newValueHUE)
end
--Waits before the next step
fibaro:sleep(55*1000);
end
Debug( "green"," - ALL ACTIONS ARE NOW COMPLETED.")
end
--- INITALIZE -------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
function initVar()
timeM = os.date("%M")
timeNow = os.date("%H:%M", os.time());
currentTime = os.date('*t');
currentwday = currentTime['wday'];
alarmStatus = fibaro:getGlobalValue(alarmClockStatus);
alarmTime1 = fibaro:getGlobal("AlarmClockTime1")
alarmTime2 = fibaro:getGlobal("AlarmClockTime2")
alarmDay1 = fibaro:getGlobal("AlarmClockDays1")
alarmDay2 = fibaro:getGlobal("AlarmClockDays2")
blindUpLevel = fibaro:getGlobal("openBlinds")
alarmTimes = {alarmTime1, alarmTime2}
alarmDays = {alarmDay1, alarmDay2}
vDimmertbl = {}
if (timeM % 10 == 0) then
runEvery10min()
end
timerFunction()
end
--- TIMER THAT RUNS EVERY MINUTE ------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
function timerFunction()
if alarmDay2 == alarmDaysMapping.Off then
table.remove(alarmDays, 2)
table.remove(alarmTimes, 2)
end
for i = 1,#alarmDays do
if timeNow == alarmTimes[i] then
if alarmDays[i] == alarmDaysMapping.Weekdays then
if (currentwday >= 2 and currentwday <= 6) then
Debug("lightblue","Activated by AlarmClock - Weekdays")
if useSleepState == true then
fibaro:setGlobal(sleepState, sleepStateMapping.Awake)
end
if (useDevices == true and useDimFixed == false) or (useVD == true and vDeviceIncrFunc == false) or (useHUE == true and useHueFixed == false) then
turnLightOn()
elseif (useVd == true and vDeviceIncrFunc == true) or (useHUE == true and useHueFixed == true) or (useDevices == true and useDimFixed == true) then
wakeUpFunc()
end
end
elseif alarmDays[i] == alarmDaysMapping.Weekends then
if (currentwday == 1 or currentwday == 7) then
Debug("lightblue","Activated by AlarmClock - Weekends")
if useSleepState == true then
fibaro:setGlobal(sleepState, sleepStateMapping.Awake)
end
if (useDevices == true and useDimFixed == false) or (useVD == true and vDeviceIncrFunc == false) or (useHUE == true and useHueFixed == false) then
turnLightOn()
elseif (useVd == true and vDeviceIncrFunc == true) or (useHUE == true and useHueFixed == true) or (useDevices == true and useDimFixed == true) then
wakeUpFunc()
end
end
else
for iVar = 1, 7 do
if alarmDays[i] == weekday[iVar] then
if ((weekday[iVar] == weekday[currentwday])) then
Debug("lightblue","Activated by AlarmClock - "..weekday[currentwday])
if useSleepState == true then
fibaro:setGlobal(sleepState, sleepStateMapping.Awake)
end
if (useDevices == true and useDimFixed == false) or (useVD == true and vDeviceIncrFunc == false) or (useHUE == true and useHueFixed == false) then
turnLightOn()
elseif (useVd == true and vDeviceIncrFunc == true) or (useHUE == true and useHueFixed == true) or (useDevices == true and useDimFixed == true) then
wakeUpFunc()
end
end
end
end
end
end
end
setTimeout(initVar, 55*1000)
end
--- START OF SCENE --------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
if (startSource["type"] == "autostart") then
if useHelper then
helper();
else
startInfo()
end
end
if (startSource["type"] == "global") then
fibaro:sleep(2000)
alarmTime1 = fibaro:getGlobal("AlarmClockTime1")
alarmTime2 = fibaro:getGlobal("AlarmClockTime2")
alarmDay1 = fibaro:getGlobal("AlarmClockDays1")
alarmDay2 = fibaro:getGlobal("AlarmClockDays2")
Debug("lightblue","Triggered by AlarmClock VD")
Debug( "grey", "Next alarm time");
Debug( "grey", "alarmDay1:"..alarmDay1.." alarmTime1:"..alarmTime1);
Debug( "grey", "alarmDay2:"..alarmDay2.." alarmTime2:"..alarmTime2);
if (fibaro:getGlobalValue(alarmClockStatus) == alarmClockMapping.Off) then
Debug("lightblue","Actions will not start until you activate the AlarmClock VD")
else initVar();
end
end