Skip to content

Commit

Permalink
Add support for scene status via a keypadlnc
Browse files Browse the repository at this point in the history
  • Loading branch information
kuestess authored May 8, 2018
1 parent 6c7fcd0 commit 17bc285
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ Edit the config.json (see example) to fit your installation - configuration para
Devices are also defined in the config.json as follows:

- `name`: Device name as you want it to appear in Homebridge
- `deviceID`: Insteon ID with no spaces or dividers
- `deviceID`: Insteon ID with no spaces or dividers
- `groupID`: Insteon group ID for a scene
- `keypadbtn`: Keypad button to check for status of a scene, in caps (8-key models only)
- `dimmable`: dimmable or non-dimming device - valid values are "yes" or "no"
- `deviceType`: valid values include 'lightbulb', 'dimmer', 'switch', 'scene', 'iolinc', 'motionsensor', 'leaksensor'

Scenes are currently on/off only, and do not support status (although the status of the component devices will update). When defining a scene, the `deviceID` parameter should be the group number in the Insteon app (Scenes->Edit Scene->Group Number).
**Scene config changes in 0.3.2 and later**

Scenes remain on/off only, and now support status when controlled via a Keypadlinc. When defining a scene, the `deviceID` is the Insteon ID of a keypad that controls the scene and `keypadbtn` is then button that indicates the status of the scene. The `groupID` parameter is now the group number in the Insteon app (Scenes->Edit Scene->Group Number).

For iolinc devices, there is an additional parameter that can be defined:

Expand Down
93 changes: 88 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,19 @@ function InsteonLocalPlatform(log, config, api) {
}

break

case ('scene'):
//var group = parseInt(command2, 16)
//if (group == foundDevice.groupID) {

self.log('Got updated status for ' + foundDevice.name)
foundDevice.getSceneState.call(foundDevice)

foundDevice.lastUpdate = moment()
//}

break

case 'iolinc':
if (command1 == 11 || command1 == 13) {
setTimeout(function() {
Expand Down Expand Up @@ -339,7 +351,6 @@ InsteonLocalAccessory.prototype.pollStatus = function() {
switch (self.deviceType) {
case ('lightbulb' || 'dimmer'):
self.getStatus.call(self)

setTimeout(function() {self.pollStatus.call(self)}, (1000 * self.refreshInterval))
break

Expand All @@ -352,6 +363,11 @@ InsteonLocalAccessory.prototype.pollStatus = function() {
self.getSensorStatus.call(self)
setTimeout(function() {self.pollStatus.call(self)}, (1000 * self.refreshInterval))
break

case ('scene'):
self.getSceneState.call(self)
setTimeout(function() {self.pollStatus.call(self)}, (1000 * self.refreshInterval))
break
}
}
}
Expand Down Expand Up @@ -643,7 +659,7 @@ InsteonLocalAccessory.prototype.setRelayState = function(state, callback) {
InsteonLocalAccessory.prototype.setSceneState = function(state, callback) {
var self = this
var powerOn = state ? "on" : "off"
var groupID = parseInt(self.id)
var groupID = parseInt(self.groupID)

self.log("Setting power state of " + self.name + " to " + powerOn)

Expand Down Expand Up @@ -698,6 +714,63 @@ InsteonLocalAccessory.prototype.setSceneState = function(state, callback) {
}
}

InsteonLocalAccessory.prototype.getSceneState = function(callback) {
var self = this
var buttonState
var timeout = 0
var buttonArray = {'A': 7, 'B': 6, 'C': 5,'D': 4,'E': 3,'F': 2,'G': 1,'H': 0};

if (self.keypadbtn == 'A') {
var cmd = {
cmd1: '19',
cmd2: '00',
};
} else {
var cmd = {
cmd1: '19',
cmd2: '01',
};
}

self.log('Getting status for ' + self.name)

hub.directCommand(self.id, cmd, timeout, function(err,status){
if(err || status == null || typeof status == 'undefined'){
self.log("Error getting power state of " + self.name)
self.log.debug('Err: ' + util.inspect(err))
return
} else {

var hexButtonMap = status.response.standard.command2
var binaryButtonMap = parseInt(hexButtonMap, 16).toString(2);
binaryButtonMap = "00000000".substr(binaryButtonMap.length) + binaryButtonMap //pad to 8 digits

self.log.debug('Binary map: ' + binaryButtonMap)

var buttonNumber = buttonArray[self.keypadbtn]
var buttonState = binaryButtonMap.charAt(buttonNumber)
self.log.debug('Button ' + self.keypadbtn + ' state is ' + buttonState)

if (buttonState > 0) {
self.currentState = true
self.level = 100
} else {
self.currentState = false
self.level = 0
}

self.log.debug(self.name + ' is ' + (self.currentState ? 'on' : 'off'))
self.service.getCharacteristic(Characteristic.On).updateValue(self.currentState)
if (self.dimmable) {
self.service.getCharacteristic(Characteristic.Brightness).updateValue(self.level)
}
self.lastUpdate = moment()
return
}
})
}


function InsteonLocalAccessory(platform, device) {
var self = this

Expand All @@ -724,14 +797,20 @@ InsteonLocalAccessory.prototype.init = function(platform, device) {
self.lastUpdate = ''
self.refreshInterval = platform.refreshInterval || 0
self.server_port = platform.server_port


if (self.deviceType == 'scene') {
self.groupID = device.groupID
self.keypadbtn = device.keypadbtn
}

if (self.deviceType == 'iolinc') {
self.gdo_delay = device.gdo_delay || 15
}

if(self.refreshInterval > 0){
hub.on('connect',function(){
if (self.deviceType == ('lightbulb' || 'dimmer' || 'switch' || 'iolinc')){
if (self.deviceType == ('lightbulb' || 'dimmer' || 'switch' || 'iolinc' || 'scene'))
{
self.pollStatus.call(self)
}
}
Expand Down Expand Up @@ -829,7 +908,11 @@ InsteonLocalAccessory.prototype.getServices = function() {
self.dimmable = false

self.service.getCharacteristic(Characteristic.On).on('set', self.setSceneState.bind(self))


hub.on('connect', function() {
self.getSceneState.call(self)
})

break

case 'iolinc':
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-platform-insteonlocal",
"version": "0.3.1",
"version": "0.3.2",
"description": "Insteon platform plugin with local control for homebridge: https://github.com/nfarina/homebridge",
"license": "ISC",
"keywords": [
Expand Down

0 comments on commit 17bc285

Please sign in to comment.