Dimming with a button (long press event)
Posted: Wednesday 02 September 2020 19:23
Hi!
I'm trying to write a script to dim my light using an aqara opple switch.
I'm having trouble as the script is running too fast and I don't get that slow fade to be able to stop at the desired new level. Usually it's going form 0 to 100 and the same backwards instantly. Is there a way to slow down the script? like a delay() or sleep() without the bad behaviour of sleep or delay?
Any help would be appreciated!
I'm trying to write a script to dim my light using an aqara opple switch.
Code: Select all
return {
on = {
devices = {
'Arbeitszimmer Flur',
'Arbeitszimmer Wohnzimmer'
}
},
execute = function(domoticz, device)
local Wand = domoticz.devices('Arbeitszimmer - Wandbeleuchtung')
local Decke = domoticz.devices('Arbeitszimmer - Decke')
local dimLevelWand = 1
local dimLevelDecke = 0
domoticz.log('Device ' .. device.name .. ' was changed. State: ' .. Wand.state, domoticz.LOG_INFO)
if device.state == "B1" then
Wand.toggleSwitch()
end
if device.state == "B3" then
if Decke.state == 'Off' then
Decke.setState('On')
else
Decke.setState('Off')
end
end
if device.state == "B1L" then
repeat
dimLevelWand = dimLevelWand + 0.01
--domoticz.log('Set ' .. Wand.name .. ' to dimLevel '.. dimLevelWand, domoticz.LOG_INFO)
Wand.dimTo(dimLevelWand)
until dimLevelWand >= 100
elseif device.state == "B1RL" then
end
if device.state == "B2L" then
repeat
dimLevelWand = dimLevelWand - 0.01
--domoticz.log('Set ' .. Wand.name .. ' to dimLevel '.. dimLevelWand .. '%, after ' .. delay .. ' seconds', domoticz.LOG_INFO)
Wand.dimTo(dimLevelWand)
until dimLevelWand <= 0
elseif device.state == "B2RL" then
end
end
}
Any help would be appreciated!