Blynk, IFTTT & Momentairy Switch

Hello everyone, Last time i posted an Topic i got great help that worked, so thank you for that!

The guy that helped me also redirected me to another topic about momentairy Switching with Blynk
But unfortunately it (and other topics) dont work for me. I dont know what i am doing wrong, therefore i write this Topic

First of all i will tell you a little about the project
I am trying to make a system so when i say to my Google Assistant that i should turn on the computer
Then the NodeMCU will be a momentairy switch that will emulate a button that will be pressed for 1 second and then automatically turn off

The problem i have is that when i say to google it will turn on and never turn off again which is a problem, it should automatically turn off after 1 second or so

I hope you can help me :smiley:

I think it was probably me that pointed you towards a possible solution.
To be honest, this is not a Blynk issue, but without some information about what you’ve tried and why it didn’t work, it’s difficult for anyone to do more than I did and signpost you toward potential solutions.

Pete.

Sounds like a job for a timeout timer. I use such a timer in this example.

Yes @PeteKnight it was you that sent me there.
Right now i just use the normal Blynk Libary, because the codes of didnt do anything for me

@PeteKnight & @Gunner
I’ve tried both links you gave me and i have the same problem, when i try to upload the code it will just display the error:

exit status 1
‘timer’ was not declared in this scope

I dont know what to do. but i tried to include the SimpleTimer Libary with no luck

Post the code that you’re having problems with (correctly formatted of course) along with the error message you’re getting, and we’ll take a look at it.

Pete.

Used @Gunner’s method

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth = “YourAuthToken”;
char ssid = “YourNetworkName”;
char pass = “YourPassword”;
int latchButton;
int latchFlag;

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

Blynk.begin(auth, ssid, pass);
}

//===== Timeed latching button =====
BLYNK_WRITE(V1) { // Button Widget set as switch
latchButton = param.asInt();
if (latchButton == 1 && latchFlag == 0) {
latchFlag = 1; // Keeps from allowing button press more then once while relay activated
// ----- Start your timed thing here
digitalWrite(5, HIGH); // Activate digital pin
// -----
timer.setTimeout(5000L, { // Timed Lambda Function - Latching Button release after 5 seconds
// ----- Stop your timed thing here
digitalWrite(5, LOW); // Deactivate digital pin
// -----
Blynk.virtualWrite(V1, 0); // Reset Latching Button to OFF
latchFlag = 0; // resets to allow next interaction
}); // END Timer Function
} else {
if (latchButton == 0 && latchFlag == 1) { // If you try to tun off the button before time is up
Blynk.virtualWrite(V1, 1); // Restore Latching Button ON until timer is finished
}
}
}

void loop()
{
Blynk.run();
}

The error was:

Arduino: 1.8.8 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

C:\Users\mathi\AppData\Local\Temp\arduino_modified_sketch_679240\ESP8266_Standalone.ino: In function ‘void BlynkWidgetWrite1(BlynkReq&, const BlynkParam&)’:

ESP8266_Standalone:27:5: error: ‘timer’ was not declared in this scope

 timer.setTimeout(5000L, []() {  // Timed Lambda Function - Latching Button release after 5 seconds
 ^

exit status 1
‘timer’ was not declared in this scope

add this code
BlynkTimer timer;

Where?

Some examples of this code apply, please learn.
https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=More%2FStroboscope
and
https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=More%2FSync%2FSyncPhysicalButton
and many more examples, please explore

Anywhere after this line, and before your void setup…

#include &lt;BlynkSimpleEsp8266.h&gt;

Pete.

Hey @PeteKnight, @Gunner and @projecttrinof Thanks so much for the help!

I’ve been looking around in other topics
So with your help and others i was beginning to understand it. and now i accomplished my goal of turning it on momentarily. to turn on my computer.

1 Like

Hey, can you share the entire code that you did for momentarily switching on the relay?
Ben

Maybe you could post how far you have gotten and we could help you with your code.