AlarmClock + WakeUpTime scene

csabe
Medlem
Posts: 58
Joined: 17 Dec 2014, 15:22

12 Sep 2015, 20:14

Hmm... vet inte vad jag gör för fel men får detta error:

[DEBUG] 20:05:09: WakeUpTime scene - LUA Scripting by Jonny Larsson 2015
[DEBUG] 20:05:09: Version: 1.0.3
[DEBUG] 20:05:09: -- Set alarmtime in virtual device --
[DEBUG] 20:05:09: -- Set slider to how much blinds should open --
[DEBUG] 20:05:09: Alarm is set to Saturday
[ERROR] 20:05:09: line 113: attempt to concatenate global 'alarmTime1' (a nil value)

Går jag in på Variabler (översta) så står det:
alarmDays1 Weekdays
alarmTime1 07:20
Nybörjare sedan 2014
Bonden
Medlem
Posts: 43
Joined: 06 Nov 2013, 20:37

03 Oct 2015, 10:11

Kolla namnen på de globala variablerna. LUA koden försöker läsa in andra variabler än de som VD'n skapar.
csabe
Medlem
Posts: 58
Joined: 17 Dec 2014, 15:22

03 Oct 2015, 10:31

Hmm... jag är lost.

variablerna jag har är "alarmDays1" & "alarmTime1" (har också fått värden)
Vilket verkar vara det som den vill ha på rad 113
Nybörjare sedan 2014
Bonden
Medlem
Posts: 43
Joined: 06 Nov 2013, 20:37

03 Oct 2015, 10:48

Jag ändrade till detta och då funkar det (rad 79 och frammåt...)
----------------------------------------------------------------------------
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 = "17:28"
alarmTime1 = fibaro:getGlobal("alarmTime1")
alarmDay1 = fibaro:getGlobal("alarmDays1")
-------------------------------------------------------------------------------------------------------------

Hittade också ett fel på rad 157

temptbl skall vara tmptbl
Bonden
Medlem
Posts: 43
Joined: 06 Nov 2013, 20:37

03 Oct 2015, 11:05

En cool feature på denna vore att scenen automatiskt plockade de devices som finns i rummet den är tilldelad till. Någon som vet hur man populerar devices {} med prylarna man har i rummet?

En annan feature vore om den tog hänsyn till om det är mörk eller ljust ute. Är det sommar behöver man ju inte tända lamporna när rullgardinen åker upp.
csabe
Medlem
Posts: 58
Joined: 17 Dec 2014, 15:22

03 Oct 2015, 11:27

Tack, verkar nästan funka dock sker detta nu :-)

[DEBUG] 11:16:32: WakeUpTime scene - LUA Scripting by Jonny Larsson 2015
[DEBUG] 11:16:32: Version: 1.0.3
[DEBUG] 11:16:32: -- Set alarmtime in virtual device --
[DEBUG] 11:16:32: -- Set slider to how much blinds should open --
[DEBUG] 11:16:32: Alarm is set to Saturday
[DEBUG] 11:16:32: Next alarmTime is set to next Saturday:11:20
[DEBUG] 11:17:32: Alarm is set to Saturday
[DEBUG] 11:17:32: Next alarmTime is set to next Saturday:11:20
[DEBUG] 11:18:32: Alarm is set to Saturday
[DEBUG] 11:18:32: Next alarmTime is set to next Saturday:11:20
[DEBUG] 11:19:32: Alarm is set to Saturday
[DEBUG] 11:19:32: Next alarmTime is set to next Saturday:11:20
[DEBUG] 11:20:32: Alarm is set to Saturday
[DEBUG] 11:20:32: Start soft wakeup light
[DEBUG] 11:20:33: Increase value to 5.3333333333333
[DEBUG] 11:21:33: timer stop, lights turned off
[DEBUG] 11:22:33: Alarm is set to Saturday
[DEBUG] 11:22:33: Next alarmTime is set to next Saturday:11:20

Code: Select all

-------------------- USER SETTINGS -----------------------
devices = {162}   -- Lights, dimmers and blinds {162,341,24,256,335,337,25}
_maxValue = 80             -- When dimmer reach this value it will stop there
_duration = 15            -- 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 = 174          -- Id of Sonos virtual device
vDeviceButton = 7          -- Play
vDeviceFunc = false         -- set to true to activate Sonos/Internet Radio

