Search code examples
raspberry-piwebhooksifttt

IFTTT, Sonoff and Raspberry Pi


Background:

  • 2 Sonoff Wifi relays to switch the lights on in the garage
  • 1 Raspberry Pi running as a security camera in the garage with motion detection

I've got them working independently but what I'd like to do is turn the lights on if the camera detects motion. I can run a Python script when the camera detects motion but there's no API or anything to talk to the Sonoff relays.

I've been trying to get my head round webhooks for IFTTT but I'm not sure if I'm barking up the wrong tree. I know IFTTT works with Sonoff so I can do something like turning the relays on at sunset.

What I want to do is:

if raspberrypi calls IFTTT
    turn sonoff relay on

I've read several tutorials but I just can't get my head round how this all fits together.

Any ideas gratefully received.


Solution

  • As usual, I spend many, many hours trawling through articles and tutorials only to find that I'm no further forward. I then spend 5 minutes doing the thing that I thought would never work and I'm proved wrong.

    If anyone else is interested:

    When asked for the "if" bit on IFTTT, search for webhooks and follow the instructions. For the "then" bit, search for ewelink (not Sonoff) and choose the one that suits your circumstances.

    You'll end up with something like this:

    curl -X POST https://maker.ifttt.com/trigger/garage_motion_detected/with/key/{your_key_goes_here}
    

    Works a treat!