IMPORTANT NOTICE:

Welcome to Part 4B of my ongoing saga of installing a home camera system in my place of residence. This is a continuation of Part 4A about adding a toggle switch to my cameras, well one in particular. Basically, I have a camera inside my house, and I’d like to be able to turn it off when I want to as I don’t need to it record when I am home, not just a privacy aspect of things but rather it’s wasted resources.

UPDATE(12/03/2017): 

This hack is no longer working on my system. I may have borked the server or Amazon may have done something to disable this hack. I haven’t been able to really go through and see what’s wrong on my end as it still may work for you or some. I have currently switched to using a Google Home Mini to toggle my recording switch and will explain how to do so with an upcoming blog post.

How-to add a toggle switch for a camera while using Xeoma:

Tools:

  • 2 Amazon Dash Buttons
  • IFTTT (If This Then That) – Webhooks 
  • Xeoma – You might be able to do this on other security camera software, but I’m using this, thus you get instructions to use this. I’m not going to go over how to install Xeoma, but you can start here to learn.
  • Linux server – I’m using a linux server for this, so once again you will get instructions here for this on Linux.

Step 1:

Purchase 2 Amazon Dash Buttons from Amazon. I’d recommend two different ones so you can tell them apart better so you know which one turns it on and which one turns it off. I suppose you can label them, but just buy two different ones as it’s easier. I decided to go with a Wonderful Pistachio Button for my “OFF” button and a Barnana Button for my “ON” button which I explain the reasons for in Part 4A. BTW I didn’t like the Barnana product, but the pistachios I loved.

Step 2:

I’m skipping the IFTTT step for now but will return to that in Step 3 as I’m going to first go over the Xeoma aspect of this sub-project. Hopefully, you have a running Xeoma server that is running great and you can move on to doing more fun things like this. But anyways, you are going to go to your modules  and add a HTML Switcher Module.

I placed mine in front of the archive. You can still view the camera, but it will not record the camera. Though, I probably should place it earlier in the chain to ease my server load some. Though, it’s currently on my backdoor camera as a test as I have yet to install my living room camera which I just received from China.

Next thing you need to do is configure the HTML Switch and write down the URL to turn it ON or OFF. Ok maybe you do not need to write it down, but you can come back to it later and copy and paste it by computer. But first, let’s configure the HTML Switcher module. Once, you add it to your chain, you are going to open it up for its settings. It’s going to have options like what port it’s listening on and the URLs to listen for. I’m just going to focus on the URLs. I’m going to ignore the first 3 boxes for now which is the “URL for Deactivation/for switching On/for Switching Off”. The next boxes are the important ones which will change the URL I ignored above. You do not need to change these, but I would highly recommend doing so for security sake as you should not leave these as defaults. I will say one thing about the URLs though. I didn’t need to change ‘Localhost’ to an ip address of my server as the Xeoma server is talking on the localhost. Not all installations are the same, so you might have different results. But,what you should change is the “URL-Path to Deactivate/Switch Off/Switch On…”  Like I said, you don’t need to, but you should change them to something less defaulty like maybe “Xeoma_is_good_On” “Xeoma_is_good_Off”, ect. It really could be almost anything, but treat it as a “passphrase” that only you and your trusted associates know.

TL;DR Steps:

  1. Add HTML Switcher to Camera
  2. Place it in Camera Chain
  3. Edit Config – URL-Path to Deactivate/Switch Off/Switch On…

Step 3:

Now, you need to set up a IFTTT Webhooks service over at IFTTT. I’m going to assume that you already have an IFTTT account or will make one if you don’t. But first, look for you username and click to bring down the little menu which you should find the link “New Applet.” Click that to make a new applet and then click on the big blue “+IF” link. Search for service “Webhooks” either using the search box or scrolling down until you see it. I recommend just using the search box. Then when you get to WebHooks, choose the one and only Trigger option you have which is “Receive a web request.” You need to name the trigger, which I used “phone” for my “OFF” button trigger and “phone2” for my “ON” trigger button, but it could be anything that you can remember or makes sense for this project, which might be “camera_off” and “camera_on.”. After that, you need to finish the Then statement by clicking on the big “+ That” link. Once again, search for Webhooks and choose “Make a web request.” At this point, you can go back to Xeoma and look at the HTML Switcher module and get one of the URLs to switch on/off the camera. It doesn’t matter which one you grab first, but copy (ctrl+c) the url to paste (ctrl+v) it into the URL box over at IFTTT in the configuration of your applet. Next option, I kept Method as “Get” and set Content Type  as “application/JSON.” Afterwards, you can click on “Create Action” which then allows you the option to have notifications sent to you each time the IFTTT applet has ran. For testing, I’d leave it off, but will go back after you know it works to yes.

Now, you only need to repeat those steps to make an IFTTT applet for the other switch, which in this case if you go by the picture above would be an “On” switch.

Note: The URL you supply in IFTTT needs to be accessed over the internet. “localhost” will not work but you IP or domain set to forward to your ip will. You might have to edit your router settings to allow the connection.

TL;DR Steps:

  1. Go to ifttt.com
  2. Create New Applet
  3. Click “+ IF” and search for “Webhooks”
  4. Choose “Trigger” option for “Receive a Web Request”
  5. Name your Trigger
  6. Click “+That” and search for “WebHooks”
  7. Click “Make a Web Request”
  8. Goto Xeoma and the HTML Switcher module for the camera you want to control.
  9. Copy URL of switch action(On or Off) and paste it at IFTTT under URL for making web request
  10. Change “Content Type” to “application/json”
  11. Repeat for other switch action(On or Off)