-- Dimmers to set to fixed value when alarmWakeup
Dimdevices = {162}         -- Dimmers to set to fixed value
fixedValue = 80            -- Dimmer value
DimdevicesFunc = true      -- set to true or false

(HAR INTE DETTA VAD JAG VET)
--TimeOfDay variable -- 
varTOD = "TimeOfDay"      -- TOD translate
varTODMorning = "Morgon"   -- TOD Morning translate
varState = "SleepState"      -- TOD translate
varStateMorning = "Vaken"   -- TOD Morning translate
variableFunc = true      -- set to true or false
Nybörjare sedan 2014
Bonden
Medlem
Posts: 43
Joined: 06 Nov 2013, 20:37

03 Oct 2015, 11:51

Du har device 162 både i dimdevice och devices. Testa att stänga av funktionen dimdevice på rad 55
csabe
Medlem
Posts: 58
Joined: 17 Dec 2014, 15:22

03 Oct 2015, 13:20

Attans, får inte till det.

Lampan som bara ska tändas tänds det funkar fint. Men uppdimmringen händer det inget med.
Har provat att kasta om lamporna, med samma effekt.

[DEBUG] 13:09:36: WakeUpTime scene - LUA Scripting by Jonny Larsson 2015
[DEBUG] 13:09:36: Version: 1.0.3
[DEBUG] 13:09:36: -- Set alarmtime in virtual device --
[DEBUG] 13:09:36: -- Set slider to how much blinds should open --
[DEBUG] 13:09:36: Alarm is set to Saturday
[DEBUG] 13:09:36: Next alarmTime is set to next Saturday:13:10
[DEBUG] 13:10:23: Alarm is set to Saturday
[DEBUG] 13:10:23: Start soft wakeup light
[DEBUG] 13:10:24: Increase value to 5.3333333333333
[DEBUG] 13:10:36: Alarm is set to Saturday
[DEBUG] 13:10:36: Start soft wakeup light
[DEBUG] 13:10:37: Increase value to 5.3333333333333
[DEBUG] 13:11:24: timer stop, lights turned off
[DEBUG] 13:11:37: timer stop, lights turned off
[DEBUG] 13:12:24: Alarm is set to Saturday
[DEBUG] 13:12:24: Next alarmTime is set to next Saturday:13:10
Nybörjare sedan 2014
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
Location: Hofors

01 Nov 2015, 19:36

Ny version 2.0.1
LUA koden kommer kolla min server om det finns en uppdatering att hämta, om det finns så dyker det upp en länk i debug fönstret som är klickbar.
post-873-0-35212800-1446536811.png
post-873-0-35212800-1446536811.png (14.08 KiB) Viewed 18299 times

Code: Select all

--[[ 

INSTRUCTIONS
* 
* add those devices you want to use in this script to "devices"
* set dimmer device to a "_maxValue"
* set "_duration" to a value in minutes for how long the dim function should be active
* to activate debug, helper and versionCheck set the value to true or false

* helper is to show all "lights" in your system.
* debug is debug :)
* versionCheck checks if script is updated. Click on "Get it" 

--]]

-- REFERENCE
-- forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se 
-- Thanks to robmac, stevenvd for good LUA functions code.

-- 2015-11-01 ver 2.0.0 new version of scene and virtual device. Supports 2 alarm.
-- 2015-11-02 ver 2.0.1 list all lights in scene. Add those you want to use in 'User Settings' section

-- SCENE SCENARIO
-- Advanced wakeup scene to turnOn lights at specified time, time you set in
-- alarm clock virtual device
-- Set value for how much the blinds should open with the slider in VD.

Code: Select all

--[[
%% autostart
%% properties
%% globals
AlarmClockStatus
AlarmClockDays1
AlarmClockDays2

--]]

--[[ 

INSTRUCTIONS
* 
* add those devices you want to use in this script to "devices"
* set dimmer device to a "_maxValue"
* set "_duration" to a value in minutes for how long the dim function should be active
* to activate debug, helper and versionCheck set the value to true or false

* helper is to show all "lights" in your system.
* debug is debug :)
* versionCheck checks if script is updated. Click on "Get it" 

--]]

-- REFERENCE
-- forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se 
-- Thanks to robmac, stevenvd for good LUA functions code.

-- 2015-11-01 ver 2.0.0 new version of scene and virtual device. Supports 2 alarm.
-- 2015-11-02 ver 2.0.1 list all lights in scene. Add those you want to use in 'User Settings' section

-- SCENE SCENARIO
-- Advanced wakeup scene to turnOn lights at specified time, time you set in
-- alarm clock virtual device
-- Set value for how much the blinds should open with the slider in VD.

version = "{2.0.1}"

-------------------- USER SETTINGS -----------------------
devices = {339,341,24,256,335,337,25}	-- Lights, dimmers and blinds
_maxValue = 50	 			-- When dimmer reach this value it will stop there
_duration = 5				-- Time in minutes for how long wakeUp should be active
debug = true				-- set debug to true or false
helper = false				-- loop through all devices and search for lights/dimmers/binarySwitch etc
versionCheck = true		-- check if new version of script exist on server

-- EXTRA FUNCTIONS, OPTIONS
-- Start Sonos/Internet Radio
vDeviceID = 393 			-- Id of Sonos virtual device
vDeviceButton = 7 			-- Play
vDeviceFunc = false			-- set to true to activate Sonos/Internet Radio

-- Dimmers to set to fixed value when alarmWakeup
Dimdevices = {343}			-- Dimmers to set to fixed value
fixedValue = 50				-- Dimmer value
DimdevicesFunc = false		-- set to true or false

--TimeOfDay variable --
varTOD = "TimeOfDay"		-- TOD translate
varTODMorning = "Morgon"	-- TOD Morning translate
varState = "SleepState"		-- TOD translate
varStateMorning = "Vaken"	-- TOD Morning translate
variableFunc = true			-- set to true or false
-----------------------------------------------------------
timeNow = os.date("%H:%M")
dayName = os.date("%A")

------------- DO NOT CHANGE LINES BELOW -------------------
startSource = fibaro:getSourceTrigger();
sortedtbl = {}
tmptbl = {}
runOnce = true
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}


-- 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);
Debug( "lightgreen", "-- Set alarmtime in virtual device --");
Debug( "lightgreen", "-- Set slider to how much blinds should open --");


function timerFunction()
  
-- Check if alarmDay2 is in use, else remove it from tables
if alarmDay2 == "00:00" then
   table.remove(alarmDays, 2)
   table.remove(alarmTimes, 2)
end
for i = 1,#alarmDays do
    	--Check if day and time is same as alarmDays and alarmTimes
    	if timeNow == alarmDays[i] and alarmTimes[i] then
      		-- Sort table of devices
			sortTable()
    	else 
    		if (debug) then
    			Debug( "grey", "Next alarmTime is set to next "..alarmDays[i]..":"..alarmTimes[i]);
    		end
      	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" or fibaro:getType(lightItems) == "com.fibaro.FGWP101" then
            table.insert(sortedtbl,lightItems)
       elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
          table.insert(sortedtbl,lightItems)
       elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" 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" or fibaro:getType(lightItems) == "com.fibaro.FGWP101" 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" then
         	table.insert(tmptbl,lightItems)
       end
    end
		if (DimdevicesFunc) then
   			for i = 1,#Dimdevices do
       			DimItems = Dimdevices[i];
       			fibaro:call(DimItems, "setValue", fixedValue);
    		end
		end
if (vDeviceFunc) then
   		fibaro:call(vDeviceID, "pressButton", vDeviceButton)
end
if tmptbl == nil then
if (debug) then
	Debug( "red",'No dimmers in table, will not run next function')
end
else wakeUpFunc()end

end

-- Now its time to turnOn some lights
wakeUpFunc = function()
if (debug) then
	Debug( "green",'Start soft wakeup light')
end
for i = 1,#tmptbl do
    lightItems = tmptbl[i];
    fibaro:call(lightItems, "setValue", "0");
	fibaro:sleep(200);
	addValue = _maxValue / tonumber(_duration);
    local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
    local newValue = currentValueLights + addValue;
end
fibaro:sleep(1000);
  
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
    	for i = 1,#tmptbl do
    	lightItems = tmptbl[i];
  			fibaro:call(lightItems, "setValue", newValue);
      	end
  		--Waits before the next step
    	fibaro:sleep(60*1000);
end
end

insert2Table = function()
if runOnce then
sortedtbl = {}
  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)) then
      	table.insert(sortedtbl,i)
    end
  end
end
  Debug( "grey","All your lights will be listed in a table below, add them in devices in 'User Settings' section")
  Debug( "grey",json.encode(sortedtbl))
  runOnce = false
end

------ CHECK SCRIPT VERSION ON SERVER ------
function versionChecker()
local function getMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
  http:request(requestUrl, {
      options = {
        method = 'GET',
        headers = {
        },
      },
      success = successCallback,
      error = errorCallback
  })
end
content = "ACWUT.lua"
local url = 'http://jonnylarsson.se/JL/'..content

getMethod(url, function(resp)
	s = resp.data
    serverVersion = string.match(s, "{(.-)}");
    scriptVersion = string.match(version, "{(.-)}");
    if serverVersion > scriptVersion then
    	Debug("grey", "Checking script version...") 
    	Debug("yellow", "There is a new version out! "..'<a href="http://jonnylarsson.se/JL/ACWUT.lua" target="_blank" style="display:inline;color:Cyan">Get it!</a>')

    end
    end,
  	function(err)
    print('error' .. err)
end
)
end
---------------- SCRIPT CHECK END ---------------------



------------------ START OF SCENE ----------------------
if ( startSource["type"] == "autostart" ) or ( startSource["type"] == "global" ) then
	if helper then
		insert2Table()
	end
	if versionCheck then
		versionChecker()
	end
  	if fibaro:getGlobal("AlarmClockStatus") == "On" then
		timerFunction()
    else Debug( "blue","Scene is not active until you set AlarmClock to On")
    end
end
alarmClock VD 2.0.png
alarmClock VD 2.0.png (47.08 KiB) Viewed 18355 times
Alarm_Clock_2.0.vfib.zip
(2.83 KiB) Downloaded 370 times
csabe
Medlem
Posts: 58
Joined: 17 Dec 2014, 15:22

19 Nov 2015, 23:33

Känner mig sjukt dum i huvudet, fick inte förra versionen att funka och hoppades på denna men inte här heller :-)
Förstår inte vad jag gör för fel, inte så många ställen att ändra tycker jag.

1. Har kopierat och klistrat in ovanstående kod i en ny scen.
2. Ändrat id till de lampor som ska används.
3. Läst in virutal devicen. Ställt in tiden och weekdays.

Scenen säger:

[DEBUG] 22:28:06: WakeUpTime scene - LUA Scripting by Jonny Larsson 2015
[DEBUG] 22:28:06: Version: {2.0.1}
[DEBUG] 22:28:06: -- Set alarmtime in virtual device --
[DEBUG] 22:28:06: -- Set slider to how much blinds should open --
[DEBUG] 22:28:06: Next alarmTime is set to next Weekdays:22:30
[DEBUG] 22:28:44: Next alarmTime is set to next Weekdays:22:25
[DEBUG] 22:29:06: Next alarmTime is set to next Weekdays:22:30
[DEBUG] 22:29:44: Next alarmTime is set to next Weekdays:22:25
[DEBUG] 22:30:06: Next alarmTime is set to next Weekdays:22:30
[DEBUG] 22:30:44: Next alarmTime is set to next Weekdays:22:25
[DEBUG] 22:31:06: Next alarmTime is set to next Weekdays:22:30
[DEBUG] 22:31:44: Next alarmTime is set to next Weekdays:22:25
[DEBUG] 22:32:06: Next alarmTime is set to next Weekdays:22:30

Nu visar det också två tider vilket är konstigt för jag har bara ställt in en tid på 1:an
Först 22:25, sedan 22:30 när det innan inte funkade.

Någon idé?
Nybörjare sedan 2014
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
Location: Hofors

20 Nov 2015, 08:43

Hejsan
kan du ge mig koden som du lagt så kan jag se om du har gjort något fel, men det kan vara så att det är jag också ;)

