Homemade Occupancy Sensor: Using Webhooks, IFTTT & Wyze Motion Sensors

ifttt
#1

I have been trying to figure out a good way to use the Wyze Motion Sensor as an ad-hock occupancy sensor. My goal was to turn off my basement lights after 15 minutes of inactively. I finally figured out a way to do it by using IFTTT & Webhooks and thought I would share the info here.

The only prerequisites are owning a Wyze Motion Sensor, having a free IFTTT account, and activating the IFTTT Webhooks service. Having a free IFTTT Platform account is also helpful for more advanced functionality (but I believe this step is optional).

Step 1: Find your Webhook Key. The “key” is the string of charters after “use/” in the URL (Example: https://maker.ifttt.com/use/xxxvxvxvxvxvxvxxv)

Step 2: Create a new IFTTT Applet. For the THIS action use “If motion sensor becomes clear”. For THAT select the Webhooks service to “make a web request”. In the URL section use the following:
http://lab.grapeot.me/ifttt/delay?event=EVENTNAME&t=15&key=KEY&reset=1
In the URL your EVENTNAME can be anything - mine was BASEMENTOFF. The key needs to be your personal key from step 1. The “15” in the URL can be any time delay you prefer. The method should be GET and the rest can be left alone.

All credit for this webhook goes to Yan Wang who created the API. Here is the raw code if you’re interested in what’s under the hood.

Step 3: Create another IFTTT Applet to perform the action. The THIS should be Webhooks “receive a web request”. The Event Name should match the EVENTNAME in your URL above. The THAT can be anything. In my case it was telling my Wink Hub to run a shortcut to turn off all the basement lights.

When the motion sensor becomes clear it send a webhook request to the URL. The webhook then holds the response for 15 minutes (or for whatever time you entered) and then send if back to IFTTT. Once received, IFTTT triggers the new action applet.

I’m just starting to understand Webhooks but so far it seems like it can be a very powerful tool!
Hope someone else find this useful. If you use this guide to create something cool let me know!

8 Likes
#2

Interesting applet! Curious what happens if someone leaves just long enough for the sensor to clear, then reenters the room? Would the light still go out at 15 minutes from the first clear, or is there some way to cancel or reset that based on the new motion activity?

#3

This is so much easier with Alexa routines. Wish Wyze would hurry up with that integration.

4 Likes
#4

Hmm that’s an interesting situation I’ll have to test out. If you have the sensor in a high traffic area it could cause a bunch of overlapping triggers to turn off the lights. That would be an issue if the lights are turned on in the meantime. Now that it’s enabled I’ll see how it works in the real world. Maybe we’ll eventually get an option to adjust the delay between Motion & Motion Cleared.

#5

You can add &reset=1 to the URL to clear any previous triggers.

I used that web service for awhile but had to stop because of usage limits.

1 Like
#6

Thanks for the tip! Using &reset=1 does solve that problem. Do you know if the usage limits you ran into were imposed by the Webhooks service or the API? I’m curious if I’ll run into the same issue eventually.

Now that Stringify is no more I’m looking into some other methods of creating more complex actions like this (going to test out Apolio next).

#7

The usage limits came from IFTTT, and they do not email you or anything, you have to look in your activity log to find out why the process isn’t working.

I was using it to turn lights off after a time, but now the Tuya Smart Life system can do that on it’s own, so I don’t need the grapeot service any longer.

#8

I too have been searching for a way to perform more complex actions or base actions on multiple triggers since Stringify is shutting down for good in June.

So far apilio.io seems to be the most flexible replacement, but it’s not very intuitive. It’s transitioning from a personal side project to an actual company, so future direction is up in the air.

Home Assistant seems like a powerful and low-cost option, but has a significant learning curve and time investment to get basic functionality.

#9

Home Assistant looks incredible and has a great community around it. I just haven’t pulled the trigger yet as I’ll basically need to learn how to create a custom Pi3 hub and code it. Could be a fun project though.

#10

I am trying to understand what Webhooks actually is… i thought people were using IFTTT and Webhooks interchangeably, but now i am seeing they arent the same thing. What does webhooks do that IFTTT can not do on its own?

#11

I’m new to Webhooks as well so my explanation is probably an oversimplification, but it’s just another way for apps to talk to each other. It’s used extensively for web applications behind the scenes, but when it comes to IFTTT it’s mainly used to allow for more complex event triggering. IFTTT is actually pretty limited, and even by using their advanced Platform I couldn’t create something that functioned with a delay (like my motion sensor event). So people have created custom snippets of code that do advanced things that function as Webhooks. Basically IFTTT will send some info to a URL, a custom piece of code runs, and then new info is sent back to IFTTT. If you want to read a more thorough explanation check this link out.

#12

Thank you for helping me understand, but now i have more questions…
Can you give me an example of a situation where you intentionally want a delay? I read a lot of people complaining about delays and they arent even setup for an intentional delay. So what situation would you want a delay on purpose?

How do you write more code into an IFTTT??

#13

IFTTT custom Applet documentation

#14

In my experience, it’s much easier to use a platform that supports IFTTT natively, rather than trying to work around. That said, I haven’t tried Webhooks.

If you’re looking for lighting that supports IFTTT, I recently switched to Lutron Caseta from a combination of Insteon and TP-Link Kasa. So far, the Lutron Caseta products have worked flawlessly where I was having issues with the other 2 before. And bonus for those of us with no neutral wire, Lutron Caseta doesn’t require one for their dimming switches.

#15

I have motion detector switches in my offices that automatically turn on lights and off when there is no activity. My Wyze cam records movements.
What is the benefit of the method you have described that I don’t get with my set up?

#16

Hi @emailjd - The main benefit is that it’s wireless and I don’t have to install new motion detector switches. I’m an architect by trade and I use occupancy switches in projects all the time, but this acts as a remote sensor. It also works in an open space where there’s no good place to put wall mounted switches, or the switches wouldn’t have visibility of the area where motion is taking place. With this you can basically have the same functionality anywhere you can set the Wyze Motion Detector.

I like it because it’s very customizable. For example, I can have it turn off some lights instead of all the lights connected to the switch. I can have it just dim lights instead. I can have it turn off lights in a totally different area of the house (or close the garage door). I also like that it sends me a notification to let me know it ran… it’s also very cheap! Definitely easier to install and cheaper than new switches everywhere.

#17

I completely agree. All of my bulbs are linked to my Wink Hub which actually does support IFTTT but not for this particular action. I would love if Wyze supported this type of customization natively. While this solution is a bit DIY, I wouldn’t necessarily call it a workaround. Webhooks are natively supported by IFTTT and get used constantly by web apps and software - we just don’t see it as much on the frontend. Do the Lutron products support this kind of occupancy sensor action?

#18

So obviously a lot more flexibility. Makes sense. You could set it up so if someone is moving around outside it turns on the lights inside for example.

Thanks for explaining!

#19

Lutron Caseta Light and Shade products can be an IFTTT “That”. So for example, if Wyze Motion Sensor Clears, set Lutron Caseta light to Off. There are 3 options:
• Set light level (Off, 10%, 20%, etc)
• Set shade position (any position between and including Open and Close)
• Recall a scene

I’ll update when I get a chance to get my Wyze Motion Sensor and the Lutron Caseta switch installed where I intend to use those devices. Right now, I only have 1 Lutron Caseta plug-in lamp dimmer installed.