Leviton Decora Wi-Fi smart switch implementation

Tags: #<Tag:0x00007f1871189008> #<Tag:0x00007f1871188f40>

Currently there is no openHAB binding available for the Leviton Decora WI-FI smart switch. As a workaround to this problem I have successfully implemented the following solution by utilizing a python script that is executed by an openHAB rule.

Items:

Switch Rule_kitchen_lights   "Kitchen lights"	["Lighting"]

Rules:


/*
Usage: python <path>/Decora-cli.py [email] [pswd] [id#:ON|OFF|0-100] <[id#:ON|OFF|0-100]> <etc.>
Usage: python <path>/Decora-cli.py [email] [pswd] ?    ... list all switch ids
*/

rule "Turn on kitchen lights"
when
    Item Rule_kitchen_lights received command
then
	if(receivedCommand==ON) {
             logInfo("Decora ", "Turn on kitchen lights.")
             val Results_decora = executeCommandLine("python /etc/openhab2/scripts/Decora-cli.py <emailaddress> <password> 98765:ON", 120000)
             logInfo("Decora ", Results_decora) 
             }
	if(receivedCommand==OFF) {
             logInfo("Decora ", "Turn off kitchen lights.")
             val Results_decora = executeCommandLine("python /etc/openhab2/scripts/Decora-cli.py <emailaddress> <password> 98765:OFF", 120000)
             logInfo("Decora ", Results_decora) 
             }
end

Notes:

  • Python was automatically installed in my Raspberry Pi during the openHAB installation process. If it’s not installed in your server, you will need to install this application in your server first.
  • Go to https://github.com/markcaldwell0017/python-decora_wifi-cli, select “Clone or download”, select “Download Zip”, download the files, unzip the files and copy all into your openHAB scripts directory (currently found at /etc/openhab2/scripts/)
  • From a terminal command line, log in to Openhabian
    (i.e., ssh openhabian@ip_address), change to the scripts directory (cd /etc/openhab2/scripts/) and execute:
python <path>/Decora-cli.py <emailaddress> <password> ?

Using the above recommended install directory, this would be:

python /etc/openhab2/scripts/Decora-cli.py <emailaddress> <password> ?
  • and receive an output such as:
Permission id#12345 (Accountid#9876)
Residence  id#4567  (your address)
Switch1    id#23456 (Kitchen)
Switch2    id#67890 (Bedroom)
  • Edit the two executeCommandLine’s in the rules file to include your email address, password and the appropriate switch id# as found in the above output.
  • Add additional items and rules to control additional switches.
  • Although not yet tested, the following should set a dimmer switch to the designated dimness level, e.g. 25%:
val Results_decora = executeCommandLine("python /etc/openhab2/scripts/Decora-cli.py <emailaddress> <password> 98765:25", 120000)
  • Since each login to Leviton takes several seconds, you can trigger several switch actions within a single command, which will execute the second, third, etc. switch commands faster:
val Results_decora = executeCommandLine("python /etc/openhab2/scripts/Decora-cli.py <emailaddress> <password> 67890:ON 45678:OFF 23456:50", 120000)
  • Output is logged to the openhab.log file, assuming you have logging turned on.
4 Likes

Thanks for sharing, Mark