//Jonny
csabe
Medlem
Posts: 58
Joined: 17 Dec 2014, 15:22

20 Nov 2015, 08:53

kommer här:

Code: Select all

--[[
%% autostart
%% properties
%% globals
AlarmClockStatus
AlarmClockDays1
AlarmClockDays2

--]]

--[[ 

INSTRUCTIONS
* 
* add those devices you want to use in this script to "devices"
* set dimmer device to a "_maxValue"
* set "_duration" to a value in minutes for how long the dim function should be active
* to activate debug, helper and versionCheck set the value to true or false

* helper is to show all "lights" in your system.
* debug is debug :)
* versionCheck checks if script is updated. Click on "Get it" 

--]]

-- REFERENCE
-- forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se 
-- Thanks to robmac, stevenvd for good LUA functions code.

-- 2015-11-01 ver 2.0.0 new version of scene and virtual device. Supports 2 alarm.
-- 2015-11-02 ver 2.0.1 list all lights in scene. Add those you want to use in 'User Settings' section

-- SCENE SCENARIO
-- Advanced wakeup scene to turnOn lights at specified time, time you set in
-- alarm clock virtual device
-- Set value for how much the blinds should open with the slider in VD.

version = "{2.0.1}"

-------------------- USER SETTINGS -----------------------
devices = {162,37,34}   -- Lights, dimmers and blinds
_maxValue = 95             -- When dimmer reach this value it will stop there
_duration = 5            -- Time in minutes for how long wakeUp should be active
debug = true            -- set debug to true or false
helper = false            -- loop through all devices and search for lights/dimmers/binarySwitch etc
versionCheck = true      -- check if new version of script exist on server

-- EXTRA FUNCTIONS, OPTIONS
-- Start Sonos/Internet Radio
vDeviceID = 174          -- Id of Sonos virtual device
vDeviceButton = 7          -- Play
vDeviceFunc = false         -- set to true to activate Sonos/Internet Radio

-- Dimmers to set to fixed value when alarmWakeup
Dimdevices = {34}         -- 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
varState = "SleepState"      -- TOD translate
varStateMorning = "Vaken"   -- TOD Morning translate
variableFunc = false         -- set to true or false
-----------------------------------------------------------
timeNow = os.date("%H:%M")
dayName = os.date("%A")

------------- DO NOT CHANGE LINES BELOW -------------------
startSource = fibaro:getSourceTrigger();
sortedtbl = {}
tmptbl = {}
runOnce = true
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}


-- 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);
Debug( "lightgreen", "-- Set alarmtime in virtual device --");
Debug( "lightgreen", "-- Set slider to how much blinds should open --");


function timerFunction()
  
-- Check if alarmDay2 is in use, else remove it from tables
if alarmDay2 == "00:00" then
   table.remove(alarmDays, 2)
   table.remove(alarmTimes, 2)
end
for i = 1,#alarmDays do
       --Check if day and time is same as alarmDays and alarmTimes
       if timeNow == alarmDays[i] and alarmTimes[i] then
            -- Sort table of devices
         sortTable()
       else 
          if (debug) then
             Debug( "grey", "Next alarmTime is set to next "..alarmDays[i]..":"..alarmTimes[i]);
          end
         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" or fibaro:getType(lightItems) == "com.fibaro.FGWP101" then
            table.insert(sortedtbl,lightItems)
       elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
          table.insert(sortedtbl,lightItems)
       elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" 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" or fibaro:getType(lightItems) == "com.fibaro.FGWP101" 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" then
            table.insert(tmptbl,lightItems)
       end
    end
      if (DimdevicesFunc) then
            for i = 1,#Dimdevices do
                DimItems = Dimdevices[i];
                fibaro:call(DimItems, "setValue", fixedValue);
          end
      end
if (vDeviceFunc) then
         fibaro:call(vDeviceID, "pressButton", vDeviceButton)
end
if tmptbl == nil then
if (debug) then
   Debug( "red",'No dimmers in table, will not run next function')
end
else wakeUpFunc()end

end

-- Now its time to turnOn some lights
wakeUpFunc = function()
if (debug) then
   Debug( "green",'Start soft wakeup light')
