Time over midnight
Posted: Thursday 19 January 2017 21:17
Hi
I try to turn off light in my living room automatically. But I'm facing a problem. When I use time between 16 and 23, then it works perfekt. But when I use the time between 23 and 6 in the morning, the script does not work anymore. Does anybody know, how I can make a time shift over midnight? The script looks like this:
Can anybody help me with the midnight problem?
I try to turn off light in my living room automatically. But I'm facing a problem. When I use time between 16 and 23, then it works perfekt. But when I use the time between 23 and 6 in the morning, the script does not work anymore. Does anybody know, how I can make a time shift over midnight? The script looks like this:
Code: Select all
dayNow = tonumber(os.date('%w'))
hourNow = tonumber(os.date('%H'))
if (globalvariables['Security']) == 'Disarmed' or devicechanged['Dummy Disarmed'] == 'On' then
if ((devicechanged['Bewegungssensor_WZ'] == 'On' and tonumber(w) < 20) and otherdevices['Licht_WZ'] == 'Off') then
commandArray['Licht_WZ'] = 'On'
elseif ((otherdevices['Bewegungssensor_WZ'] == 'Off' and tonumber(w) < 20) and otherdevices['Licht_WZ'] == 'On') then
if (((dayNow > 0) and (dayNow < 6)) and ((hourNow > 16) and (hourNow <= 23))) then
commandArray['Licht_WZ'] = 'Off AFTER 3600'
print('Es ist Wochentag zwischen 16 und 23 Uhr')
elseif (((dayNow > 0) or (dayNow < 6) and (hourNow > 23) and (hourNow <= 6))) then
commandArray['Licht_WZ'] = 'Off AFTER 3600'
print('Es ist Wochentag zwischen 17 und 22 Uhr')
elseif (((dayNow == 0) or (dayNow == 6) and (hourNow > 19) and (hourNow < 6))) then
commandArray['Licht_WZ'] = 'Off AFTER 1200'
print('Es ist Wochenende zwischen 22 und 6 Uhr')
elseif (((dayNow == 0) or (dayNow == 6) and (hourNow > 17) and (hourNow <= 19))) then
commandArray['Licht_WZ'] = 'Off AFTER 3600'
print('Es ist Wochenende zwischen 17 und 22 Uhr')
end