Hi everyone,
I'm quite new to domoticz and so far I was able to figure out most things by reading in this forum and the domoticz wiki.
So far I have a Spirit-z thermostat and a domitech zBulb in my system and I try to take my WakeUp Scenario to the next level with the help of Lua.
With blockly I'm already able to heat up the bathroom before I wake up and to have the light in my sleeping room come up slowly.
However I want to use lua to substract 25 minutes from my alarm time in order to start the wake up procedure. At the moment I do this substraction manually.
To automize it I tried stuff like:
commandArray={}
commandArray['Variable:WakeUp_Begin'] = tostring(tonumber(uservariables["Alarm_Time"])-25)
return commandArray
which obviously doesn't work. I probably have to transform the "Alarm_Time" somehow, so I can do arithmetics with it. What do I have to do?
I would much appreciate if you guys could help me with this problem.
Thanks a lot in advance!
[solved] Substract Minutes from Alarm Time
Moderator: leecollings
-
- Posts: 3
- Joined: Sunday 04 February 2018 23:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
[solved] Substract Minutes from Alarm Time
Last edited by d3nn1s on Saturday 10 February 2018 20:41, edited 1 time in total.
-
- Posts: 3
- Joined: Sunday 04 February 2018 23:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Substract Minutes from Alarm Time
Okay I solved it this way:
Code: Select all
-- uservariables["Wecker_Uhrzeit"] is the alarm time which I set from my smart phone. It's a user time variable holding a string in the format HH:MM.
-- Dimmer_Dauer is the number of minutes I want the wake up process to start before my alarm rings.
commandArray = {}
local Dimmer_Dauer=25 -- Set dimming duration to 25 Minutes
local Hour=string.sub(uservariables["Wecker_Uhrzeit"],1,2); -- Here it gets funny: The string holding the alarm time has to be decomposed into hours and minutes. Here I extract the hours by taking the first two etrys of the string into the local variable Hour
local Minute=string.sub(uservariables["Wecker_Uhrzeit"],4,5); -- Here I extract the minutes by taking the third and fourth etry of the string into the local variable Minute.
local Wecker_Sekunden=os.time{year=1970, month=1, day=1, hour=tonumber(Hour), min=tonumber(Minute)}; --here there strigs with the extracted hours and minutes have to converted into numbers and then into seconds, which I find really funny. This is done by the os.time function. The year, month and day don't matter at all, because after the following math I only extract the hour and minute again. They have to be defined however.
local WakeUp_Sekunden=Wecker_Sekunden-Dimmer_Dauer*60; -- This is the part which does what I intentionally wanted to do. Substracting the duration of the dimming from my alarm time. The local variable WakeUp_Sekunden now holds the desired beginning of the wake up process as a number of seconds from the date defined in the os.time function above.
local WakeUp_Beginn=tostring(os.date("%H:%M",WakeUp_Sekunden)); --the os.date function transforms the desired wake up time from seconds back to a string in the format HH:MM. This is done by choosing only hours and minutes through the %H, the : and the %M.
commandArray['Variable:WakeUp_Beginn']=WakeUp_Beginn; --This updates my user variable which blockly uses to start the wake up process.
return commandArray
-- google about os.time and os.date if you have trouble understanding what these functions do.
Who is online
Users browsing this forum: Google [Bot] and 1 guest