You guys are spot on with the DO button to check the state…
How about putting in a Push Notification when the door is opened/closed so you are notified of the change in state rather than having to check?
Something like this:
int relay = D1;
int delayRelay = D3;
int reed = D6;
int lastState = -1;
int relayPulse(String command)
{
digitalWrite(relay, HIGH);
delay(1000);
digitalWrite(relay, LOW);
return 1;
}
int statusCheck(String command)
{
return digitalRead(reed);
}
void setup()
{
Particle.function("relay", relayPulse);
Particle.function("status", statusCheck);
Particle.publish("myNotifyWebhook", "Garage Opener Restart", 60, PRIVATE);
pinMode(relay, OUTPUT);
pinMode(delayRelay, OUTPUT);
pinMode(reed, INPUT);
digitalWrite(relay, LOW);
digitalWrite(delayRelay, LOW);
}
void loop()
{
int currentState = digitalRead(reed);
if(currentState != lastState)
{
notifyMe(digitalRead(reed));
lastState = currentState;
}
delay(50); //crude debounce for reed switch
}
void notifyMe(int newState)
{
Particle.publish("myNotifyWebhook", newState? "Garage Door Open" : "Garage Door Closed", 60, PRIVATE);
}
myNotifyWebhook
would be a service like Pushover