0

if topic = 1 do this then publish back a 0?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

if topic = 1 do this then publish back a 0?

by Kris_J on Thu Jan 17, 2019 5:55 pm

I bought a new car and want to tinker with Google Assistant customization. I'm new to IFTTT, MQTT, etc.

Hardware:
Garage door button near entrance to house proper is just a momentary short circuit, so a ESP8266 controlled relay in parallel should do the trick.

Software:
IFTTT Applet: IF Kris says this, then write a 1 to GarageDoor feed @ Adafruit.IO
ESP8266: subscribe to and check the GarageDoor feed; if feed = 1 then pulse the relay.

Problem:
How do I return the feed to zero after pulsing the relay?
In other words, exactly like the momentary switch in my Garage Door Dashboard block on A.IO

Thoughts:
Would I use a Trigger in A.IO? "if feed = 1 then write a zero back to feed"
This seems like it would happen instantly, and the ESP8266 wouldn't get a chance to detect the 1?

Or would I do something in the ESP8266 code?
"if feed = 1 then pulse the relay AND write a zero back to the feed"

Thanks!

Kris_J
 
Posts: 10
Joined: Wed Dec 19, 2012 6:00 pm
Location: Battle Creek, MI USA

Re: if topic = 1 do this then publish back a 0?

by brubell on Thu Jan 17, 2019 6:47 pm

IFTTT would check against the feed's value (of 1). This is a similar applet: https://ifttt.com/applets/317329p-if-a- ... he-details

In your code, you would write a '1' to the feed to pulse the relay. If you are using Adafruit IO Arduino or an MQTT library which is subscribed to the `garagedoorfeed`, the action's handler (the code which opens the garage door) will be called. After this code happens, you'd send a value of 0 back to the feed.

Here's some psedudo-code based off of Adafruit IO Ardino's MessageHandler

Code: Select all | TOGGLE FULL SIZE
// this function is called whenever a 'garagedoor' message
// is received from Adafruit IO. it was attached to
// the garagedoor feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {

  Serial.println("Value on Adafrit IO Feed");
  enableGarageDoorRelay();
  // wait RELAY_DELAY seconds (however long it takes for the garage door to open/close).
  delay(RELAY_DELAY * 1000);
  garagedoor->save(0);
}

brubell
 
Posts: 245
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.