Skip to content

Commit

Permalink
Adding button press
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Nov 27, 2023
1 parent d2c7226 commit b0e45c8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
9 changes: 9 additions & 0 deletions lutron.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export class LutronLeap {
return this.sendZoneLevelCommand(zone, onOff ? 100 : 0)
}

async sendButtonPress(button) {
var response = await leap.request('CreateRequest', '/button/' + button + '/commandprocessor', {
"Command": {
"CommandType": "PressAndRelease"
}
})
logging.info('command response: ' + JSON.stringify(response))
}

async sendZoneLevelCommand(zone, level) {
var response = await leap.request('CreateRequest', '/zone/' + zone + '/commandprocessor', {
"Command": {
Expand Down
68 changes: 37 additions & 31 deletions mqtt-lutron-leap-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var connectedEvent = function () {
logging.info('Subscribing to topic: ' + topic)
client.subscribe(topic, { qos: 1 })

topic = topic_prefix + '/+/+/+/press'
topic = topic_prefix + '/button/+/press'
logging.info('Subscribing to topic: ' + topic)
client.subscribe(topic, { qos: 1 })
health.healthyEvent()
Expand All @@ -115,38 +115,44 @@ if (_.isNil(client)) {
// MQTT Observation
client.on('message', (topic, message) => {
var components = topic.split('/')
logging.info(' => topic: ' + topic + ' message: ' + message)

// topic_prefix/zone/NUMBER/COMMAND = VALUE
const scope = components[components.length - 4]
const number = components[components.length - 3]
const command = components[components.length - 2]
logging.info(' => topic: ' + topic + ' message: ' + message + ' scope: ' + scope + ' scope: ' + number + ' scope: ' + command)

if (_.isNil(scope) || _.isNil(number) || _.isNil(command)) {
logging.error('malformed MQTT command')
return
}

switch (scope) {
case 'zone':
switch (command) {
case 'on_off':
lutron.sendZoneOnOffCommand(number, message == '1' ? true : false)
break;

case 'level':
lutron.sendZoneLevelCommand(number, Number(message))
break;

default:
logging.error('unhandled command: ' + command)
break;
}
break;

default:
logging.error('unhandled scope: ' + scope)
break;
if (topic.includes('set')) {
const scope = components[components.length - 4]
const number = components[components.length - 3]
const command = components[components.length - 2]
logging.info(' => topic: ' + topic + ' message: ' + message + ' scope: ' + scope + ' scope: ' + number + ' scope: ' + command)

if (_.isNil(scope) || _.isNil(number) || _.isNil(command)) {
logging.error('malformed MQTT command')
return
}

switch (scope) {
case 'zone':
switch (command) {
case 'on_off':
lutron.sendZoneOnOffCommand(number, message == '1' ? true : false)
break;

case 'level':
lutron.sendZoneLevelCommand(number, Number(message))
break;

default:
logging.error('unhandled command: ' + command)
break;
}
break;
default:
logging.error('unhandled scope: ' + scope)
break;
}
} else if (topic.includes('press')) {
const number = components[components.length - 2]
logging.info(' => button press: ' + number)
lutron.sendButtonPress(number)
}
})

Expand Down

0 comments on commit b0e45c8

Please sign in to comment.