BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

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


#7


#8

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


#9

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


#11

basically using

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

in the url


#12

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.


#14

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”


#15

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”


#16

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.


#17

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


#18

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().


#19

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


#20

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

#21

/*************************************************************
  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
  

  
}


#22

is that what you meant costas?


#23

No.

Move last 2 lines of loop() into myTimerevent().


#24

hey costas thanks for your reply again , when i have done that the relay just goes on and off continuously, with no control via the virtual pin any ideas?


#25

What @Costas meant was there should only be blynk.run() and timer.run() in loop(), if you want to run a timed event. Set up the timed event in setup().

In your myTimerevent, you are writing the current second since boot to the pin. It will do nothing on the board.

If you want to toggle the light on the board via IFTTT, then just set a virtual pin via IFTTT Webhooks. In your code, in the BLYNK_WRITE(Vx) event, toggle the pinnas @Gunner had given.


#26

and that will go in loop()?


#27
BLYNK_WRITE(V1){
digitalWrite(14, !digitalRead(14));
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}

#28
> /*************************************************************
>   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[] = "YourAuthToken";
> 
> // Your WiFi credentials.
> // Set password to "" for open networks.
> char ssid[] = "YourNetworkName";
> char pass[] = "YourPassword";
> 
> 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);
> }
> BLYNK_WRITE(V1){
> digitalWrite(14, !digitalRead(14));
> }
> void loop()
> {
>   Blynk.run();
>   timer.run(); // Initiates BlynkTimer
> }

Like that? :slight_smile: