I am using my Photon to control my garage door. Further, I am using IFTTT recipe to trigger door open/close. When the door changes state (open -> close, close -> open), I publish a single Spark event, logging new state. I verified in dashboard, that only 1 event is published. Further, I have a IFTTT recipe to monitor these specific events and notify on my mobile.
Now the problem is, when the door is closed, I receive 1 IFTTT notification (expected correct behavior). But when it opens, I receive 2 notifications! In the dashboard, I see that only 1 event is published, be it open or close command. So, why does open state generate 2 notifications, instead of 1? Any ideas?
Here’s my code:
int remote = D3;
int garageCloseDetectPin = D4;
int commandProcessingUnderway = 0;
String command = "";
String garageState = "";
String previousGarageState = "";
unsigned long currentTime = 0;
void setup() {
pinMode(remote, OUTPUT);
pinMode(garageCloseDetectPin, INPUT);
digitalWrite(remote, HIGH); // reverse relay connections
Spark.function("Garage", garage);
}
void loop() {
currentTime = millis();
garageState = digitalRead(garageCloseDetectPin) == HIGH ? "closed" : "open";
if(commandProcessingUnderway == 0 && ((command.equalsIgnoreCase("open") && garageState.equals("closed")) || (command.equalsIgnoreCase("close") && garageState.equals("open")))) {
digitalWrite(remote, LOW);
commandProcessingUnderway = 1;
Spark.publish("Garage", garageState.equals("closed") ? "Garage opened" : "Garage closed", 60, PRIVATE);
}else if(commandProcessingUnderway == 1 && (previousGarageState.length() > 0 && !previousGarageState.equals(garageState))) {
digitalWrite(remote, HIGH);
commandProcessingUnderway = 0;
}
command = "";
previousGarageState = garageState;
}
int garage(String cmd) {
if(cmd.length() < 1)
return garageState.equals("closed") ? 1 : -1;
// Ignore incoming request, if already processing other request
if(commandProcessingUnderway == 1 || command.length() > 0)
return -100;
// otherwise, record for processing
else if(cmd.equalsIgnoreCase("open") || cmd.equalsIgnoreCase("close")) {
command = cmd;
return 0;
}
}
And here are the event publish logs:
event: Garage
data: {"data":"Garage closed","ttl":"60","published_at":"2015-09-20T06:19:33.587Z","coreid":""}
event: ifttt-trigger-event-check
data: {"data":"{\"count\":34}","ttl":"60","published_at":"2015-09-20T06:19:34.355Z","coreid":""}
event: Garage
data: {"data":"Garage opened","ttl":"60","published_at":"2015-09-20T06:20:57.273Z","coreid":""}
event: ifttt-trigger-event-check
data: {"data":"{\"count\":36}","ttl":"60","published_at":"2015-09-20T06:20:58.537Z","coreid":""}
event: Garage
data: {"data":"Garage closed","ttl":"60","published_at":"2015-09-20T06:21:13.185Z","coreid":""}
event: ifttt-trigger-event-check
data: {"data":"{\"count\":37}","ttl":"60","published_at":"2015-09-20T06:21:14.286Z","coreid":""}
Notice how the numbering scheme (count) is not consistent for IFTTT events! While during OPEN count increased by 2 (34 to 36), during CLOSE it incremented by 1 only (36 - 37). Anybody else noticed this behavior with Particle IFTTT recipes?
[Update] I changed the IFTTT recipe to send me SMS instead of notification, and while the numbering scheme (count) is still messed up ( jumps 2, then jumps 1), I received only 1 SMS for each close and open events! So, when it costs money (sending SMS) things are coded correctly, otherwise not so much Seems more like IFTTT issue to me now.
[Update 2] SMS has the same problem. Published earlier update too soon! 2 SMS received for open and 1 for close.