Set pin value = 1 and immediately after = 0 (like a button on push mode) through web request (IFTTT+Webhooks)

Hello!

I am setting up my automation system and am looking for a solution as explained below:

I am using IFTTT, with the google assistant as the input and Webhooks as the output. I can sucessfully change the value of pins like that, but what i really need is to send a command to set the pin value to “1” (high), and few miliseconds after set its value to “0” (low). That’s because i am using impulse relays, so if the pin value continues as high, the relay won’t change state when I try to comand it from other sources, like the blynk app it self.

So,

1 - How can I do that in a single web request?
2 - How can I do that for more pins in the same web request?

I would like to thank the Blynk team in advance, the app is simply amazing!

maybe you could use the blynk api?

1 Like

you need to use Blynk timer or simpletimer Lib to handle such delay without breaking
the Connectivity.

1 Like

Maybe is there an easier option?

What I really want to do is to simulate a button (push mode) trough the webrequest, like I have on the app.

Maybe its possible to do it straigh like that, instead of making the pin work as a button switch?

I want first to make sure it is possible to do without adding line codes to the nodemcu sketch. Righ now i am using only the Blynk.run(); function and the rest needed for conection.

I checked the Blynk API but couldn’t find out yet if its possible do this.

PS: I am updating the title of the topic.

…i do not think so. but it is not too complicated. for button press time i think you can find available code on this forum.

1 Like

That “simple” mode get people started, flicking the state of a few pins and blinking some LEDs, etc… But you will need to invest in some coding to really utilise the power of Blynk and things like API, IFTT, Webhooks, etc.

Like quick, timed, pin activation/deactivation pulses

BLYNK_WRITE(Vx) { // when Button Widget or Web API called
  if (param.asInt() == 1) {
    digitalWrite(6, HIGH);
    timer.setTimeout(100L, []() {  // reset pin in 100ms
      digitalWrite(6, LOW);
    });
  }
}
4 Likes

Thank you very much @Gunner Gunner!

I installed the simple timer and made it work flawless. Some minutes ago I had succeeded using a delay funtion (thanks to this topic I found: Virtual pin to control momentary latch relay) and trigging the virtual pin trough webhook to change the state of the digital pin, but now its even better with the timer your time function.

I have some comments about the code though, for whoever needs it in the future:

1 - After setting the digital pin low, it’s better to set the virtual pin low as well.
2 - It’s necessary to add the timer funcion to the void loop to make the timer work.

And you are right about investing in some coding to really utilise the power of Blynk!

Thanks also to @wanek wanek and @scropion86

Working Code:

...(other libraries)+
#include <SimpleTimer.h>
SimpleTimer timer;

void setup() { 
 ...(other confings) +

pinMode (14, OUTPUT);

}

BLYNK_WRITE(V1) {
   if (param.asInt()==1){  // act only on the HIGH and not the LOW of the momentary
    digitalWrite(14, !digitalRead(14));  // invert pin state just once
    timer.setTimeout(100L, [](){
    digitalWrite(14, !digitalRead(14));  // then invert it back after 100ms
  Blynk.virtualWrite(V1, LOW);
//    });
  
    });
    }
}

void loop() {
  
  Blynk.run();
  timer.run();
}
3 Likes

I was assuming Widget as momentary, but yes… tweak as required.

I was also assuming one would setup the required prerequisites as per documentation and examples.

Otherwise, glad you got it working so fast :smile:

1 Like

:wink:

And I am glad to receive such a quick help from the community! The problem was solved within 12h!

1 Like

A post was split to a new topic: Problem with IFTTT + Webhooks and Google Assistant

Buona sera premetto che non sono in grado di programmazione ma ho usato blynk X fare una domotica casalinga ho lo stesso problema vorrei usare relè come pulsanti mi aiutereste a modificare il programma grazie X farlo funzionare