Skip to content

Commit

Permalink
issue #3: make relay active state configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rsporny committed Nov 20, 2017
1 parent a08c612 commit 7be261e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Sample accessory:
"pinUp": 5,
"pinDown": 11,
"durationUp": 13000,
"durationDown": 13000
"durationDown": 13000,
"activeLow": false
}
]
```
Expand All @@ -34,6 +35,7 @@ Fields:
- `pinDown` pin for moving down
- `durationUp` milliseconds to open blinds completely
- `durationDown` milliseconds to close blinds completely
- `activeLow` set to false if your relay is activated by high state (default: *true*)

## Raspberry Pi setup
- Raspberry Pi 3 (should work with all versions)
Expand Down
8 changes: 5 additions & 3 deletions config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
"pinUp": 5,
"pinDown": 11,
"durationUp": 13000,
"durationDown": 13000
"durationDown": 13000,
"activeLow": false
},
{
"accessory": "Blinds",
"name": "Bedroom",
"pinUp": 4,
"pinDown": 3,
"durationUp": 27000,
"durationDown": 25000
"durationDown": 25000,
"activeLow": false
}
]
}
}
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var _ = require("underscore");
var rpio = require("rpio");
var Service, Characteristic;

Expand All @@ -13,12 +14,16 @@ module.exports = function(homebridge) {
}

function BlindsAccessory(log, config) {
_.defaults(config, {activeLow: true});

this.log = log;
this.name = config['name'];
this.pinUp = config["pinUp"];
this.pinDown = config["pinDown"];
this.durationUp = config['durationUp'];
this.durationDown = config['durationDown'];
this.initialState = config['activeLow'] ? rpio.HIGH : rpio.LOW;
this.activeState = config['activeLow'] ? rpio.LOW : rpio.HIGH;

this.currentPosition = 0; // down by default
this.targetPosition = 0; // down by default
Expand All @@ -36,8 +41,8 @@ function BlindsAccessory(log, config) {
rpio.init({
mapping: 'gpio'
});
rpio.open(this.pinUp, rpio.OUTPUT, rpio.HIGH);
rpio.open(this.pinDown, rpio.OUTPUT, rpio.HIGH);
rpio.open(this.pinUp, rpio.OUTPUT, this.initialState);
rpio.open(this.pinDown, rpio.OUTPUT, this.initialState);

this.service
.getCharacteristic(Characteristic.CurrentPosition)
Expand Down Expand Up @@ -106,9 +111,9 @@ BlindsAccessory.prototype.setTargetPosition = function(position, callback) {
}

BlindsAccessory.prototype.togglePin = function(pin, duration) {
rpio.write(pin, rpio.LOW);
rpio.write(pin, this.activeState);
setTimeout(function() {
rpio.write(pin, rpio.HIGH);
rpio.write(pin, this.initialState);
}.bind(this), duration);
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-gpio-blinds",
"version": "1.0.0",
"version": "1.0.1",
"description": "Homebridge plugin to control blinds via Raspberry Pi GPIO pins",
"license": "MIT",
"keywords": [
Expand All @@ -16,7 +16,8 @@
"url": "https://github.com/rsporny/homebridge-gpio-blinds"
},
"dependencies": {
"rpio": "^0.9.12"
"rpio": "^0.9.12",
"underscore": "^1.8.3"
},
"engines": {
"homebridge": ">=0.4.6",
Expand Down

0 comments on commit 7be261e

Please sign in to comment.