Code: Select all
return {
on = {
devices = {
'All lights'
},
timer = {
}
},
execute = function(domoticz, device, triggerInfo)
local lightsDownstairs = domoticz.devices().filter(function(device)
return (device.name ==
(
'Sofa light' or
'Dining room light' or
'TV light' or
'Hallway light' or
'Kitchen light'
)
)
end
)
if triggerInfo.type == 'device'
then
print('trigger = device')
print('devicename = ' .. device.name)
if device.name == 'All lights'
then
print('Device state: ' .. device.state)
if device.state == 'On'
then
lightsDownstairs.forEach(function(light)
print('Do something with ' .. light.name)
light.switchOn()
end
)
else
lightsDownstairs.forEach(function(light)
print('Do something with ' .. light.name)
light.switchOff()
end
)
end
end
end
end
}
My log says:
Code: Select all
2017-11-19 10:38:04.813 User: Admin initiated a switch command (99/All lights/On)
2017-11-19 10:38:04.881 dzVents: Info: Handling events for: "All lights", value: "On"
2017-11-19 10:38:04.881 dzVents: Info: ------ Start internal script: Light switch events: Device: "All lights (Virtual switches controller)", Index: 99
2017-11-19 10:38:04.909 dzVents: trigger = device
2017-11-19 10:38:04.909 dzVents: devicename = All lights
2017-11-19 10:38:04.909 dzVents: Device state: On
2017-11-19 10:38:04.909 dzVents: Do something with Sofa light
2017-11-19 10:38:04.909 dzVents: Info: ------ Finished Light switch events