I share this script as is. Feel free to adapt and tinker.
Code: Select all
-- Balanced group dimmer by EScApe 2018
-- Version 0.1
--
-- This virtual dimmer script will control multiple dimmers as a group and dim them with individual relative levels
-- Installation:
-- Create a virtual Dimmer (dummy)
-- Create Domoticz user variable (string) named Cfg_<virtual dimmer name> (eg. 'Cfg_DimmerLivingRoom') and configure it based on the example below
-- Adapt the myname variable in the script to the Domoticz name of this virtual dimmer.
-- Tip: save the script as script_device_<lower_case_dimmer_name>.lua (with underscores instead of spaces) so it will only run if the specified virtual dimmer changes.
--
-- Configuration:
-- Example configuration (user variable): Lamp1=100,Lamp2=50,Lamp3=75,defaultlevel=50,maxout=1,debug=1
-- In this example Lamp2 will be at half the level compared to Lamp1 (so it Lamp1 is at 50, Lamp2 will be at 25).
-- Not every lightsource has the same maximum brightness and this script helps you balance them to your liking.
-- Make sure there are no extra spaces in the configuration variable and you are using the exact (case sensitive) names for the actual lights (which obviously must be dimmers).
--
-- Besides the lamps you can also see some (optional) settings in the example:
-- defaultlevel: the level the virtual dimmer is set to when it is turned on (by button or anything else than the slider). Can be usefull if individual lights are also controlled seperately.
-- maxout: with this set to 1 alle lights will be set to maximum brightness (100%) if the virtual dimmer is set to (exactly) 100%. Ignoring the relative brightness settings.
-- debug: if this is set to 1 then the script will generate verbose logging to help you check your configuration and monitor script behaviour.
myname="Dimmer Beneden"
commandArray = {}
if devicechanged[myname] then
cfgvar="Cfg_" .. myname
if not uservariables[cfgvar] then
print("ERROR! Virtual '" .. myname .. "' dimmer is missing configuration variable named: '" .. cfgvar .. "'")
return commandArray
end
debug=false
defaultlevel=0
maxout=false
lights = {}
for key, value in string.gmatch(uservariables[cfgvar], "([^=,]+)=(%d+)") do
if key == 'debug' then
if value == '1' then
print('-- starting with debug mode enabled --')
debug = true
end
elseif key == 'defaultlevel' then
defaultlevel = tonumber(value)
elseif key == 'maxout' then
if value == '1' then
maxout = true
end
else
lights[key] = value
end
end
if debug then
print("relative light levels:")
for k, v in pairs(lights) do
print("> " .. k .. " : " .. v)
end
if maxout then print("All lights will be set to their individual maximum when slider is set to 100%") end
end
if devicechanged[myname] == 'Off' then
for lampname, lampmax in pairs(lights) do
if debug then print("Turn " .. lampname .. " off") end
commandArray[lampname]='Off'
end
elseif devicechanged[myname] == 'On' then
if defaultlevel > 0 then
if debug then print("setting to default level: " .. defaultlevel) end
commandArray[myname] = 'Set Level ' .. defaultlevel
else
for lampname, lampmax in pairs(lights) do
if debug then print("Turn " .. lampname .. " on") end
commandArray[lampname]='On'
end
end
else
dimlevel = tonumber(otherdevices_svalues[myname])/100
if debug then print("setting relative level to: " .. dimlevel) end
for lampname, lampmax in pairs(lights) do
if maxout and dimlevel == 1 then
level = 100
else
level = math.floor(dimlevel * lampmax)
end
if level > 0 then
if debug then print("set " .. lampname .. " to " .. level) end
commandArray[lampname]='Set Level ' .. level
else
if debug then print("Turn " .. lampname .. " off") end
commandArray[lampname]='Off'
end
end
end
end
return commandArray