AlarmClock + WakeUpTime scene

jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

NEW ALARM CLOCK VERSION

UPDATE to version 3.1.2 (12 January 2017)
Functions corrected

Screenshot_9.png.3ba4a48181bbccf39dc5fc734b51b31d.png
Screenshot_8.png.792faa0ee8442c32a3b62242d78cf8d1.png
alarmClock.png
alarmClock.png (17.22 KiB) Viewed 23957 times
Scene:
ACWUT_3.1.2.zip
(5.18 KiB) Downloaded 787 times
Virtual Device:
Alarm_Clock_3.0.0.zip
(2.32 KiB) Downloaded 819 times
-- 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! :-)

--]]
Scene

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
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50
10

- FGR AND FGRM? I guess it should be a OR statement?

Kristian
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

javisst, det ska vara OR
User avatar
Bamsefar
Z-Wave Kung
Posts: 1268
Joined: 25 Nov 2013, 15:06
10
Location: Stockholm

Kanske kombinerbar med min arbetsdagsuträkning (dvs vart är påsken förlagd osv)? Då borde man få allt automagiskt?
http://www.zwaveforum.se/viewtopic.php?f=21&t=4656
Kör Home Assistant efter totalt nederlag för HomeSeer :twisted: :twisted: :mrgreen:
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50
10

Låter grymt! Att ha mån-sön och en "workday" som är rullande alla arbetsdagar.


Sent from my iPhone using Tapatalk
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

Ny version i första inlägget
User avatar
Bamsefar
Z-Wave Kung
Posts: 1268
Joined: 25 Nov 2013, 15:06
10
Location: Stockholm

Intressant metod att skapa globala variabler inne i LUA koden... Även om jag inte kan franska...
Kör Home Assistant efter totalt nederlag för HomeSeer :twisted: :twisted: :mrgreen:
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50
10

Skulle önska:
- aktiv/inaktiv funktion
- Kan man inte lägga save i mainloop och ta bort knappen?
- Att ha en status rad ihopslagen ex. "Friday - 07:00 - On"

Anledning är främst att spara plats i VD så den syns i 1 skärmbild i tex Iphone och slippa scrolla.

Problem:
- Sätter slidervalue 30, men hoppar efter ett tag upp till 37?!?
- Hur får jag koll på att "huvudiconen" ligger kvar. Ser att du sätter currenticon 428. Borde de inte ligga en get current icon först? så id blir rätt?



Sent from my iPhone using Tapatalk
Last edited by KristianO on 12 Mar 2015, 23:24, edited 1 time in total.
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

ny version, 1.0.0. Uppdaterat första inlägget
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

Typ nåt så här KristianO?
Capture.PNG
Capture.PNG (19.24 KiB) Viewed 97874 times
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50
10

Perfekt!

Alt bara ha dag-tid och låta ikonen visa on/off.

Sent from my iPhone using Tapatalk
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

Ska gå igenom koden innan ny VD kommer, blir nog under dagen
Blir lite nya variabler som skapas för ändamål.
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50
10

Testade förresten din (tror jag) VD för att vid väckning köra Sonos TTS notication vd. Like "good morning". Jag la in vd Id och knapp "1". Men inget händer...


Sent from my iPhone using Tapatalk
User avatar
sonnyboy
Proffsmedlem
Posts: 669
Joined: 26 Sep 2013, 08:05
11
Location: Västerås

Morrn, har en fråga.
Kör senaste AlarmClock i morse tändes lampan tyvärr, kör med Weekdays 05:15.
Är inte weekdays Måndag - Fredag?

Edit
Variabeln står det måndag på, men i debugen står det lördag.
Attachments
alarm.PNG
alarm.PNG (12.67 KiB) Viewed 91434 times
Fibaro HomeCenter 2
Fw 4.600
BeyondMeasure 1.10
EventRunner
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

Upptäckte det själv i morse...gick igenom koden och såg att jag gjort en tankevolt, rättat till den nu. Se första inlägget.
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50
10

Har du testat att köra tex notifications iform av TTS? Trycker på min "godmorgon" så kommer texten fint. Men kör jag den i denna alarmclock så kommer texten 3 ggr...


Sent from my iPhone using Tapatalk
jens
Medlem
Posts: 329
Joined: 22 Apr 2013, 17:09
11

KristianO wrote:Har du testat att köra tex notifications iform av TTS? Trycker på min "godmorgon" så kommer texten fint. Men kör jag den i denna alarmclock så kommer texten 3 ggr...


Sent from my iPhone using Tapatalk
Prova med denna jag använder kör bara en gång...
jens
Medlem
Posts: 329
Joined: 22 Apr 2013, 17:09
11

Missade filen :)

//Jens
Attachments
Sova_TTS.rar
Sova TTS
(2.7 KiB) Downloaded 623 times
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50
10

Tack! Men jag kör Krikroffs Sonos TTS i botten, anropar den via en Notification VD med flera olika knappar för olika TTS. Just en av dessa knappar anropar min väckning. Den sk "god morgon" knappen. Texten som sägs då körs då dock 3 ggr... Trots att det funkar bra om jag trycker på knappen manuellt.


Sent from my iPhone using Tapatalk
Clabbe
Medlem
Posts: 357
Joined: 25 May 2015, 21:53
9
Location: Torslanda

Har ni lyckats lösa så den bara pratar en gång?
-----------------------------------------------------------------
HC2
Aeon Labs, Fibaro, Danfoss enheter (30++st)
Post Reply