end
for i = 1,#tmptbl do
    lightItems = tmptbl[i];
    fibaro:call(lightItems, "setValue", "0");
   fibaro:sleep(200);
   addValue = _maxValue / tonumber(_duration);
    local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
    local newValue = currentValueLights + addValue;
end
fibaro:sleep(1000);
  
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
       for i = 1,#tmptbl do
       lightItems = tmptbl[i];
           fibaro:call(lightItems, "setValue", newValue);
         end
        --Waits before the next step
       fibaro:sleep(60*1000);
end
end

insert2Table = function()
if runOnce then
sortedtbl = {}
  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)) then
         table.insert(sortedtbl,i)
    end
  end
end
  Debug( "grey","All your lights will be listed in a table below, add them in devices in 'User Settings' section")
  Debug( "grey",json.encode(sortedtbl))
  runOnce = false
end

------ CHECK SCRIPT VERSION ON SERVER ------
function versionChecker()
local function getMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
  http:request(requestUrl, {
      options = {
        method = 'GET',
        headers = {
        },
      },
      success = successCallback,
      error = errorCallback
  })
end
content = "ACWUT.lua"
local url = 'http://jonnylarsson.se/JL/'..content

getMethod(url, function(resp)
   s = resp.data
    serverVersion = string.match(s, "{(.-)}");
    scriptVersion = string.match(version, "{(.-)}");
    if serverVersion > scriptVersion then
       Debug("grey", "Checking script version...") 
       Debug("yellow", "There is a new version out! "..'<a href="http://jonnylarsson.se/JL/ACWUT.lua" target="_blank" style="display:inline;color:Cyan">Get it!</a>')

    end
    end,
     function(err)
    print('error' .. err)
end
)
end
---------------- SCRIPT CHECK END ---------------------



------------------ START OF SCENE ----------------------
if ( startSource["type"] == "autostart" ) or ( startSource["type"] == "global" ) then
   if helper then
      insert2Table()
   end
   if versionCheck then
      versionChecker()
   end
     if fibaro:getGlobal("AlarmClockStatus") == "On" then
      timerFunction()
    else Debug( "blue","Scene is not active until you set AlarmClock to On")
    end
end
Variablerna:
AlarmClockDays1
Weekdays

AlarmClockDays2
00:00

AlarmClockStatus
On

AlarmClockTime1
22:30

AlarmClockTime2
00:00
Nybörjare sedan 2014
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
Location: Hofors

23 Nov 2015, 10:47

Ser var felet ligger någonstans och behöver göra en fix för detta, men du kan ta bort AlarmClockDays2 variabeln och sen spara om den virtuella enheten så skapar den om variabeln igen.
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50

23 Nov 2015, 14:18

Om man bara vill ha 1 tid likt version 1. Vilken version är stabil utan buggar?


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

23 Nov 2015, 18:59

Ny virtuell enhet för att hantera båda alarm tiderna bättre, går att sätta dom till "Off".

Ny lua scene
http://jonnylarsson.se/JL/ACWUT.lua
Skärmavbild 2015-11-23 kl. 17.46.25.png
Skärmavbild 2015-11-23 kl. 17.46.25.png (51.93 KiB) Viewed 18079 times
Alarm_Clock_2.1.vfib.zip
(2.96 KiB) Downloaded 388 times
acwut.png
acwut.png (19.94 KiB) Viewed 18079 times
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
Location: Hofors

23 Nov 2015, 19:12

Finns en version 2.1.0 nu
KristianO
Medlem
Posts: 461
Joined: 10 Mar 2014, 09:50

23 Nov 2015, 21:02

Jo tack! Men vill bara ha 1 tid, då jag vill att hela min VD skall synas i min iPhone utan att behöva scrolla.


Sent from my iPhone using Tapatalk
csabe
Medlem
Posts: 58
Joined: 17 Dec 2014, 15:22

26 Dec 2015, 16:05

Hej det är jag igen! :-)
Asså jag får inte detta att funka, förstår inte vad jag gör för fel. Nu har jag raderat allt gammalt och försökt lägga in det på nytt:

VDn har jag inte ändrat något på, mer ät dag och tid för alarm.
Scenen ändrade jag nu bara lamporna som ska dimmras.

