Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ndguardian/130a68bb298f817f85a1cb5664483062 to your computer and use it in GitHub Desktop.
Save ndguardian/130a68bb298f817f85a1cb5664483062 to your computer and use it in GitHub Desktop.
IFTTT Geofencing for Wyze Cam
Alright, got this written up. Hopefully this helps! If something is wrong or you have any questions, let me know.
It`s 1AM here so I kept it brief near the end, but I can add more details as needed later. I need to get to bed.
To create a geofence using IFTTT, there are a few things you will need. You will need a Google Sheet per person, a Google App Script and an IFTTT Pro subscription. Everyone using the geofence will need the IFTTT app installed on their phone to update accordingly.
One person, presumably the person who will “own” the geofence, will need to make a Google Sheet. In column A, you will put the name of the person a value will correspond with. Start with row 1. Put the owner’s name. In column B, put the value of TRUE or FALSE. This will be updated later by IFTTT.
In column D, row 1, put something like “Anyone Home?” - This is just to let you know what the value in Column E represents.
In column E, row 1, put the following function:
=OR(B:B)
This will check if any value in column B equals TRUE.
Every other person who is part of the geofence will need to create a separate Google Sheet (annoying, I know). In A1, that person should go ahead and set the value to TRUE or FALSE. Doesn’t matter which one right now, as it will also be updated by IFTTT. Then share the sheet with the geofence owner.
For each person, in the owner’s sheet in column A put the name of the person, and for column B, put the following function, replacing [URL] with the URL for the shared sheet.
=IMPORTRANGE(“[URL]”, “A1")
Upon entering the function and pressing enter, the value should resolve to the value from the shared spreadsheet. At this point, you are done with the owner’s sheet itself, but don’t navigate away from the spreadsheet itself yet. You have one more thing to do, which is to set up the Google App Script.
You see, by default the IMPORTRANGE function in Google Sheets only updates when the spreadsheet is open in a browser or app. This is not good for automation tasks, so we need to force refresh the spreadsheet. On the Google Sheets page, click Tools > Script Editor. This will create a Google App Script linked to the owner’s Google Sheet. For the code, enter the following below.
function refresh() { SpreadsheetApp.flush()}
And then click Save. In the upper right hand corner, click the blue Deploy button.
On the left side of the screen, click the clock icon, and then click the Add Trigger button in the lower right hand corner. You should now have a prompt for your trigger. For the following options, set the values below.
Function to run: refresh
Which deployment should run: Head
Event source: Time-driven
Type of time based trigger: Minutes timer
Select minute interval: Every 5 minutes (can tweak as needed)
Click Save
You are now done with the spreadsheet portion. For the future, you will only need to have new people create a new sheet, share it and add a new row in for the person in question.
Now to IFTTT. If the owner doesn’t have a pro subscription, you will need it now.
You will need to create two applets via a web browser.
Create two applets as described below. Let’s start with the function to turn the camera off.
For the IF section, select Google Sheets. If you haven’t already, you should be prompted to connect to your Google Account. Go ahead and do this.
Select the option under Google Sheets for “Cell updated in spreadsheet.”In the URL section, enter the URL for the primary spreadsheet with everyone’s records. In which cell to monitor, enter E1.
For the “Then that” section select the Wyze service. If you haven’t done so already, link the Wyze service. Then select the “Turn off device” section, and select the device in question. In my case, a Wyze cam. Then add the action.
You will need to add a filter code section, and include the following code in it.
if(GoogleSheets.cellUpdatedInSpreadsheet.Value.toLowerCase() === `false`){ Wyzecam.turnOffDevice.skip();}
Then save. Repeat the same process for turning the camera on, with two major differences. Instead of using the turn off device option, use the turn on device option. And instead of the code above, use this code.
if(GoogleSheets.cellUpdatedInSpreadsheet.Value.toLowerCase() === `true`){ Wyzecam.turnOffDevice.skip();}
Now you are done with IFTTT in the browser. Get the IFTTT app installed on your phone and wrap this up. These steps are slightly different between iOS and Android, based on my own experience. With Android, location-based applets tend to be unreliable so we go based off of wifi connections at home, while with iOS location is reliable but wifi is not an option.
Additionally, the steps are slightly different with the owner vs shared spreadsheets, but only in the cell referenced. Shared spreadsheets will use the cell A1 while the primary spreadsheet will use the cell B1.
For each person in their IFTTT app, they will need two applets. One will be to update their spreadsheet when they leave home, and the other to update the spreadsheet when the return home.
For the first one, create a new applet, using the appropriate “if” option as mentioned above. If using WiFi as the trigger, enter the name of your WiFi connection. If using location, set the location for home. For arriving at home, use connect to wifi or entered a location, and the opposite for leaving home.
For the “then” option, select Google Sheets, and then select “Update Cell in Spreadsheet”, linking the appropriate Google account if needed.
Set the drive folder path if the spreadsheet is located in a folder in Drive. If it is not located in a folder, leave this blank. Set the spreadsheet name for the spreadsheet, matching case. For the cell, select the cell per my comment above.
Assuming the first applet is to mark that you are away, set the Value option to FALSE.
For the second applet, repeat the same steps, setting the Value option to TRUE.
Do that on each device, and you should be done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment