Code: Select all
dz.devices("Lamp XXX").setColor(0,0,0,100,255,255,2,160).silent()This is the total code.
I have 2 lamps (XXX and YYY) and a switch "Bedlampen"
That switch is controlled by hand or by a PIR
The total acts OK, but this script is executed multiple times.
Code: Select all
return {
active = true,
-- active = false,
on = {
devices = { "Bedlampen", "Lamp XXX", "Lamp YYY" }
},
execute = function(dz, mySwitch)
if mySwitch.name == "Lamp XXX" or mySwitch.name == "Lamp YYY" then
XXX = dz.devices("Lamp XXX").state
YYY = dz.devices("Lamp YYY").state
if (XXX == 'On' or YYY == 'On') then
dz.devices("Bedlampen").switchOn().checkFirst().silent()
elseif (XXX == 'Off' and YYY == 'Off') then
dz.devices("Bedlampen").switchOff().checkFirst().silent()
end
elseif mySwitch.name == "Bedlampen" then
if (mySwitch.state == 'On') then
if dz.devices("Lamp XXX").state == 'Off' then
dz.devices("Lamp XXX").setColor(0,0,0,100,255,255,2,160).silent()
end
if dz.devices("Lamp YYY").state == 'Off' then
dz.devices("Lamp YYY").setColor(0,0,0,100,255,255,2,160).silent()
end
else
dz.devices("Lamp XXX").switchOff().checkFirst().silent()
dz.devices("Lamp YYY").switchOff().checkFirst().silent()
end
end
end
}