Code: Select all
return
{
on =
{
devices = { 'Wall Switch Kitchen' }, -- Switch Controlling two lights
},
logging =
{
level = domoticz.LOG_INFO,
marker = "Wall Switch Kitchen"
},
execute = function(domoticz, device)
local dimDevice = domoticz.devices(677,679) -- Two lights to be controlled at the a same time
local dimLevel = 100 -- Would it be possible to determine the actual dim level as a starting point?
if device.state == "Brightness_Move_Down" then
<set a timer to determine duration of this device state in milliseconds>
elseif device.state == "Brightness_Stop" then
<a calculation of the amount of milliseconds between Brightness_Move_Down and Brightness_Stop>
<every 200 milliseconds is 5% of dim, so dimLevel = dimLevel - Calculation/200 * 5>
domoticz.log('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%', domoticz.LOG_INFO)
dimDevice.dimTo(dimLevel)
dimDevice.cancelQueuedCommands()
if dimDevice.level == 0 then
dimDevice.switchOff()
if device.state == "Brightness_Move_Up" then -- Repeat code, but now to increase dimmer
local dimLevel = 0 -- Reset Dim Level to allow it to go up
<set a timer to determine duration of this device state in milliseconds>
elseif device.state == "Brightness_Stop" then
<a calculation of the amount of milliseconds between Brightness_Move_Down and Brightness_Stop>
<every 200 milliseconds is 5% of dim, so dimLevel = dimLevel + Calculation/200 * 5>
domoticz.log('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%', domoticz.LOG_INFO)
dimDevice.dimTo(dimLevel)
dimDevice.cancelQueuedCommands()
if dimDevice.level == 100 then
dimDevice.switchOn()
end
end
end
}