HELP WIth google assitant Blynk and FFTT (to flip flop a GPIO)

hello

need help with Iftt webhooks and google assitant using blynk

i am controlling a relay and would like to turn the relay on and off using once voice command

at the moment i have to use two

for example :

Relay - relay turns high “1”

relay off- relay turns low “0”

I would like to be able to say relay and have it turn on (high) then say "relay " again and have it turn low “0”

i am new to this so any help is greatly apreciated

thank you

Use the IFTTT WebHook gadget to add the URL for turning on/off the relay.

Check out this https://blynkapi.docs.apiary.io/# documentation to see how to enter your URL and auth code :slight_smile:

hi thanks for your reply but im not sure what you mean

basically in the body is there a way to toggle instead of going high and low?

thank you

Yes, read the documentation. It’s stated clearly there how to do it.

so as far as i see it only allows me to go “1” with one voice command or “2”

please correct me if im wrong

You are wrong ;). You can send any number you want. For example, I use it to address a PWM dimmable LED. In theory I could add a webhook to send the number I’m speaking.

when i use that it will turn relay off but not back on

There may be an error in your code. Can you post that?

basically using

Http://cloud.blynk.cc:8080/a0424cc5xxxxxxxxxxxx3e18asdasdsadadb/pin/D14

in the url

Have you tried sending [“0”] or [“1”] instead of toggle? Because I don’t see anything in your code to reflect that. Besides, a digital pin can only be 1 or 0.

1 Like

yes i have … thats where my problems starts … i need to make the digital pin turn off then on using one voice command

if i put “1” there the voice command can only turn it on and the same for the “0”

so i m controlling my hallway lights …

if i say hallway lights and the relay is at “1” i need it to go to “0”

if i say hallway lights and the relay is at “0” i need it to go to “1”

Write a Blynk function that is called whenever your voice command happens… the function will simply toggle the relays current pin state to its opposing state.

BLYNK_WRITE(Vx) {  // Relay toggle function processes the following command regardless of the state of the calling vPin
digitalWrite(RelayGPIOpin, !digitalRead(RelayGPIOpin)); // Go HIGH if LOW, go LOW if HIGH
}

You may want to add in some minor timer and flag to keep this from rapidly flip flopping if this function somehow gets rapidly called (e.g. as would happen if using a momentary Button Widget to call this function).

You could also make it so that your voice command always triggers a HIGH, and make this function only trigger on HIGH, but then after flipping the relay, reset the vPin to LOW.

Lots of little ways to do what you need.

hi guys sorry for bringing this back

ive tried to learn more about the project which i put on the back burner and have gotten to here

my understanding is that i will call for a virtual pin via iftt to high or “1” then the code will take that and decide what the state of the pin is and change it accordingly ?

here is the code i have attempted (which doesnt work )

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxh";
char pass[] = "xxxxx";

void setup()
{


 // Debug console
 Serial.begin(9600);

 Blynk.begin(auth, ssid, pass);
 // You can also specify server:
 //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 84xx);
 //Blynk.begin(auth, ssid, pass, IPAddress(192,1xx,1,100), 84xx42);

 int outputPin = 14;

}

void loop()
{
 Blynk.run();

 BLYNK_WRITE(V1) ;  // Relay toggle function processes the following command regardless of the state of the calling vPin
 digitalWrite(outputPin, !digitalRead(outputPin)); // Go HIGH if LOW, go LOW if HIGH

}

please go easy on me

Change your sketch to use the same format as the PUSH DATA example i.e. call a function at timed intervals and just 2 lines of code in loop().

hi Gunner Thank you for your help

so my understanding of what you have written ( as im a complete noob) is

blynk_write(vx) is the virtual pin my iftt will call for

i will need to assign a gpio pin and define it as (Relay GPIOpin)

after looking around i have found other people doing similar thing to what i am trying to achieve but using current/voltage sensing, that is a option but not required as i can use a voice command to just change the state of a two position relay using the voice command “hallway lights”

i am basically creating a three way switch with the "intermediate switch " being under the control of the google assistant and the node mcu

Yes, Just replace Vx with whatever virtual pin you are using… e.g. V1

or just put the appropriate pin number there… e.g.

digitalWrite(14, !digitalRead(14));  // Using GPIO14 (D5) Go HIGH if LOW, go LOW if HIGH

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  NOTE:
  BlynkTimer provides SimpleTimer functionality:
    http://playground.arduino.cc/Code/SimpleTimer

  App project setup:
    Value Display widget attached to Virtual Pin V5
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "txxxdxxxxxixxx";
char pass[] = "xxxxx";

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
  BLYNK_WRITE(V1) ;  // Relay toggle function processes the following command regardless of the state of the calling vPin
  digitalWrite(14, !digitalRead(14));  // Using GPIO14 (D5) Go HIGH if LOW, go LOW if HIGH
  

  
}

is that what you meant costas?