Use Motion from Blynk as a Trigger in IFTTT

I am using a NodeMCU with a PIR module. I have already setup the project in my Blynk App & I am able to get notification when motion is detected. So I want to use this motion as a trigger to turn on my WiFi Light. I am using Sonoff switch, which is connected to IFTTT. After reading through many forums, watching many video etc I still can’t figure out how to do it. The closest I have ever got was using the Webhook Widget. But I can’t understand how to set it up. I mean what should I set as the Output PIN (V0, v1, …), URL, Method (GET, POST, …), Content Type (application/json, text/plain) & Body.

1 Like

So what is IFTTT expecting, in terms of an incoming command, to turn your Sonoff on and off?

Pete.

Turn on. Actually i created the applet which lets me turn on the light as the THEN action. But i dont understand how i can use the motion from my blynk project as the IF trigger.

How have you tested this connection between the Sonoff and IFTTT?

Pete.

@satyajitmishra191293

I got from your post that you implement the below:

  • NodeMCU circuit with motion detection
  • a sonoff connected as a light switch

You want to motion to trigger sonoff (light switch), and this can be achieved with 4 modifications

1- Configure a rules in IFTTT with trigger (THIS) as “webhooks”, and action (THAT) as eWeLink
for webhooks, you will choose a name for the event,
for example “turnonwifi” as the event name

for eWeLink, you first will enter login details,then choose “Turn 1 Channel Switch on or off”, then choose your device and choose “on”

so, now you have a url that can turn on your sonoff switch
link will be like “https://maker.ifttt.com/trigger/{event name}/with/key/”
for example
https://maker.ifttt.com/trigger/turnonwifi/with/key/

to get your ifttt url
for PC: go to ifttt.com, then from user icon on the left, choose “My Services”, choose “Webhooks”, then click “documentation”
for Android: click on your email on the left top corner, choose “My Services”, then “Webhooks”, then “Get More”, then “Documentation”.

2- Configure another rules in IFTTT with trigger (THIS) as “webhooks”, and action (THAT) as eWeLink
for webhooks, you will choose a name for the event,
for example “turnoffwifi” as the event name

for eWeLink, you first will enter login details,then choose “Turn 1 Channel Switch on or off”, then choose your device and choose “off”

so, now you have another url that can turn off your sonoff switch
link will be like “https://maker.ifttt.com/trigger/{event name}/with/key/”
for example
https://maker.ifttt.com/trigger/turnoffwifi/with/key/

3- You will modify NodeMCU code, and application to use webhook so it trigger webhook url (mentioned in first point above) when motion is detected

https://docs.blynk.cc/#widgets-other-webhook

for code modification:
Blynk.virtualWrite(V10, 1); // to turn on
Blynk.virtualWrite(V20, 1); // to turn off

for app:
create two webhooks,
one for V10 pin, with url from step 1
one for V20 pin, with url from step 2

In the “Create your own - IFTTT” I selected the “IF THIS” as a “Service”. This service was “Webhooks” & under it I selected the “Receive a web request”. Then I gave it a name & created a trigger. Then I selected the “THEN THAT” as “eWeLink Smart Home”, under that “Turn 1 Channel Switch on or off”. Then I selected the switch & chose its state as On & created the action. Finishing the applet. By going to the webhooks service, under their documentation, there is an url which has space given after trigger where I put the name of the event. And when I use this link in my browser, the THEN THAT action i.e. the Sonoff switch is turned on.

Actually I don’t want to add code to my NodeMCU. The Blynk app detects the motion when I select Notification Widget. In the widget section there is a option for Webhooks. So is there any way to use the motion detected as the trigger which can interact with an IFTTT event.

What is the “V10 Pin”?

Actually it is any unused virtual pin, you can choose whatever you want but configure the same in app corresponding webhook widget

How you send notification from hardware… Using something like the below?

Blynk.notify(“Hey, Blynkers! My hardware can push now!”);

Can you please elaborate?

Actually I used this; https://www.instructables.com/id/IoT-Motion-Detector-With-NodeMCU-and-BLYNK/
The code is in this webpage

you need to modify the code adding these lines

/***************************************************
 * Get PIR data
 **************************************************/
void getPirValue(void)
{
  pirValue = digitalRead(pirPin);
  if (pirValue) 
  { 
    Serial.println("==> Motion detected");
    Blynk.notify("T==> Motion detected");  
    Blynk.virtualWrite(V10, 1); // To call webhook
  }
  digitalWrite(ledPin, pirValue);
}

Blynk.virtualWrite(V10, 1); // this will call the “webhook” widget you created in the app to call the url in it, and turn on sonoff

Okay I will try that. But is there any way to do this without modifying the code i.e. via the app only.

Good Job… Hope it work normally as you expect

I will try to implement a test nodemcu to confirm code is working normally, and will update you.