Hi Waaren,
I have a another question with the script, but i can't find a proper solution with my limited programming knowledge.
Yesterday the following happened.
Due to bad weather and rain it was pretty dark around 18:30, but the script only gets triggered 60 minutes before sunset (21:14) and therefore i turned on the lights manually.
Becasue the lights were on, the lux value will never reach the trigger setting (<10 lux) and the script will retrigger it self every 5 min after 20:14 (60 minutebefore sunset).
No problem, but i turned of the lights manually around 22:30, which is before UV_sleep (23:00) and the script was still running and turned on the lights again with the retrigger event.
How can I bypass this ? If I turn on the lights manually before the script is started and switch on after sunset.
This is my latest version of the script
Code: Select all
local scriptVersion = 'Versie 1.01'
local scriptVar = '-=# PIR Woonkamer #=-'
local PIR = 451 -- "PIR Sensor" change to name of your PIR
local lux = 454 -- "PIR Lux" change to name of your lux device
local light = 'Woonkamer' -- change to name of your light/group
local retrigger = 'Retrigger using customEvent'
local Switch = 'Party Mode' -- Schakelaar Party Mode (464)
local minutesBeforeSunset = 60 -- 60 min before sunset
return
{
on =
{
timer =
{
function(domoticz)
return
domoticz.time.matchesRule('at ' .. domoticz.variables('UV_Sleep').value) or
domoticz.time.matchesRule('at ' .. minutesBeforeSunset .. ' minutes before sunset') -- must use matchesRule when making your own function
end,
},
customEvents =
{
retrigger,
}
},
logging = { level = domoticz.LOG_INFO,
marker = scriptVar },
execute = function(dz)
local PIR = dz.devices(PIR)
local light = dz.groups(light) -- groups instead of device
local lux = dz.devices(lux).lux
local Switch = dz.devices(Switch)
local Sleep = dz.variables('UV_Sleep').value
dz.log(' LUX = ' .. lux,dz.LOG_FORCE)
dz.log(PIR.name .. ' was last updated ' .. PIR.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_FORCE)
dz.log(light.name .. ' state is ' .. light.state ,dz.LOG_FORCE)
-- the text between quotes and the variables minutesBeforeSunset (60) and Sleep (23:00) will be concatenated to
-- between xx minutes before sunset and 23:00
if dz.time.matchesRule('between ' .. minutesBeforeSunset .. ' minutes before sunset and ' .. Sleep) and not(dz.time.matchesRule('at ' .. Sleep)) then
if lux < 10 then
light.switchOn().checkFirst()
dz.log(light.name .. ' switched On or already On',dz.LOG_FORCE)
else
dz.emitEvent(retrigger).afterSec(300) -- try again in 5 min.
dz.log('Script will start again in 5 minutes',dz.LOG_FORCE)
end
else
if PIR.lastUpdate.secondsAgo > 1800 and (Switch.state == 'Off') then
light.switchOff().checkFirst()
dz.log(light.name .. ' switching Off or already Off and: ' .. Switch.name .. ' switched Off' ,dz.LOG_FORCE)
else
dz.emitEvent(retrigger).afterSec(300) -- try again in 5 min.
dz.log('Script will start again in 5 minutes',dz.LOG_FORCE)
end
end
end
}
I hope you can give me some advise.