Time triggers and hard-coding times
Posted: Sunday 05 April 2020 13:18
Hi,
Say you have a dzVents script for switching lights and you have several triggers for both switching them on and switching off. In the execution part of the script, how do you know which trigger was actually triggered? Do you have to do a manual check with hard-coded values that was it the trigger e.g. for switchig the lights off at 09:00?
For now I have done like this:
It feels like bad coding having to hard-code the trigger values and do a lot of checking in the script. There surely must be a better pattern? Can you e.g. have variables and use them both as trigger values and in the script?
Regards,
Peik
Say you have a dzVents script for switching lights and you have several triggers for both switching them on and switching off. In the execution part of the script, how do you know which trigger was actually triggered? Do you have to do a manual check with hard-coded values that was it the trigger e.g. for switchig the lights off at 09:00?
For now I have done like this:
Code: Select all
...
timer = {
'at sunrise',
'at 05:30',
}
...
execute = function(domoticz, triggeredItem, info)
local gardenLights = domoticz.devices(122)
local Time = require('Time')
local currentTime = Time()
...
...
if (currentTime.matchesRule('at 05:30')) then
gardenLights.switchOn()
elseif (currentTime.matchesRule('at sunrise')) then
gardenLights.switchOff()
end
end
Regards,
Peik