Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some direction on a garage door opener #1348

Closed
d0n13 opened this issue Jun 14, 2017 · 4 comments
Closed

Some direction on a garage door opener #1348

d0n13 opened this issue Jun 14, 2017 · 4 comments

Comments

@d0n13
Copy link

d0n13 commented Jun 14, 2017

Hi all

Just need some help on how to work a garage door opener with the GarageDoorOpener service. It's not too well documented.

I have 3 pins on the Raspberry Pi already wired up to the door and working when I toggle them with a C or bash script, but I really want to use this service instead of node.js or anything like that because it shouldn't need it, although it would be easier. I'm also just worried about having a server on the door that can just open the door if I poke a URL. I know there are ways to fix that but I don't have the time to invest in learning how to do it even though I probably should...

Basically, I'd rather get my head around doing it directly in the accessory code. I've made a start as shown below but I'm a little stuck.

Anybody got an implementation that works and wouldn't mind sharing?

Thansk
Donie

var request = require("request");
var Service, Characteristic;

// These are wiringPi ping numbers
PINS = {
    OpenPIN  : 0,
    ClosePIN : 21,
    StopPIN  : 24
}

module.exports = function(homebridge) {
    Service = homebridge.hap.Service;
    Characteristic = homebridge.hap.Characteristic;

    homebridge.registerAccessory("homebridge-MainGarage", "MainGarage", MainGarageAccessory);
}

function MainGarageAccessory(log, config) {
    this.log = log;
    this.config = config;
    this.name = config["name"];

    this.service = new Service.GarageDoorOpener(this.name);
    this.service
        .getCharacteristic(Characteristic.CurrentDoorState)
        .on('get', this.getCurrentDoorState.bind(this));
    this.service
        .getCharacteristic(Characteristic.TargetDoorState)
        .on('get', this.getTargetDoorState.bind(this))
        .on('set', this.setTargetDoorState.bind(this));
    this.service
        .getCharacteristic(Characteristic.ObstructionDetected)
        .on('get', this.getObstructionDetected.bind(this));
}

MainGarageAccessory.prototype.getCurrentDoorState = function(callback) {
        
    callback(null, 1); // OPEN=0, CLOSED=1, OPENING=2, CLOSING=3, STOPPED=4
}

MainGarageAccessory.prototype.getTargetDoorState = function(callback) {
        
   callback(null, 1); // OPEN=0, CLOSED=1
}

MainGarageAccessory.prototype.setTargetDoorState = function(targetState, callback) {
        
   callback(null, targetState); // OPEN=0, CLOSED=1
}

MainGarageAccessory.prototype.getObstructionDetected = function(callback) {

   callback(null, 0); // 0=NO, 1=YES
}

MainGarageAccessory.prototype.getServices = function() {
    return [this.service];
}
@toshibochan
Copy link

@d0n13
Copy link
Author

d0n13 commented Jun 15, 2017

@toshibochan That's awesome. Nicely done. I'll be using it for reference. I like the way you figured out how to detect if the door was open or not. That was giving me a few issues on how to detect it simply.

Thank you!

@toshibochan
Copy link

Please close this issue if you find the answer. Thanks!

@Quiqui64
Copy link

Did you ever find an answer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants