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

Blynk, IFTTT & Momentairy Switch

#1

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:

0 Likes

#2

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.

0 Likes

#3

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

0 Likes

#4

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

0 Likes

#5

@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

0 Likes

#6

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.

0 Likes

#7

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

0 Likes

#8

add this code
BlynkTimer timer;

0 Likes

#9

Where?

0 Likes

#10

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

0 Likes

#11

Anywhere after this line, and before your void setup…

#include &lt;BlynkSimpleEsp8266.h&gt;

Pete.

0 Likes

#12

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