Script for faster, more efficient bulk control of devices (eg everything off)
Posted: Wednesday 10 January 2018 4:05
This Lua script can dramatically improve performance as an alternative to a scene to bulk control devices.
Example, a home has 20 devices of various technologies (z-wave, phillips hue, xiaomi etc...). Half the devices are turned on and the other half are not.
Let's say you want to turn off all the devices, the script will look at which devices Domoticz thinks are turned on and turn them off FIRST, then tell the other half of the devices that Domoticz thinks are turned off to turn off.
So we tell the 20 devices in the home to turn off but it's done in a way that delivers a more rapid responsiveness for the user by prioritising which devices to control first.
This is what output in the Domoticz event log looks like:
Devices to be controlled are processed in the order top to bottom (see the script below). Look at the script then look at the Domoticz event log above you can see how the algorithm processed devices thought to be "On" first, then moved on to turning off the remaining devices (look how Main Bedroom was the first remaining device to be turned off).
I use a virtual on / off device called "Everything" to trigger the Lua device script and then have an event which controls the virtual on / off device (Optional).
Code:
Updated 11/06/2018 (improved code efficiency)
Example, a home has 20 devices of various technologies (z-wave, phillips hue, xiaomi etc...). Half the devices are turned on and the other half are not.
Let's say you want to turn off all the devices, the script will look at which devices Domoticz thinks are turned on and turn them off FIRST, then tell the other half of the devices that Domoticz thinks are turned off to turn off.
So we tell the 20 devices in the home to turn off but it's done in a way that delivers a more rapid responsiveness for the user by prioritising which devices to control first.
This is what output in the Domoticz event log looks like:
Code: Select all
2018-01-10 18:39:26.478 LUA: Priority Off:Main Bathroom
2018-01-10 18:39:26.478 LUA: Priority Off:Main Entrance Hallway
2018-01-10 18:39:26.478 LUA: Priority Off:Kitchen
2018-01-10 18:39:26.478 LUA: Priority Off:Living Room Middle
2018-01-10 18:39:26.478 LUA: Priority Off:Fish Tank
2018-01-10 18:39:26.478 LUA: Remaining Off:Main Bedroom
2018-01-10 18:39:26.478 LUA: Remaining Off:Main Bedroom Hallway
2018-01-10 18:39:26.478 LUA: Remaining Off:Second Bathroom
2018-01-10 18:39:26.478 LUA: Remaining Off:Living Room Window
2018-01-10 18:39:26.478 LUA: Remaining Off:Office
2018-01-10 18:39:26.478 LUA: Remaining Off:Mirror LightStrip Main Bathroom
2018-01-10 18:39:26.478 LUA: Remaining Off:Kitty Litter Lightstrip
2018-01-10 18:39:26.478 LUA: Remaining Off:Mirror LightStrip 2nd Bathroom
2018-01-10 18:39:26.478 LUA: Remaining Off:Kitchen R Lightstrip
I use a virtual on / off device called "Everything" to trigger the Lua device script and then have an event which controls the virtual on / off device (Optional).
Code:
Code: Select all
commandArray = {}
-- Devices to be controlled, last entry should not have a comma at the end
devices = {
"Main Bedroom",
"Main Bedroom Hallway",
"Main Bathroom",
"Main Entrance Hallway",
"Second Bathroom",
"Kitchen",
"Living Room Middle",
"Living Room Window",
"Office",
"Fish Tank",
"Mirror LightStrip Main Bathroom",
"Kitty Litter Lightstrip",
"Mirror LightStrip 2nd Bathroom",
"Kitchen R Lightstrip"
}
if (devicechanged["Everything"] == 'On') then
for i = 1, #devices do
if (otherdevices[devices[i]] == 'Off') then -- Priority control
commandArray[devices[i]] = 'On'
print("Priority On:" .. devices[i])
end
end
for i = 1, #devices do
if (otherdevices[devices[i]] == 'On') then -- Remaining control
commandArray[devices[i]] = 'On'
print("Remaining On:" .. devices[i])
end
end
elseif (devicechanged["Everything"] == 'Off') then
for i = 1, #devices do
if (otherdevices[devices[i]] ~= 'Off') then -- Priority control
commandArray[devices[i]] = 'Off'
print("Priority Off:" .. devices[i])
end
end
for i = 1, #devices do
if (otherdevices[devices[i]] == 'Off') then -- Remaining control
commandArray[devices[i]] = 'Off'
print("Remaining Off:" .. devices[i])
end
end
end
return commandArray