Domoticz – Set dimlevel using wallswitches
My home automation system (domoticz) uses wall switches of the brand ‘klik aan klik uit’.
These switches are battery powered, and send signals using 433Mhz, just like most car keys.
Domoticz picks up these signals, and sends out Milight signals using 2,4Ghz to my lightbulbs.
This is working perfecly, but this way, I’m only able to switch my lights on and off.
To set a dimlevel, I need to use my phone or tablet.
The mission today is, to create a LUA script for domoticz, to control dimlevels using the wall switches.
Step 1: Create a user variable in domoticz.
To set the dimlevel value, we need a user variable in domoticz, otherwise the local LUA variable will be destroyed at the end of the script.
We need to set an integer, the value is set to ‘0’, we are going to change this using LUA.
Step 2: Create the LUA script
I used the code below to make it work:
-- edit the local variables below local switch_1 = 'Study - SW2' local lamp_1 = 'Study - Desk Light' local var_usr = "Light-Study-Desk" local var_1 = 'Variable:Light-Study-Desk' -- script to dim from 93, 58 and 23% when wallswitch is pushed to 'on' state commandArray = {} if (devicechanged[switch_1] == 'On') then print(lamp_1 .. ' switch is toggeld') if (otherdevices[lamp_1] == 'Off') then commandArray[0]={[lamp_1]='Set Level 93'} commandArray[1]={[var_1]= tostring(93)} print(lamp_1 .. ' level set at 93') elseif ( uservariables[var_usr] == 0 ) -- use this block for when other script write 0 but switch is still in 'on' state. same function as block above then commandArray[0]={[lamp_1]='Set Level 93'} commandArray[1]={[var_1]= tostring(93)} print(lamp_1 .. ' level set at 93') elseif ( uservariables[var_usr] == 93 ) then commandArray[0]={[lamp_1]='Set Level 58'} commandArray[1]={[var_1]= tostring(58)} print(lamp_1 .. ' level set at 58') elseif ( uservariables[var_usr] == 58 ) then commandArray[0]={[lamp_1]='Set Level 23'} commandArray[1]={[var_1]= tostring(23)} print(lamp_1 .. ' level set at 23') elseif ( uservariables[var_usr] == 23 ) then commandArray[0]={[lamp_1]='Set Level 93'} commandArray[1]={[var_1]= tostring(93)} print(lamp_1 .. ' level set at 93') end elseif (devicechanged[switch_1] == 'Off') then commandArray[0]={[lamp_1]='Off'} commandArray[1]={[var_1]= tostring(0)} print(lamp_1 .. ' switched OFF by user') end return commandArray
Leave a Reply