Friends I've worked with Blocky so far, however I can't possibly make what is needed in Blocky. So I started dzVents. I copied some ideas and ended up with this script ... with the necessary errors. I'll leave the script and error message here and hope you guys can see where I'm going wrong? Thanks in advance and a happy New Year!:
--Declarations
local HBSNum1 = 85 -- Sensor Boven (vul het id in) (dit geeft het id aan van de sensor)
local HBSNum2 = 87 -- Sensor Hal (vul het id in) (dit geeft het id aan van de sensor)
return {
on = { devices = {
HBSNum1, -- Sensor Boven (Maakt een device aan met het id dat gegeven is.)
HBSNum2 -- Sensor Hal (Maakt een device aan met het id dat gegeven is.)
}
},
execute = function(domoticz, device)
local LampHal = domoticz.devices(96) --Lamp Hal (Haalt het device op voor het device met het gegeven id)
local HBS1 = domoticz.devices(HBSNum1) -- Sensor Boven (Haalt het device op met het gegeven id.)
local HBS2 = domoticz.devices(HBSNum2) -- Sensor Hal (Haalt het device op met het gegeven id.)
if (HBS1.active) then -- (Als Sensor Boven aan gaat dan)
LampHal.switchOn() -- (Zet Lamp Hal aan)
repeat -- (Herhaal)
local now = os.time() + 60 -- (Simpele methode om te kijken hoe laat het over 1 minuut is)
if (LampHal.state == "Off") then --(Als LampHal staat uit dan)
LampHal.switchOn() --(Zet lamphal aan)
end -- (einde als statement)
until os.time() >= now --(herhaal tot tijd gelijk is aan de tijd 1 minuut geleden)\
LampHal.switchOff()
elseif (HBS2.active) then -- (Als Sensor hal aan gaat dan)
LampHal.switchOn() -- (Zet Lamp Hal aan)
repeat -- (Herhaal)
local now = os.time() + 60 -- (Simpele methode om te kijken hoe laat het over 1 minuut is)
if (LampHal.state == "Off") then --(Als LampHal staat uit dan)
LampHal.switchOn() --(Zet lamphal aan)
end -- (einde als statement)
until os.time() >= now --(herhaal tot tijd gelijk is aan de tijd 1 minuut geleden)\
LampHal.switchOff()
end
LampHal.switchOff() --(Zet lamp Hal uit)
end
}
rolandtwilt wrote: Thursday 31 December 2020 14:33
Friends I've worked with Blocky so far, however I can't possibly make what is needed in Blocky. So I started dzVents. I copied some ideas and ended up with this script ... with the necessary errors. I'll leave the script and error message here and hope you guys can see where I'm going wrong?
You don't' want to use loops in event scripts like this. You will block the event system completely because the event system is single threaded. To protect the rest of domoticz the main worker of domoticz will kill the script after about 10 seconds.
If I understand your intended use of the script correctly, below version will do the same using standard dzVents methods.
return
{
on =
{
devices =
{
85, -- Sensor Boven
87, -- Sensor Hal
},
},
execute = function(domoticz, item)
local LampHal = domoticz.devices(96) -- Lamp Hal (dzVents device object)
if item.active then -- If one of the sensors are updated to active
LampHal.cancelQueuedCommands() -- Cancel all scheduled commands for this device
LampHal.switchOn().checkFirst()
LampHal.switchOff().afterSec(60)
end
end
}
Thank you!! when I walk from bottom to top, the lamp turns on and then turns off after 60 seconds. When I walk from top to bottom the lamp stays on ..... what am I doing wrong?
rolandtwilt wrote: Thursday 31 December 2020 17:06
Thank you!! when I walk from bottom to top, the lamp turns on and then turns off after 60 seconds. When I walk from top to bottom the lamp stays on ..... what am I doing wrong?
Hard to tell without log...
I added a log line in below version. It will not solve the issue but might help in identifying a cause.
return
{
on =
{
devices =
{
85, -- Sensor Boven
87, -- Sensor Hal
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'PIR control',
},
execute = function(domoticz, item)
domoticz.log(item.name .. ', State: ' .. item.state .. ', active is ' .. tostring(item.active), domoticz.LOG_DEBUG )
local LampHal = domoticz.devices(96) -- Lamp Hal (dzVents device object)
if item.active then -- If one of the sensors are updated to active
LampHal.cancelQueuedCommands() -- Cancel all scheduled commands for this device
LampHal.switchOn().checkFirst()
LampHal.switchOff().afterSec(60)
end
end
}
No, it was not necessary ..... an old script was still running and that caused problems . Now that the old script is turned off, your script works like a charm. Super thanks!!