* Garden lights on at sunset (works)
* Gardenlightdoor turns on when motion detected at nighttime (works)
* Garden lights turn off around 23:30 (works)
* Gardenlights turn on at motion detected at nighttime, but after they are turned off after 23:30-ish (not working)
What am I doing wrong in the following script?
Code: Select all
local gardenMotion = 157 --motion sensor tuin
return {
on =
{
devices =
{
[gardenMotion] = { 'at nighttime' },
},
timer =
{
'at sunset',
'at 23:30',
},
variables = {},
scenes = {},
groups = {},
security = {},
httpResponses = {},
shellCommandResponses = {},
customEvents = {},
system = {},
},
data = {},
logging =
{ level = domoticz.LOG_DEBUG,
marker = "Hue light tuin",
},
execute = function(dz, item)
local ped1 = dz.devices(142) --hue tuinlamp 1
garden = dz.devices().filter({142, 143, 144, 145, 146}) --hue tuinlampen
gardenlightdoor = dz.devices(174) --hue lamp naast keukendeur
gardenMotion = dz.devices(157)
--motionsensor tuin, lamp naast keukendeur aan op beweging
if item == gardenMotion and gardenMotion.state == 'On' then
if (gardenlightdoor.active) then
gardenlightdoor.dimTo(0).afterMin(3)
else
gardenlightdoor.dimTo(100).forMin(3)
end
--motionsensor tuin, lampen in tuin aan op beweging
elseif item == gardenMotion and gardenMotion.state == 'On' and dz.time.matchesRule('after 23:30') then
if ped1.active then
dz.log('Lampen waren aan en gaan nu uit')
garden.forEach(function(device)
device.switchOff().afterMin(3)
end)
else
dz.log('Lampen gaan aan door beweging')
dz.openURL({
url = 'http://10.0.1.27/api/eoKsH5jcG2zz5zt2Q2Qzk-WdZRdEpeXQHgkXOE22/groups/4/action',
method = 'PUT',
postData = {scene = "2k1uz6x3yPrWSZd"} --scene 'energie'
})
garden.forEach(function(device)
device.switchOff().afterMin(3)
end)
end
--lampen tuin aan bij zonsondergang en uit rond 23:30uur
elseif item.isTimer then
if (dz.time.matchesRule('at sunset')) then
dz.openURL({
url = 'http://10.0.1.27/api/xxxxxxxxxxxxxxxxxxxx/groups/4/action',
method = 'PUT',
postData = {scene = "-PHj0N3ZEsw37b2", transitiontime = 9000} --scene 'ontspannen' met een transitietijd van 15 minuten
})
else
dz.openURL({
url = 'http://10.0.1.27/api/xxxxxxxxxxxxxxxxxxxx/groups/4/action',
method = 'PUT',
postData = {on = false} --uitschakelen alle lampen
}).withinMin(20)
end
end
end
}