-- user variable line from LUA version translated into a table and some local variables below it: -- uitbouw dimmer=100,Ikea kast=100,Eettafel=60,Aanrecht spots dimmer=100,Schemerlamp woonkamer=60,defaultlevel=50,maxout=1 local VIRTUALDIMMER = 'Woonkamer Lichten' local DIMMERTABLE = { -- [ 'Dimmer' ] = individual dimmer level ['uitbouw dimmer'] = 100, ['Ikea kast'] = 100, ['Eettafel'] = 60, ['Aanrecht spots dimmer'] = 100, ['Schemerlamp woonkamer'] = 60 } local DEFAULTLEVEL = 50 local MAXOUT = true return { active = true, logging = { level = domoticz.LOG_INFO, -- Select one of LOG_DEBUG, LOG_INFO, LOG_ERROR, LOG_FORCE to override system log level marker = VIRTUALDIMMER }, on = { devices = { VIRTUALDIMMER -- define device to trigger this script } }, execute = function(domoticz, device) if (device.state == 'On' and device.lastLevel == device.level ) then -- if the level did not change, the on-button was pressed dimlevel = tonumber(DEFAULTLEVEL)/100 domoticz.log('Setting to default level: '.. DEFAULTLEVEL , domoticz.LOG_INFO) for light, dimValue in pairs (DIMMERTABLE) do if ( MAXOUT and dimlevel == 1 ) then level = 100 else level = math.floor(dimlevel * dimValue) end domoticz.log('36: changing ' .. light ..' to relative level: ' .. level, domoticz.LOG_INFO) domoticz.devices(light).dimTo(level) end device.dimTo(DEFAULTLEVEL).silent() elseif (device.state == 'On' and device.lastLevel ~= device.level ) then -- the dimmer slider was moved; level changed while on domoticz.log('Dimmer slider moved from '..device.lastLevel ..' to: ' .. device.level ..' while already on ' , domoticz.LOG_INFO) dimlevel = tonumber(device.level)/100 for light, dimValue in pairs (DIMMERTABLE) do if ( MAXOUT and dimlevel == 1 ) then level = 100 else level = math.floor(dimlevel * dimValue) end domoticz.log('52: changing ' .. light ..' to ' .. level, domoticz.LOG_INFO) domoticz.devices(light).dimTo(level) end elseif (device.state == 'Off') then domoticz.log('timer off; lights to off' , domoticz.LOG_INFO) for light, dimValue in pairs (DIMMERTABLE) do domoticz.devices(light).switchOff().checkFirst() end end end }