Skulle gärna få detta att funka då det verkar smidigare än det jag har nu.
Skärmavbild 2015-12-26 kl. 15.01.12.png
Skärmavbild 2015-12-26 kl. 15.01.12.png (69.62 KiB) Viewed 17722 times

Code: Select all

--[[
%% autostart
%% properties
%% globals
AlarmClockStatus
AlarmClockDays1
AlarmClockDays2
AlarmClockTime1
AlarmClockTime2

--]]

--[[ 

INSTRUCTIONS
* 
* add those devices you want to use in this script to "devices"
* set dimmer device to a "_maxValue"
* set "_duration" to a value in minutes for how long the dim function should be active
* to activate debug, helper and versionCheck set the value to true or false

* helper is to show all "lights" in your system.
* debug is debug :)
* versionCheck checks if script is updated. Click on "Get it" 

--]]

-- SCENE SCENARIO
-- Advanced wakeup scene to turnOn lights at specified time, time you set in
-- alarm clock virtual device
-- Set value for how much the blinds should open with the slider in VD.


-- REFERENCE
-- forum.fibaro.com, lua.org, domotique-fibaro.fr, www.gronahus.se 
-- Thanks to robmac, stevenvd for good LUA functions code.

-- 2015-11-01 ver 2.0.0 new version of scene and virtual device. Supports 2 alarm.
-- 2015-11-02 ver 2.0.1 list all lights in scene. Add those you want to use in 'User Settings' section
-- 2015-11-27 ver 2.1.1 adjustment of debug lines and added variable to %% globals

version = "{2.1.1}"

-------------------- USER SETTINGS -----------------------
devices = {34,37}	-- Lights, dimmers and blinds
_maxValue = 100	 			-- When dimmer reach this value it will stop there
_duration = 5				-- Time in minutes for how long wakeUp should be active
debug = true				-- set debug to true or false
helper = false				-- loop through all devices and search for lights/dimmers/binarySwitch etc
versionCheck = true		-- check if new version of script exist on server

-- EXTRA FUNCTIONS, OPTIONS
-- Start Sonos/Internet Radio
vDeviceID = 393 			-- Id of Sonos virtual device
vDeviceButton = 7 			-- Play
vDeviceFunc = false			-- set to true to activate Sonos/Internet Radio

-- Dimmers to set to fixed value when alarmWakeup
Dimdevices = {343}			-- Dimmers to set to fixed value
fixedValue = 50				-- Dimmer value
DimdevicesFunc = false		-- set to true or false

--TimeOfDay variable --
varTOD = "TimeOfDay"		-- TOD translate
varTODMorning = "Morgon"	-- TOD Morning translate
varState = "SleepState"		-- TOD translate
varStateMorning = "Vaken"	-- TOD Morning translate
variableFunc = false			-- set to true or false
-----------------------------------------------------------
timeNow = os.date("%H:%M")
dayName = os.date("%A")

------------- DO NOT CHANGE LINES BELOW -------------------
startSource = fibaro:getSourceTrigger();
sortedtbl = {}
tmptbl = {}
runOnce = true
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}


-- 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);
Debug( "lightgreen", "-- Set alarmtime in virtual device --");
Debug( "lightgreen", "-- Set slider to how much blinds should open --");
if alarmDay1 ~= "Off" then 
  Debug( "grey", "Next alarm time is set to next "..alarmDay1..":"..alarmTime1)
end
if alarmDay2 ~= "Off" then 
  Debug( "grey", "Next alarm time is set to next "..alarmDay2..":"..alarmTime2)
end

function timerFunction()
timeNow = os.date("%H:%M") 
-- Check if alarmDay2 is in use, else remove it from tables
if alarmDay2 == "Off" then
   table.remove(alarmDays, 2)
   table.remove(alarmTimes, 2)
