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

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!

10 Likes

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?

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

4 Likes

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.

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.

2 Likes

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).

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.

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.

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.

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?

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.

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??

IFTTT custom Applet documentation

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.

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?

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.

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?

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!

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.

I used the instructions here to set up a motion sensor in my living room to increase the set temperature on a smart thermostat when it detects motion ( living room is occupied) and decrease the temperature in a bedroom (person has woken up and gone to living room). When there is no motion for 15 minutes it will lower the temperature (living room is empty).

I then used the instructions in this link: How to Allow IFTTT Applets Only to Run at Certain Times | Smart Home Solver

to have the applets active only during certain times in the day (say 8am-5pm).

everything seems to be working as it should but the only issue I see is that it can be kind of spammy as the motion sensor resets after no motion for 40 seconds and worst case is every 40 seconds there could be multiple IFTTT triggers firing. I was just curious if anyone had found a more efficient method? Not necessarily limited to just thermostats. Having non wyze brand smart bulbs functioning in a similar manner would be analogous.

I think multiple preset IFTTT Wyze triggers for motion sensor has become clear for x minutes could be useful.

i.e. something like preset triggers for 5, 10, 15, 30, 60 minutes after motion is cleared.