Monitoring Your Smart Home with InfluxDB and IFTTT

Navigate to:

Do you have smart and IoT home devices switches, video cameras, doorbells, alarm systems or appliances? Do you want to monitor and send events from these devices to InfluxDB with zero coding? With IFTTT Webhooks, you can!

Let’s dive in.

What is IFTTT?

IFTTT stands for “If This, Then That.” it’s a cloud service that allows you to connect IoT devices and services. It’s an incredibly powerful service that can help you automate your smart home.

Do more with the things you love

I’ve used IFTTT to:

  • Open my garage door when I get close to home
  • Turn on lights in my home with motion detection
  • Send my phone a notification when I’ve left the fridge door open too long
  • Start video camera recording when my home alarm is triggered.

However, what if I want to do more things like:

  • Keep track of all the motion and sound events from my cameras
  • Or log fridge temperature over time
  • Learn which lights are left on the longest
  • Track how often the temperature in my home fluctuates

How do I do all these? That’s where InfluxDB comes in.

What is InfluxDB?

InfluxDB is a time-series database that allows you to track metrics and events from devices and services over time. InfluxDB accepts data in the form of Line Protocol. It’s built to scale and stream data from all your devices. InfluxDB is an open source project. However, it also offers a free cloud service which I’m using for this exercise.

More than monitoring motion and sound events from the Wyze Camera

The Wyze app lets me see my Wyze cams’ motion and sound events. But it doesn’t provide a way to combine the data and answer how often my cameras capture motion events each minute. To solve this, I will use IFTTT + InfluxDB integration for my Wyze cams.

The best part is that this integration requires no code! Here’s how it works.

Creating an IFTT and InfluxDB integration

First, make an IFTTT and InfluxDB Cloud accounts. Both are free!

Once you’ve done that, go into your IFTTT account and “Connect” Wyze.

Next, login to your InfluxDB Cloud account and create a bucket. A “bucket” is where you’ll store your time series data. You can create a bucket by visiting the Load Data page and selecting the Buckets tab. Name this bucket whatever you’d like. I called mine “wyze”.

While you’re on this page, click the “API Tokens” tab. Create a new “read/write” token with write permissions to your newly created bucket. This token will give IFTTT permission to write to your InfluxDB bucket.

Generate Read-Write API token

After you’ve created your new token, copy that token to your clipboard.

Finally, you’ll need to find your InfluxDB Organization ID. Click the initial icon on the nav bar and select About.

Find your InfluxDB Organization ID

You’ll find your Organization ID on this page. Copy that somewhere as well, so you can reference it later.

Creating an IFTTT integration

Alright, now the fun begins! Go back to IFTTT log in.

Click the Create button in the top right corner. You’ll then be presented with the “If this…”, “…then that” screen.

Click “If this…” and then search for the Wyze service.

Create your own - if this - then that

You’ll be presented with events you can subscribe to. In our case, we’re interested in the motion events from the cameras.

Select Motion detected and then choose Any camera in the dropdown.

After clicking Create Trigger, you should see this screen. This means half your job is done!

Create Trigger

And now, you guessed it, click the …Then that button!

Making a Webhook web request

Now search for Webhooks, and choose Make a web request. You should end up on a bright blue screen that looks like this:

Make a web request

Here’s what we’re going to write in each field:

  • URL: This will depend on which InfluxDB region you signed up for. You can find out out by copying the domain from your browser’s address bar after logging into InfluxDB Cloud. In my case, my region is https://us-west-2-1.aws.cloud2.influxdata.com/. After finding your region, append “/api/v2/write?orgID=[[your org id]]&bucket=[[your bucket name]]” to the URL
  • Method: Select “POST”
  • Content type: Select “text/plain”
  • Additional headers: Type “Authorization: Token [[your InfluxDB API token]]”

Body: Type activity,type=motion message=”{{MotionDetected}}”. The and escape the messages so the double quotes are passed through correctly.IFTTT will make an API request to InfluxDB Cloud using your API Token for authorization.

