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
AlarmClock + WakeUpTime scene
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
----------------------------------------------------------------------------
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
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.
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.
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
[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
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
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
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.
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.
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
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é?
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
kommer här:
Variablerna:
AlarmClockDays1
Weekdays
AlarmClockDays2
00:00
AlarmClockStatus
On
AlarmClockTime1
22:30
AlarmClockTime2
00:00
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
AlarmClockDays1
Weekdays
AlarmClockDays2
00:00
AlarmClockStatus
On
AlarmClockTime1
22:30
AlarmClockTime2
00:00
Nybörjare sedan 2014
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
Ny lua scene
http://jonnylarsson.se/JL/ACWUT.lua
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.
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.
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
-
- Site Admin
- Posts: 276
- Joined: 10 Dec 2011, 11:43
- 12
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.
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.