Controlling Lutron Homeworks QS

The Lutron binding doesn’t work with Homeworks QS. @actong88 kindly modified the binding and it worked partially for a while, but a more recent OH update seems to have broken it - see Lutron OH2 binding

I don’t begin to have the skills to write a binding, but I have written a node-js script which runs in the background, and acts as a bridge between openHAB items (with the exec binding) and the Lutron telnet interface. Once customised it essentially does the job of a binding. Reads/writes lights and keypad buttons/LEDs, and writes to blinds (my blinds are unusual non-lutron blinds, so that may not work for everyone).

Happy to share with anyone interested, although I don’t know if it will work for other people’s systems without modification…

I don’t know if anyone is interested but publish away, there will always be takers or people inspired by your solution to come up with something else. Please share…

1 Like

OK! This is provided without liability and, most importantly, on the strict conditions nobody laughs at how bad I am at coding.

Items file covers the lights, the blinds, the keypad LEDs and the keypad buttons. Uses the expire binding and the OH1 exec binding:

// Lutron dimmers
// Note must use OH 1 exec binding

Dimmer bookshelfled {exec=">[*:curl$s]"}
Dimmer kitchenled {exec=">[*:curl$s]"}
Dimmer westspots {exec=">[*:curl$s]"}
Dimmer picturespots {exec=">[*:curl$s]"}
Dimmer kitchen {exec=">[*:curl$s]"}
Dimmer island {exec=">[*:curl$s]"}
Dimmer terrace {exec=">[*:curl$s]"}
Dimmer pendants {exec=">[*:curl$s]"}
Dimmer bookshelfspots {exec=">[*:curl$s]"}
Dimmer diningstrip {exec=">[*:curl$s]"}
Dimmer studyspots {exec=">[*:curl$s]"}
Dimmer studystrip {exec=">[*:curl$s]"}
Dimmer entryspots {exec=">[*:curl$s]"}
Dimmer stairskylights {exec=">[*:curl$s]"}
Dimmer stairfloorlights {exec=">[*:curl$s]"}
Dimmer fourthspots {exec=">[*:curl$s]"}