Step 4:

This is perhaps the more difficult and trickiest portion to this project. I had trouble here as I had to change other people’s code into my own to suit my needs. I did find one over at aaronbell.com who got his inspiration from another blog from Ted Benson. I will try to walk you through this the best that I can, but you can probably reference either one of those 2 blogs if you get lost here.

First, we need to setup the Dash buttons to connect to your wifi router. Follow the steps from Amazon located here  until Step #8(#8 will be last step you complete) which at that point just close your app. If you continue beyond that, you will order something each time you toggle your camera which you might not like. Note: You can complete the setup fully and order once through the button to get you $5 Amazon credit. Just make sure to reset your device  and then follow the activation steps again up to #8 which then you’d close your app to stop the process there. I’d also recommend turning off Dash Button Notifications on your phone app otherwise Amazon will bug you to complete the process each time you toggle your camera. On Android, open your Amazon app, then goto “Settings > Notifications” and turn off the one for “Dash Button Updates.”

TL;DR Steps:

  1. Buy 2 Amazon Dash Buttons.
  2. Follow steps from Amazon to set it up via phone app.
  3. Stop after Step #8 and close Amazon App and close the app.
  4. Repeat process for other button.

IMPORTANT NOTE: Make sure you have stopped the setup of your Amazon Dash Buttons after Step 8, otherwise your button will order stuff for you as well. If this happens Reset your Amazon Dash button and start the process over and stop after you do Step 8 and close the app. Note: I did fully setup both of my dash buttons, ordered an item and then reset the buttons and set it up properly.

Step 4b:

Here is where the real fun begins. First for the script/program/app to work, we need to find the MAC addresses for the buttons. I used the python scripts that I based the script I modified to use for my purpose to find the MAC addresses for my buttons.

To find it you just run the script, and let it run for a little bit as it should find some other devices on your network, and then you press the button and a new device should appear where you exit(ctrl+c) out of the script so you can copy the MAC address which you should copy somewhere so you can add it to the real script later on.

You can name the script what you want. I named it test.py but it really doesn’t matter as long as you remember what it does, so easier names like macsearch.py work better than test.py. In my example, I let it run and I recognize most of my IPs and when I pressed the button I noticed the new one ending in .135 which most likely was what I was looking for. Copy the mac and place it somewhere for safe keeping as you’d need it later. Also, repeat it for both buttons.

After you get the MAC addresses of your buttons, you can move on to editing the script so it works with your buttons.

You can copy the above python script, however you will need to edit the configuration to suit your system. Items framed with “##” need to be changed for your use. Make sure to remove the ##’s as well.

Items to change:

  1. ##YOUR_IFTTT_KEY## –> to your IFTTT Webhooks key found here.
  2. ##OFF_BUTTON_MAC_address## –> MAC address to the Button you want to use as OFF button
  3. ##ON_BUTTON_MAC_address## –> MAC address to the Button you want to use as ON button
  4. ##YOUR_OFF_TRIGGER_NAME## –> Name you gave your “Off Button” Trigger on IFTTT
  5. ##YOUR_ON_TRIGGER_NAME## –> Name you gave your “On Button” Trigger on IFTTT
Where to find your IFTTT Key

That should complete setting up the script for your usage and you can keep everything else the same. You can change some stuff, but it’s really unneeded. Stuff like “poop” and “pee” could have been changed as that’s a remnant from Aaron Bell’s version of the script, I just kept it the same in my modified version for my use.

At this point, you can test the script and see if it works.

This is what you see when you hit the ON button.

As you can see by the picture, I run this on my OpenWRT that I route my cameras through. You don’t need to run it on your router, but I believe it does have to at least be on the same network. It does work on my server that is connected to the same OpenWRT router. One final though here is to make sure to check both buttons. Keep in mind that the script catches the button multiple times on my server and I have yet to figure a way around that, but beyond sending multiple requests to IFTTT and your server, it’s pretty harmless unless you select the “receive notification each time this applet runs” option then it becomes annoying. If anyone knows how to fix this, please let me know.

TL;DR Steps:

  1. Make and run Python script to find MAC addresses of your Dash Buttons
  2. Copy MAC addresses for later use.
  3. Make script to actually send web requests to IFTTT with your own settings.
  4. Test Script.
  5. Fix script if needed.

Step 4c:

Once you have a working script, it is time to get things running smoothly on your server as this script should be running in the background 24/7 or at least whenever you want to toggle your cameras off or on. When following the next instructions, keep in mind that to run the script that python might need to be ran as root. Your configuration might be different and will need to be adjusted to your needs.

I have my script(cameratoggle.py) in its own directory were it sits until it is called about. /root/dash/cameratoggle.py which will be called upon by the following bash scripts that are in my /root dir.

Output of running tcheck

Create those two bash scripts and make sure they are capable of being ran properly and then the next step is to add an entry to your crontab to run tcheck(or whatever you want to call it) every so often to make sure the process stays open.

TL;DR Steps:

  1. Create and modify to your needs a Bash script to run the Python script.
  2. Create and modify to your needs a Bash script to check if Python script is running and run it if it’s not.
  3.  Edit Crontab to call on Bash script that checks to see if Python script is running.

If I explained everything correctly, you did everything correctly, and if the moons and the stars are aligned correctly, you should have two fully functioning Amazon Dash Buttons that turn the recording on one of your cameras off or on.

If you have any questions, suggestions, or want to point out any errors or fixes, please let me know in the comments below. Thank you.