end
for i = 1,#alarmDays do
    	--Check if day and time is same as alarmDays and alarmTimes
    	if timeNow == alarmDays[i] and alarmTimes[i] then
      		-- Sort table of devices
			sortTable()
    	--else 
    		--if (debug) then
    			--Debug( "grey", "Next alarmTime is set to next "..alarmDays[i]..":"..alarmTimes[i]);
    		--end
      	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" or fibaro:getType(lightItems) == "com.fibaro.FGWP101" then
            table.insert(sortedtbl,lightItems)
       elseif fibaro:getType(lightItems) == "com.fibaro.binarySwitch" then
          table.insert(sortedtbl,lightItems)
       elseif fibaro:getType(lightItems) == "com.fibaro.multilevelSwitch" 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" or fibaro:getType(lightItems) == "com.fibaro.FGWP101" 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" then
         	table.insert(tmptbl,lightItems)
       end
    end
		if (DimdevicesFunc) then
   			for i = 1,#Dimdevices do
       			DimItems = Dimdevices[i];
       			fibaro:call(DimItems, "setValue", fixedValue);
    		end
		end
if (vDeviceFunc) then
   		fibaro:call(vDeviceID, "pressButton", vDeviceButton)
end
if tmptbl == nil then
if (debug) then
	Debug( "red",'No dimmers in table, will not run next function')
end
else wakeUpFunc()end

end

-- Now its time to turnOn some lights
wakeUpFunc = function()
if (debug) then
	Debug( "green",'Start soft wakeup light')
end
for i = 1,#tmptbl do
    lightItems = tmptbl[i];
    fibaro:call(lightItems, "setValue", "0");
	fibaro:sleep(200);
	addValue = _maxValue / tonumber(_duration);
    local currentValueLights = tonumber(fibaro:getValue(lightItems, "value"));
    local newValue = currentValueLights + addValue;
end
fibaro:sleep(1000);
  
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
    	for i = 1,#tmptbl do
    	lightItems = tmptbl[i];
  			fibaro:call(lightItems, "setValue", newValue);
      	end
  		--Waits before the next step
    	fibaro:sleep(60*1000);
end
end

insert2Table = function()
if runOnce then
sortedtbl = {}
  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)) then
      	table.insert(sortedtbl,i)
    end
  end
end
  Debug( "grey","All your lights will be listed in a table below, add them in devices in 'User Settings' section")
  Debug( "grey",json.encode(sortedtbl))
  runOnce = false
end

------ CHECK SCRIPT VERSION ON SERVER ------
function versionChecker()
local function getMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
  http:request(requestUrl, {
      options = {
        method = 'GET',
        headers = {
        },
      },
      success = successCallback,
      error = errorCallback
  })
end
content = "ACWUT.lua"
local url = 'http://jonnylarsson.se/JL/'..content

getMethod(url, function(resp)
	s = resp.data
    serverVersion = string.match(s, "{(.-)}");
    scriptVersion = string.match(version, "{(.-)}");
    if serverVersion > scriptVersion then
    	Debug("grey", "Checking script version...") 
    	Debug("yellow", "There is a new version out! "..'<a href="http://jonnylarsson.se/JL/ACWUT.lua" target="_blank" style="display:inline;color:Cyan">Get it!</a>')

    end
    end,
  	function(err)
    print('error' .. err)
end
)
end
---------------- SCRIPT CHECK END ---------------------



------------------ START OF SCENE ----------------------
if ( startSource["type"] == "autostart" ) or ( startSource["type"] == "global" ) then
	if helper then
		insert2Table()
	end
	if versionCheck then
		versionChecker()
	end
  	if alarmDay1 ~= "Off" or alarmDay2 ~= "Off" then
		timerFunction()
    else Debug( "blue","Scene is not active until you set alarmclock time and day in virtual device")
    end
end
Nybörjare sedan 2014
forumadmin
Site Admin
Posts: 251
Joined: 10 Dec 2011, 11:43

08 Feb 2016, 11:08

Tjenare Jompa68.

Av någon anledning får jag inte ACWUT att fungera på SW 4.071.
Dels tar det ca 15-20 sek att byta dag eller ändra tid. Upplever ni samma sak?

I övrigt så startar den inte heller på utsatt tid. Inga fel visas i debug'en.
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
Location: Hofors

08 Feb 2016, 14:45

Hupp!
Jag kan slå en kik på den under veckan. Har inte kollat själv efter sista uppdateringen


Regards Jonny Larsson
From my iPhone6+ med Tapatalk
Post Reply