I'm trying to convert all my scripts from blocky to Dzvents. The next script is working but I'm not getting the correct results.
My situation is;
Garage has an main switch, to powerup machines and all sockets. For the workshop I got one light switch and same for the garage one light switch.
There are also two PIR motion detectors and a garage door as a trigger for the lights.
My idea is I leave the two light switches on and when I flick the main powerswitch it all switches on, if one of the light switches is switched of that light goes down and vise-versa. If main switch is off all go off. If there is motion or the door opens and the main is off the lights go on for 3 minutes even if the light switches or in off position.
I came up with the following script and I thought is was working fine but now if I flick on the main the lights won't go on. according to the log they should be on. Maybe I'm doing something simply wrong or I might not see a small mistake, I hope someone here does see it.
Code: Select all
return {
on = {
devices = { 184, 185, 186, 144, 145, 65, 66, 39,
},
},
logging = {
level = domoticz.LOG_INFO,
marker = "WP_verlichting"
},
execute = function(domoticz, devices)
local Thuis = domoticz.devices(65)
local WP_pir = domoticz.devices(144)
local Gar_pir = domoticz.devices(145)
local hfd_schakelaar = domoticz.devices(184)--shelly i3
local WP_lichtschakelaar = domoticz.devices(185)--shelly i3
local Gar_lichtschakelaar = domoticz.devices(186)--shelly i3
local Hoofdrelais = domoticz.devices(33)--shelly2.5
local WP_verlichting = domoticz.devices(31)--shelly2.5
local Gar_verlichting = domoticz.devices(32)--shelly2.5
local Garagedeur = domoticz.devices(39)
if Thuis.state == 'On' and hfd_schakelaar.state == 'On' then
Hoofdrelais.switchOn()
domoticz.log('Hoofdschakelaar staat aan!')
else
Hoofdrelais.switchOff()
domoticz.log('Hoofdschakelaar uit!')
end
if Thuis.state == 'On' and Bedtime.state == 'On' and hfd_schakelaar.state == 'On' and WP_lichtschakelaar.state == 'On' then
WP_verlichting.switchOn()
domoticz.log('werkplaatslicht aan!')
else
WP_verlichting.switchOff()
domoticz.log('werkplaatslicht uit.')
end
if Thuis.state == 'On' and Bedtime.state == 'On' and hfd_schakelaar.state == 'On' and Gar_lichtschakelaar.state == 'On' then
Gar_verlichting.switchOn()
domoticz.log('garagelicht aan!')
else
Gar_verlichting.switchOff()
domoticz.log('garagelicht uit.')
end
if WP_pir.state == 'On' or Gar_pir.state == 'On' or Garagedeur.state == 'On' and hfd_schakelaar.state == 'Off' then
WP_pir.switchOff().afterSec(180)
Gar_pir.switchOff().afterSec(180)
WP_verlichting.switchOn()
Gar_verlichting.switchOn()
domoticz.log('Beweging in de schuur, licht aan.!')
else
WP_verlichting.switchOff()
Gar_verlichting.switchOff()
end
end
}