Completed Garage Door and Web Interface - Schematic and Code included

This is awesome.

You want a bigger feat of awesome, figure out how I can do it for my car. We ALWAYS Leave our car unlocked and sadly we just had some things lifted from it.

Spark Core that! :smile:

Thanks very much for the details on your garage door project. I purchased a Relay Shield for my Spark Core and am implementing a dual opener and sensor for my two-car garage. One small change I made to the core code (in addition to changing the locations of the I/O) was to redefine the reed switch input as type “INPUT_PULLUP”, which enabled the internal 40K pullup resistor. Without this change or an external pullup, the status of the digital input was indeterminate.

Thanks a ton on this. Curious as to why you went with the timer only in cases when the switch state we’re not equal. Is there a built in throttle to the loop function?

I’m (brand spanking) new to Photon. That being said I got this running with my reed switch thanks to your comments.

Thanks again!

1 Like

If that's referring to the delay after the publish, it's because the publishes are rate limited to one per second. If the delay weren't there it would blow over that almost instantly since the loop is really fast.

I'm sure the entire code can be improved on quite a bit, but at least it works. Let me know if you need further help.

1 Like

Thanks for the code. I am having an issue where when the door should be open, it refreshes button sometimes as closed and then open and then close etc. There seems to be no issue when the door is closed (it is always displays correctly as closed). Do you know why this may be? Thanks in advance.

Stvjay - are you able to post your code for this? I’m new to this coding world and in a world of disarray! Your post seems to be on target for what I need to complete my project. Are you able to incorporate yours into IFTTT if you choose to do so? Thanks in advance.

Sorry Andrew, but I never completed the project. I’m still using a Raspberry Pi to control my garage door (yeah, I know it’s overkill :-)). Are there any problems in particular that you are experiencing?

I’ve updated the webapp code on codepen and github a bit to now use particle API instead of spark (I know, I’m late to the party) as well as not do constant API calls. It’s also more mobile friendly.

I can’t seem to edit the original post, so I’ll add it here:
I’ve added a pebble watch app code so you can open the garage from your Pebble watch. It’s nothing special, but it works :slight_smile:

The code is on github: https://github.com/austinpe/garagecore

As well as here:

/**
 * Garagecore Pebble App
 * Control your garagecore with your pebble watch
 * Liscense: MIT
 * Austin PE
 * https://github.com/austinpe/garagecore
 */

var UI = require('ui');
var ajax = require('ajax');

//key is the same as your 'access token'
var key = "xxxx";

//device_id is the same as the 'core id'
var device_id = "xxxx";

//API call URL
var api_url = "https://api.particle.io/v1/devices/" + device_id + "/";

//status_check_time is the amount of time in ms that you want 
//to wait between checking the status of the garage door
// this should be a little longer than it takes for your garage door to open/close
var status_check_time = 18000;


// Create a Card with title and subtitle
var card = new UI.Card({
  title:'Garage Core',
  subtitle:'Fetching...'
});

// Display the Card
card.show();

var status_to_english = function(status) {
    if (status === 1) {
      card.subtitle('Open');
      console.log('open');
        //$('.status_open').css('display', 'block');
    } else if (status === 0) {
      card.subtitle('Closed');
      console.log('closed');
        //$('.status_closed').css('display', 'block');
    } else {
      card.subtitle('Disconnected');
      console.log('unkown');
        //$('.status_none').css('display', 'block');
    }
};

function garage_status() {
  ajax(
    {
      url: api_url + "status",
      method: 'POST',
      data: {access_token: key},
    },
    function(data){
      data = JSON.parse(data);      
      var response = data.return_value;
      status_to_english(response);
    },
    function(error) {
      console.log(error);
    }
  );
}

function garage_pulse() {
  ajax(
    {
      url: api_url + "relay",
      method: 'POST',
      data: {access_token: key},
    },
    function(data){
      setTimeout(function(){garage_status();}, status_check_time);
      card.body('Command Sent');
      setTimeout(function(){card.body('');}, 1000);
    },
    function(error) {
      console.log(error);
    }
  );
}

card.on('click', 'up', function(){
  garage_pulse();
});

garage_status();