In the body of the request, you’re sending some very basic Line Protocol. You’re setting “activity” as the measurement, the value “motion” to the field “type”, and you’re creating the tag “message” with the value of whatever comes from your Wyze camera. In this case, it’ll be the message “Motion detected on [[camera name]]”. because there is no timestamp in this line protocol, InfluxDB will automatically attach the current time when it receives your message.

Smash that save button! You’re done! Do a happy dance in front of your Wyze cam to start sending those motion events to InfluxDB.

sending motion events to InfluxDB

After you’ve collected some motion events, you can log back into InfluxDB to start analyzing. I’m going to create a Notebook in InfluxDB to explore this data. You can do the same by selecting the “Notebooks” option from the nav tree.

InfluxDb will present you with the query builder and a couple of visualization panels below with a new Notebook.

Select your bucket and the measurement “activity” in the query builder.

Next, click the Run button at the top of the Notebook to run the query.

Build a Query

You should see some data.

Validate the Data

Writing a Flux query for motion events

I have two cameras: Door Cam and Pan Cam. I’d like to know which receives more motion events every 10 minutes. Here’s a Flux query I wrote that can help us visualize that:

import "strings"
from(bucket: "wyze")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "activity")
|> filter(fn: (r) => strings.containsStr(v: r["_value"], substr: "Door Cam"))
|> aggregateWindow(every: 10m, fn: count, createEmpty: false)
|> yield(name: "count")

This Flux query finds all the events where the message “Motion detected on Door Cam” appears and compiles those events over a 10-minute window by counting the number of events that happened in that 10 minutes.

Adding Flux query into your Notebook

You can add this query into your Notebook by clicking the + button at the bottom and selecting Script. Then, paste the query.

Next, click the + button again and select “Graph”.

Finally, click the Run button to rerun the whole Notebook again. You should see a visualization.

If you don’t, make sure to check your time window at the top right of the Notebook — I have mine set to “Past 24 hours”. My visualization looks like this:

Door Cam activity

The Door Cam sees at most two motion events every 10 minutes. If I repeat the same process and produce another visualization for the Pan Cam, it looks very similar. It seems more often than not, both cameras detect the same events. I should probably check to make sure there isn’t any overlap in their visible field.

check there is not any overlap in their visible field

And that’s it!

I’ll leave you with a challenge: repeat this exercise but also capture the “Sound detected” events from your Wyze cameras! You should be able to overlap both the motion and sound data in a visualization. You’ll see how often your cameras hear something when they also see something. Here’s a sneak peak of what that looks like for me from both of my cameras combined:

both cameras combined

Try it out yourself

The integration with Wyze demonstrated here is one of many potential integrations you can create with IFTTT and InfluxDB! IFTTT has other IFTTT services with hundreds of devices and services. ou can send data from any of them into InfluxDB using the IFTTT Webhooks as described above.

Share your smart home projects with me by joining the InfluxDB Community Slack. I’d love to see how you’re using IFTTT and InfluxDB to monitor your smart home

FAQ

Does IFTTT work with Wyze?

Yes, Wyze works with IFTTT. All you need to do is go to the IFTTT app on your phone or through your desktop and search for WYZE. Once there, you can use any of the many applets Wyze has.

How do I add Wyze to IFTTT?

To start using IFTTT, you must first create an account. You can download the IFTTT app in Google Play or the App Store. Follow the prompts to make a user account.

To link your Wyze account in IFTTT, search for Wyze. Press Connect. It will ask you to log in to your Wyze Account.

The Wyze Applet:
Once you have an account in IFTT and have it connected to the Wyze App, you can start to work with the Wyze applets. You can get your feet wet, and try one applet to get comfortable. You can also search applets here.

Is Wyze owned by Amazon?

No, Amazon doesn’t own it. Wyze Labs, Inc. and all its related marks and logos, is a U.S. company based in Seattle, Washington. It was formed by four former Amazon employees – Yun Zhang, Dongsheng Song, Elana Fishman, and Dave Crosby.

Can Wyze trigger Alexa?

Alexa (in Amazon echo devices) and related logos are trademarks of amazon.com inc. Wyze can trigger Alexa, but you’ll have to use the Voice Monkey Skill in Your Alexa App to make this happen. Click on this link for a tutorial.