// Lutron blinds
// Note must use OH 1 exec binding
Switch blindsstudyClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsstudyOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindskitchenClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindskitchenOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsfrenchClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsfrenchOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindstvClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindstvOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindssouthClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindssouthOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsnorthClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsnorthOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsdiningwClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsdiningwOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsdiningClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsdiningOpen{exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsnwClose {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }
Switch blindsnwOpen {exec=">[ON:curl] >[OFF:]", expire="1s,command=OFF" }

String TVLED "TV [%s]"
String KitchenLED "Kitchen [%s]"
String BlindsLED "Blinds [%s]"
String LightsLED "Lights [%s]"
String StudyLED "Study [%s]"
String FourthLED "Fourth [%s]"

String TVKeypad "TV [%s]" {exec=">[*:curl$s] >[OFF:]",expire="1s,command=OFF" }
String KitchenKeypad "Kitchen [%s]" {exec=">[*:curl$s] >[OFF:]",expire="1s,command=OFF" }
String BlindsKeypad "Blinds [%s]" {exec=">[*:curl$s] >[OFF:]",expire="1s,command=OFF" }
String LightsKeypad "Lights [%s]" {exec=">[*:curl$s] >[OFF:]",expire="1s,command=OFF" }
String StudyKeypad "Study [%s]" {exec=">[*:curl$s] >[OFF:]",expire="1s,command=OFF" }
String FourthKeypad "Fourth [%s]" {exec=">[*:curl$s] >[OFF:]",expire="1s,command=OFF" }

Then the node-js script does two things. An http server on port 3000 to which commands can be sent by the exec binding. And a telnet client which logs into lutron, reads the state of items and sends it to openHAB (reading at startup, on every state change, and every 15 minutes just in case something was missed).

The arrays at the start hold the various lutron items, and will need changing. Note that on my system all device IDs are two digits. Hence lazily the script assumes that will always be the case - if it isn’t for your system then the script will fail, and need modification.

The script logs what it’s doing into /var/log/lutron-script.log (you will need to create this and give it appropriate privileges)

The telnet command used by the script are:

#MONITORING,3,1 - starts reporting events

The events picked up by the script will be one of:

~OUTPUT, ID,NUM - light number ID has been set to NUM
~DEVICE,ID,NUM,9,[1 or 0] - the LED number NUM on keypad ID has been set on/off
~DEVICE,ID,NUM,3 - button NUM on keypad ID has been pressed

The script queries light and LED settings using:

?output, ID - queries the setting (0-100) for the light with device number ID
?device,ID,NUM,9 - queries the state of LED number NUM on keypad device number ID
this returns:

Finally, it sends commands to the lutron using:
#OUTPUT,ID,1,NUM,5,3 - set light ID to NUM with a slight delay
#DEVICE,ID,NUM,3 - push button NUM on keypad ID
#OUTPUT,ID,6 - send pulse to blind device ID (depending on ID will either open or close blinds). These are non-standard non-lutron blinds, so this element may be useless for everybody else.

#!/usr/bin/env nodejs

// Lutron/openHAB bridge
// Reconnection logic taken from
// Lutron logic from

const http = require('http')
var net = require('net')
var logger = require('/usr/local/lib/node_modules/nodejslogger') 
logger.init({"file":"/var/log/lutron-server.log", "mode":"DIE"})
// Lutron processor details - assumed username/password always lutron/integration
var lutronport = 23
var lutronhost = ''

// openhab details - assumed no username/password within the network
var openHABhost = ''
var openHABport = '8080'

// Lights device number and openhab item name:
// Note assumes all are two digits
var lightsID=[18, 19, 20, 21, 22, 23, 24, 25, 26, 29, 30, 32, 33, 34, 35, 36]
var lightsname=['fourthspots', 'stairfloorlights', 'stairskylights', 'entryspots', 'studystrip', 'studyspots','diningstrip', 'bookshelfspots', 'pendants', 'terrace', 'island', 'kitchen', 'picturespots', 'westspots', 'kitchenled', 'bookshelfled']

// Keypad numbers and names
// Note assumes all numbers are two digits!
// Each keypad has two openhab devices - [panel]Button and [panel]LED
// Each is a String. Buttons are momentary events, LEDs are permanent.
// When a button is pressed, openHAB needs to check the LED status 
// to know if the button is now on or off
// Note that to avoid creating multiple openHAB items,
// only one LED is registered at any one time - the first one.

var keypadID=[16,14,10,12,13,15]
var keypadName=['TV','Kitchen','Blinds','Lights','Study','Fourth']

// Keypad buttons
var keypadButton=new Array()
var keypadButtonstatus=new Array()


// Keypad LEDs
// Note on my system LED ID is always button ID plus 80; I don't know if this is always so
var keypadLED=new Array()
var keypadLEDstatus=new Array()

// Timeout and login flags
var timeout = 1000
var retrying = false
var loginflag = false

//Debounce timer
var lastset= new Array()

// Functions to handle socket events
function makeConnection () {"Making connection")
    socket.connect(lutronport, lutronhost)
    setTimeout(() => {socket.write('lutron\r\n')},1000)
    setTimeout(() => {socket.write('integration\r\n')},2000)
    setTimeout(() => {socket.write('#MONITORING,3,1\r\n')},3000)
    setTimeout(() => {synclights(lightsID,0)},4000)
    setTimeout(() => {syncLEDs(keypadLED,0,0)},10000)


// Sync all LED items
// read with ?device,keypad,LED,9
function syncLEDs(arr, i,j){
      if (j<arr[i].length) {
          if (!loginflag) {
          } else {
  'skipping sync because am logging in')
      } else {


// Sync all lights with ?output,device
function synclights(arr, i){
          if (!loginflag) {
          } else {
  'skipping sync because am logging in')

function regularsync() {'starting regular sync')
  setTimeout(() => {syncLEDs(keypadLED,0,0)},6000)


function FindItem(array, panel,item) {
    for (var i = 0; i < array[panel].length; i++) {
        if (array[panel][i][0] == item) {
            return i;   // Found it
    return -1;   // Not found

function FindString(array, panel,item) {
    for (var i = 0; i < array[panel].length; i++) {
        if (array[panel][i][1].toUpperCase() == item.toUpperCase()) {
            return i;   // Found it
    return -1;   // Not found

function connectEventHandler() {'connected')
    retrying = false

function endEventHandler() {
function timeoutEventHandler() {
function drainEventHandler() {
function errorEventHandler() {
function closeEventHandler () {'lost connection')
    if (!retrying) {
        retrying = true'Reconnecting...')
    setTimeout(makeConnection, timeout)

// Create socket and bind callbacks
var socket = new net.Socket()
socket.on('connect', connectEventHandler)
socket.on('end',     endEventHandler)
socket.on('timeout', timeoutEventHandler)
socket.on('drain',   drainEventHandler)
socket.on('error',   errorEventHandler)
socket.on('close',   closeEventHandler)

// Main data processor
// This parses lutron info
socket.on('data', (data) => {

  var lutronoutput=data.toString('ascii')

//First see if we're logging in (again). If so set 'loginflag' flag
//So we don't risk interrupting login with commands
  if (lutronoutput.substr(0,5)=="login") {"Login prompt detected")
      loginflag = true

// Upon successful login, clear 'loginflag' flag
  } else if (lutronoutput.substr(0,4)=="QNET") {
      if (loginflag) {"Successfully logged in")
        loginflag = false

// Just in case something interrupts logging in
// Detect it and then reconnect
  } else if (lutronoutput.substr(0,8)=="Too many") {"Login error detected")
      loginflag = true
      if (!retrying) {
          retrying = true
      setTimeout(makeConnection, timeout)

// Parse "output" info from Lutron lights
  } else if (lutronoutput.substr(0,7)=="~OUTPUT") { 

    var readID=lutronoutput.substr(8,2)
    var readvalue=lutronoutput.substring(13,lutronoutput.length)

//"Have parsed Lutron output to ID " + readID + ", value " + parseInt(readvalue) + " - compared with old " + parseInt(lastset[readID]))

    if (parseInt(lastset[readID])==parseInt(readvalue)) {
//"(ignoring bounceback of my own update)")
    } else {
      var i=lightsID.findIndex(k => k==readID)

      if (i!=-1) {"Updating OH light "+lightsname[i]+" to: " + readvalue)
      } else {"Unknown ~OUTPUT received: " + lutronoutput)


//  Parse "device" info from Lutron LEDs
  } else if ((lutronoutput.substr(0,7)=="~DEVICE") && (lutronoutput.substr(13,3)==",9,")) {
      var readID=lutronoutput.substr(8,2)
      var readLED=lutronoutput.substr(11,2)

  //  Find keypad ID
      var i=keypadID.findIndex(k => k==readID)
  //  Find LED name
      var j=FindItem(keypadLED,i,readLED)

      if (j==-1) {"Unknown ~DEVICE received: " + lutronoutput)
      } else {"Updating OH LED on keypad"+keypadName[i]+", "+keypadLED[i][j][1]+" to "+lutronoutput.substr(16,1))
    //  If LED is on then update openHAB
        if (lutronoutput.substr(16,1)==1) {

//      If LED is off then clear it
        } else {
            if (keypadLEDstatus[i]==keypadLED[i][j][1]) {

//  Parse "device" info from keypad buttons
   } else if ((lutronoutput.substr(0,7)=="~DEVICE") && (lutronoutput.substr(12,2)==",3")) {
      var readID=lutronoutput.substr(8,2)
      var readbutton=lutronoutput.substr(11,2).replace(/,/g, '')

      //  Find keypad ID
      var i=keypadID.findIndex(k => k==readID)

      //  Find Button name
      var j=FindItem(keypadButton,i,readbutton)

      if (j==-1) {"Unknown ~DEVICE received: " + lutronoutput)
      } else {

        if (keypadButtonstatus[i]==keypadButton[i][j][1]) {
"Won't update OH keypad button as command originated from OH")
        } else {

"Updating OH keypad"+keypadName[i]+", button "+keypadButton[i][j][1])

  } else { 

//  This is a case where there is currently no parsing logic"Received: " + lutronoutput)


// Now connect
console.log("Starting server and telnet connection.")
console.log("Log running in /var/log/lutron-server.log")'Connecting to ' + lutronhost + ':' + lutronport + '...')

// Code for server, receiving requests from openhab exec binding
// accepts urls in the format http://house/ID/value - where ID must be two digits
// example to turn study lights on:            curl "house:3000/L/23/100"
//         to push TV blinds close button      curl "house:3000/B/50"
//         to push "night" button on keypad 16 curl "house:3000/K/16/night"
// So far seems to respond as quickly as openhab can throw commands at it

// If your system has one or three digit IDs then will need to be changed

const port = 3000
const requestHandler = (request, response) => {

//  If am in the middle of re-logging in then delay execution of commands by five seconds
    var delay=0
    if (loginflag) {"As login in progress, will delay response by 5s")

//  We always get a request for "favicon.ico" - discard this
    if (request.url != '/favicon.ico') {

//    Detect and parse command to operate blinds
      if (request.url.substr(0,3)=='/B/') {
        var devID=request.url.substr(3, 2)"Pushing to Lutron, signal to blinds ID " + devID)
        setTimeout(() => {socket.write('#OUTPUT,'+devID+',6\r\n')},50+delay)

//    Detect and parse command to push button
      } else if (request.url.substr(0,3)=='/K/') {

        var devID=request.url.substr(3, 2)
        var devname=request.url.substring(6,request.url.length)
        var i=keypadID.findIndex(k => k==devID)
        var devButton=FindString(keypadButton,i,devname)

        if (devButton==-1) {
"Unknown button requested: " + lutronoutput)

        if (keypadButtonstatus[i]==devname) {
"Won't push keypad button to Lutron as this was read from Lutron")
        } else {
"Pushing to Lutron, keypad "+devID+" to "+keypadButton[i][devButton][0]+": "+devname)
          setTimeout(() => {socket.write('#DEVICE,'+devID+','+keypadButton[i][devButton][0]+',3\r\n')},50+delay)

//    Detect and parse commands to operate light
      } else if (request.url.substr(0,3)=='/L/') {
          var devID=request.url.substr(3, 2)
          var devvalue=request.url.substring(6,request.url.length)

          if (parseInt(lastset[devID])==parseInt(devvalue)) {
//  "(ignoring bounceback from my own update)") 
          } else {
  "Pushing to Lutron, set lights ID " + devID + " to value " + devvalue)
            setTimeout(() => {socket.write('#OUTPUT,'+devID+',1,'+devvalue+',5,3\r\n')},50+delay)

//     Ooops - some other command was received
       } else {"Unrecognised command received: "+request.url.substr(0,3))

       response.end('Lutron house server. See commands in comments')

const server = http.createServer(requestHandler)

server.listen(port, (err) => {
  if (err) {
    return'Unknown error', err)
  }`Lutron/openHAB bridge server is listening on ${port}`)

As of the 2.4 release of OpenHAB, the Lutron binding should work with HomeWorks QS systems. However, some additional testing and development work is necessary to get the level of support to where it should be. I’ve recently started a new topic about it here: Lutron HomeWorks QS Support.