I have a script that should turn on a group in the morning 05:45 on weekdays and 07:00 on weekends. If the sun is already up since more than 20 minutes the light should not turn on. The group has both light indoor and outdoor. If it's daylight the the outdoor lights should turn off.
If the time have passed sunrise with more than 2 hours and there has been no movement in the house for the past 20 minutes the all light should turn off.
When the time pass 10 o'clock in the morning the light should be turned off no matter movements or not.
I have a variable with Idx (5) that another script set to "Natt" when the light goes out in the evening.
The lights goes on as intended but it does not turn off at all. Obviously there is something wrong in my amature script
Anyone that can see my mistake and enlight me?
Code: Select all
return {
active = true,
on = {
timer = {'at 05:45 - 10:15 every 5 minutes on mon,tue,wed,thu,fri', 'at 07:00 - 10:15 every 5 minutes on sat, sun'}
},
execute = function(domoticz, device)
local Morgon = domoticz.groups(1) ----- all lights in the group that should turn on in the morning
local Alla = domoticz.groups(2) ----- all lights inside the house
local Ute = domoticz.groups(5) ----- all lights outside the house
local Kok_pir = domoticz.devices(161) ----- Pir in the kitchen
local Hall_pir = domoticz.devices(37) ----- Pir in the hallway
local tid = domoticz.time.secondsSinceMidnight/60 --- time since midnight in minutes
local tidig = (domoticz.time.sunriseInMinutes + 20) --- should not turn on if this has passed
local sen = (domoticz.time.sunriseInMinutes + 120) ---- turn of if no movement at this time
local status = domoticz.variables(5) --- the variable that I use to control the status
if tid < tidig and status.value == 'Natt' then
Morgon.switchOn()
status.set('Morgon')
elseif domoticz.time.isDayTime and status.value == 'Morgon' then
Ute.switchOff()
status.set('Dagsljus')
elseif tid > sen and Hall_pir.lastUpdate.minutesAgo > 20 and Kok_pir.lastUpdate.minutesAgo > 20 and status.value ~= 'Dag' then
Alla.switchOff()
Ute.switchOff()
status.set('Dag')
elseif status.value ~= 'Dag' and tid >= 600 then
Ute.switchOff()
Alla.switchOff()
status.set('Dag')
end
end
}