Hello.
I have a small problem. I'm trying to write a script to switch on 3 lights outside for 1 minute if a detector "bewegings melder' detectes movement. Thescript only needs to be activated 10 minutes after sunset. Also one of the lights does'nt have to be switched on if a switch "sauna bezoek' is switched on. I am struggeling to write this script. Is there anyone who can help me?
This is what I have so far. I know it's full of erros
return {
on = {
timer = {'10 minutes after sunset'},
devices = { 'bewegings melder' }
},
execute = function(domoticz, item)
if (item.isTimer) then
-- the timer was triggered
domoticz.devices('Fitting').switchOff()
elseif (item.isDevice and item.active) then
-- it must be the detector
domoticz.devices('Fitting').switchOn().forMin(1)
domoticz.devices('Licht steeg').switchOn().forMin(1)
domoticz.devices('Licht blokhut').switchOn().forMin(1)
end
end
}
janpeetoom wrote: ↑Saturday 29 February 2020 13:18
I have a small problem. I'm trying to write a script to switch on 3 lights outside for 1 minute if a detector "bewegings melder' detectes movement.
return
{
on =
{
devices =
{
['bewegings melder'] = { 'between 10 minutes after sunset and sunrise' },
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
marker = 'myLight',
},
execute = function(dz, item)
if item.active then
local fitting = dz.devices('Fitting')
local steeg = dz.devices('Licht steeg')
local blokhut = dz.devices('Licht blokhut')
local sauna = dz.devices('sauna bezoek')
local function onFor(device, duration, exception)
if exception then return end
device.cancelQueuedCommands()
device.switchOn()
device.switchOff().afterSec(duration)
end
onFor(fitting, 60, sauna.state == 'On') -- if sauna bezoek 'On' then exception will be true and onFor will return immediate without any action
onFor(steeg, 60)
onFor(blokhut, 60)
end
end
}
Thanks Waaren for the quick reply.
I have copied your script into domoticz
Now I get this message:
2020-03-01 16:31:59.531 ...domoticz/scripts/dzVents/generated_scripts/Script #3.lua:5: unexpected symbol near '['
2020-03-01 16:32:00.423 Status: dzVents: Error (2.4.19): error loading module 'Script #3' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #3.lua':
Thanks for your responce. The following error occurs now: 2020-03-02 18:03:42.215 Status: dzVents: Error (2.4.19): error loading module 'Script #3' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #3.lua':
2020-03-02 18:03:42.215 ...domoticz/scripts/dzVents/generated_scripts/Script #3.lua:8: unexpected symbol near '='
If I remove the loggig part en proceed with the execute = function part the same erro occurs.
return
{
on =
{
devices = {
['bewegings melder'] = { 'between 10 minutes after sunset and sunrise' },
}
},
execute = function(dz, item)
if item.active then
local fitting = dz.devices('Fitting')
local steeg = dz.devices('Licht steeg')
local blokhut = dz.devices('Licht blokhut')
local sauna = dz.devices('sauna bezoek')
local function onFor(device, duration, exception)
if exception then return end
device.cancelQueuedCommands()
device.switchOn()
device.switchOff().afterSec(duration)
end
onFor(fitting, 60, sauna.state == 'On') -- if sauna bezoek 'On' then exception will be true and onFor will return immediate without any action
onFor(steeg, 60)
onFor(blokhut, 60)
end
end
}