Skip to content

Commit 7be261e

Browse files
committed
issue #3: make relay active state configurable
1 parent a08c612 commit 7be261e

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Sample accessory:
2121
"pinUp": 5,
2222
"pinDown": 11,
2323
"durationUp": 13000,
24-
"durationDown": 13000
24+
"durationDown": 13000,
25+
"activeLow": false
2526
}
2627
]
2728
```
@@ -34,6 +35,7 @@ Fields:
3435
- `pinDown` pin for moving down
3536
- `durationUp` milliseconds to open blinds completely
3637
- `durationDown` milliseconds to close blinds completely
38+
- `activeLow` set to false if your relay is activated by high state (default: *true*)
3739

3840
## Raspberry Pi setup
3941
- Raspberry Pi 3 (should work with all versions)

config-sample.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
"pinUp": 5,
1414
"pinDown": 11,
1515
"durationUp": 13000,
16-
"durationDown": 13000
16+
"durationDown": 13000,
17+
"activeLow": false
1718
},
1819
{
1920
"accessory": "Blinds",
2021
"name": "Bedroom",
2122
"pinUp": 4,
2223
"pinDown": 3,
2324
"durationUp": 27000,
24-
"durationDown": 25000
25+
"durationDown": 25000,
26+
"activeLow": false
2527
}
2628
]
27-
}
29+
}

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var _ = require("underscore");
12
var rpio = require("rpio");
23
var Service, Characteristic;
34

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

1516
function BlindsAccessory(log, config) {
17+
_.defaults(config, {activeLow: true});
18+
1619
this.log = log;
1720
this.name = config['name'];
1821
this.pinUp = config["pinUp"];
1922
this.pinDown = config["pinDown"];
2023
this.durationUp = config['durationUp'];
2124
this.durationDown = config['durationDown'];
25+
this.initialState = config['activeLow'] ? rpio.HIGH : rpio.LOW;
26+
this.activeState = config['activeLow'] ? rpio.LOW : rpio.HIGH;
2227

2328
this.currentPosition = 0; // down by default
2429
this.targetPosition = 0; // down by default
@@ -36,8 +41,8 @@ function BlindsAccessory(log, config) {
3641
rpio.init({
3742
mapping: 'gpio'
3843
});
39-
rpio.open(this.pinUp, rpio.OUTPUT, rpio.HIGH);
40-
rpio.open(this.pinDown, rpio.OUTPUT, rpio.HIGH);
44+
rpio.open(this.pinUp, rpio.OUTPUT, this.initialState);
45+
rpio.open(this.pinDown, rpio.OUTPUT, this.initialState);
4146

4247
this.service
4348
.getCharacteristic(Characteristic.CurrentPosition)
@@ -106,9 +111,9 @@ BlindsAccessory.prototype.setTargetPosition = function(position, callback) {
106111
}
107112

108113
BlindsAccessory.prototype.togglePin = function(pin, duration) {
109-
rpio.write(pin, rpio.LOW);
114+
rpio.write(pin, this.activeState);
110115
setTimeout(function() {
111-
rpio.write(pin, rpio.HIGH);
116+
rpio.write(pin, this.initialState);
112117
}.bind(this), duration);
113118
}
114119

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "homebridge-gpio-blinds",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Homebridge plugin to control blinds via Raspberry Pi GPIO pins",
55
"license": "MIT",
66
"keywords": [
@@ -16,7 +16,8 @@
1616
"url": "https://github.com/rsporny/homebridge-gpio-blinds"
1717
},
1818
"dependencies": {
19-
"rpio": "^0.9.12"
19+
"rpio": "^0.9.12",
20+
"underscore": "^1.8.3"
2021
},
2122
"engines": {
2223
"homebridge": ">=0.4.6",

0 commit comments

Comments
 (0)