Wrote a little script to switch on a dimmer at a certain level (50%) for a number of minutes when a doorbell is pressed.
If pressed again while the light is on, the light should be a tad brighter (50 + 25 = 75%).
if pressed again, the light must switch off.
For some reason though, dimTo seems to fail setting 50%...
Code: Select all
local INPUT_DEV='Elin drukknop'
local OUTPUT ='Hue Ikea lamp PC beneden'
local INIT_LEVEL = 50
local LEVEL_STEP = 25
local DURATION = 1
return {
on = {
devices = {
INPUT_DEV
}
},
execute = function(domoticz, switch)
local dimmer = domoticz.devices(OUTPUT)
if (switch.state == 'Chime') then
domoticz.log('dimmerlevel: ' .. dimmer.level .. '; INIT_LEVEL: '.. INIT_LEVEL ..'; dimmerstate: ' .. dimmer.state , domoticz.LOG_INFO)
if (dimmer.level == INIT_LEVEL) then
domoticz.log('!dimmerlevel = INIT_LEVEL. dimmerlevel: ' .. dimmer.level , domoticz.LOG_INFO)
dimmer.dimTo(dimmer.level + LEVEL_STEP)
domoticz.log('dimmerlevel = INIT_LEVEL+LEVEL_STEP. dimmerlevel: ' .. dimmer.level , domoticz.LOG_INFO)
elseif (dimmer.state == 'Off') then
domoticz.log('dimmerstate = off. dimmerlevel: ' .. dimmer.level , domoticz.LOG_INFO)
dimmer.dimTo(INIT_LEVEL)
domoticz.log('dimmerstate = off; dimto '.. INIT_LEVEL .. '. dimmerlevel: ' .. dimmer.level , domoticz.LOG_INFO)
--dimmer.dump()
dimmer.switchOff().checkFirst().afterMin(DURATION)
dimmer.switchOn().checkFirst().forMin(DURATION)
else
dimmer.cancelQueuedCommands()
dimmer.switchOff()
end
end
domoticz.log('Device ' .. dimmer.name .. ' was changed', domoticz.LOG_INFO)
end
}
Code: Select all
2019-11-22 00:26:32.932 (rfxcom) Lighting 1 (Elin drukknop)
2019-11-22 00:26:33.016 Status: dzVents: Info: Handling events for: "Elin drukknop", value: "Chime"
2019-11-22 00:26:33.016 Status: dzVents: Info: ------ Start internal script: DzVents device Elin drukknop: Device: "Elin drukknop (rfxcom)", Index: 656
2019-11-22 00:26:33.017 Status: dzVents: Info: dimmerlevel: 75; INIT_LEVEL: 50; dimmerstate: Off
2019-11-22 00:26:33.018 Status: dzVents: Info: dimmerstate = off. dimmerlevel: 75
2019-11-22 00:26:33.018 Status: dzVents: Info: dimmerstate = off; dimto 50. dimmerlevel: 75
2019-11-22 00:26:33.018 Status: dzVents: Info: Device Hue Ikea lamp PC beneden was changed
2019-11-22 00:26:33.018 Status: dzVents: Info: ------ Finished DzVents device Elin drukknop