I've made a new script to control my outdoor lights (previous was in blockly). My first attempt worked (see an example at First code), but I noticed that when the script triggered at 15 minutes after sunset (or at 05:40), the script started more then 1000 times. The lights were going on and the logging of the lights showed ~2,130 entries (7 days of history). My Domotiz crashed a little later. To prevent that much of On commands, I've changed my script to the current script. Now the On and Off commands are only 1 or 2. But Domoticz is still crashing sometimes and I have the feeling that this is because of this script that starts still a lot of times in one minute (or is it coincidence?). Am I doing something wrong or is this a bug?
First code:
Code: Select all
if domoticz.time.matchesRule(ONEVENING) then
LOGGING = LOGGING .."\n".."Program On-Evening"
OUTDOORHALLWAY.switchOn()
OUTDOORSTORAGEROOM.switchOn()
Code: Select all
--[[
SCRIPT DESCRIPTION:
This script turns on and off the outdoor lights based on time, sunset and sunrise.
DEVICES USED:
Idx 39 = Berging buitenlamp
Idx 43 = Gang buitenlamp
]]--
--SET USER INPUT VARIABLES:
local IDOSR = 39
local IDOHW = 43
local SECLLOFF = 60 -- turn off the lights after xx seconds at day time
local ONMORNING = 'at 05:40 on mon,tue,wed,thu,fri'
local OFFMORNING = '15 minutes before sunrise on mon,tue,wed,thu,fri'
local ONEVENING = '15 minutes after sunset'
local OFFEVENING = 'at 23:30'
local LOGGINGON = "Yes" -- turn logging on or off (values: On = "Yes", Off = "No")
return {
active = true,
on = {
devices = {
IDOSR,
IDOHW,
},
timer = {
ONMORNING,
OFFMORNING,
ONEVENING,
OFFEVENING,
'at sunset',
'at sunrise',
'2 minutes after sunrise',
},
},
execute = function(domoticz, triggeredItem, info)
--SET VARIABLES:
local OUTDOORHALLWAY = domoticz.devices(IDOHW)
local OUTDOORSTORAGEROOM = domoticz.devices(IDOSR)
local LOGGING = "\n++++++++++++++++++++\n".."SCRIPT LIGHTS OUTDOOR:".."\n...................."
-- EXECUTE SCRIPT
LOGGING = LOGGING .."\n".."Outdoor light StorageRoom: "..OUTDOORSTORAGEROOM.state..", Outdoor light Hallway: "..OUTDOORHALLWAY.state
if (domoticz.time.isNightTime) then
LOGGING = LOGGING .."\n".."Program Nighttime active"
if domoticz.time.matchesRule(ONEVENING) then
LOGGING = LOGGING .."\n".."Program On-Evening"
if (OUTDOORHALLWAY.state == "Off") or (OUTDOORSTORAGEROOM.state == "Off") then
LOGGING = LOGGING .."\n".."Turn on the lights "..ONEVENING
OUTDOORHALLWAY.switchOn()
OUTDOORSTORAGEROOM.switchOn()
else
LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
end
elseif domoticz.time.matchesRule(OFFEVENING) then
LOGGING = LOGGING .."\n".."Program Off-Evening"
if (OUTDOORHALLWAY.state == "On") or (OUTDOORSTORAGEROOM.state == "On") then
LOGGING = LOGGING .."\n".."Turn off the lights "..OFFEVENING
OUTDOORHALLWAY.switchOff()
OUTDOORSTORAGEROOM.switchOff()
else
LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
end
elseif domoticz.time.matchesRule(ONMORNING) then
LOGGING = LOGGING .."\n".."Program On-Morning"
if (OUTDOORHALLWAY.state == "Off") or (OUTDOORSTORAGEROOM.state == "Off") then
LOGGING = LOGGING .."\n".."Turn on the lights "..ONMORNING
OUTDOORHALLWAY.switchOn()
OUTDOORSTORAGEROOM.switchOn()
else
LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
end
elseif domoticz.time.matchesRule(OFFMORNING) then
LOGGING = LOGGING .."\n".."Program Off-Morning"
if (OUTDOORHALLWAY.state == "On") or (OUTDOORSTORAGEROOM.state == "On") then
LOGGING = LOGGING .."\n".."Turn off the lights "..OFFMORNING
OUTDOORHALLWAY.switchOff()
OUTDOORSTORAGEROOM.switchOff()
else
LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
end
else
LOGGING = LOGGING .."\n".."No action needed (night time)"
end
elseif (domoticz.time.isDayTime) then
LOGGING = LOGGING .."\n".."Program Daytime active"
if (OUTDOORHALLWAY.state == "On") or (OUTDOORSTORAGEROOM.state == "On") then
LOGGING = LOGGING .."\n".."Lights are on, turn off the lights in "..SECLLOFF .." seconds"
OUTDOORHALLWAY.switchOff().afterSec(SECLLOFF)
OUTDOORSTORAGEROOM.switchOff().afterSec(SECLLOFF)
else
LOGGING = LOGGING .."\n".."No action needed (day time)"
end
else
LOGGING = LOGGING .."\n".."No action needed (no night/day time)"
end
LOGGING = LOGGING .."\n++++++++++++++++++++"
--LOGGING:
if (LOGGINGON == "Yes") then
domoticz.log(LOGGING)
end
end
}