This project is about solving the problem of getting something started or turned off when you are a multiple hour drive away from the switch that does just that. Specifically this example will show how I made a remote switch to preheat a vacation property before we arrive so that my wonderful kids,
when arriving to this place past their bedtime,
at this time of year,
are not frozen when we put them to bed late at night.Problem
First thought would be to buy one of those wifi thermostats, however when things are baseboard electric and some of your thermostats are this old,
you have to do something a bit more custom.Overview
I am going to create a button that when pressed a single time will turn on the heat in our vacation home, and when double pressed/clicked, will turn off the heat at our vacation home. I will use a lovely Amazon IoT button to be our physical switch at our main home to tell our vacation spot that "we are coming!", AWS Lambda to convert the messages from the switch to send to the amazingly versatile Particle Photon to ultimately turn on some heating! ...or if we forget, turn off the heat to save the environment!Step 1
Determine if you have some thermostats that you can "short" / override easily by using a relay as a remote controlled switch. Often these types will look like the above and contain two wires (low voltage) which can be shorted to turn the heat on. WARNING: if you are not comfortable determining what type of set up you have get some professional help.
Step 2 - Acquire your tools
For this project, we are using an Amazon IoT Button,
a Particle Photon (wifi enabled arduino - like device) - with relay shield,
and your trusty shiny Amazon AWS account!Step 3 - Get your Photon Setup
After you receive the photon your purchased you can hook it up to your account.
There is an online code editing feature where you can update the code for the device without even having a computer attached to it, or be anywhere near it!
One should also install the command line tools to be able to list what devices you have attached, what state they are in and give you the ability to easily test / call remote functions on your photon device. Once installed, and you have logged in, you can test out the command by doing something like the following.
$ particle list wIRelayBoard [-----------] is online Variables: hstate (int32) Functions: int heat(String args) int readheat(String args)
Using the online editor add the attached code to the window and flash the remote device with the new instructions. Then when you run the above command again the output should be similar.
Your photon should have the right code to do the work now! Test it out by calling:
$ particle call <device_id> heat "on"
You should see a red light on relay 4 turn on if you copied the code exactly and used your device_id and access token.
Run the command again with "OFF" for arguments and you should see the light turn off.
Run a wire to each side of the mercury switch, control wires, or switch on the item you wish to control and hook them up to the NO (normally open) contacts on the relay board. Adjust the screws so that the wires will not come out.
Test your set up now by sending the command again from the command line to turn it on. See if your heat begins to turn on or your device begins to function.
You've successfully created a remote controlled switch. Now let's make it super easy to use and not require a command line interface.Step 4 - Create our Lambda Function
Amazon lambda, when it came out, seemed like the answer to so many problems that DID not require a server running 24x7 to process stochastic events that happen occasionally or at least on their own schedule. PERFECT for what we are trying to do.
With your existing, or newly created AWS account, navigate to the Lambda area and walk through the steps to create a new Lambda function.
I named mine heatControl, gave it a bit of a description so I'd remember what it should do, then edited the function, and pasted in the attached code replacing the appropriate device id and access code.
After saving this, test out the function to make sure that you've not introduced any mistakes.Step 5 - Set up the Button
If you are lucky, you will have, through some miracle acquired one of Amazon's IoT buttons and have already set it up. If not, you can try and state your case at their button website and hopefully they will send one to you. For this project I will assume that you can get your hands the button or create a similar button that can utilize the IoT infrastructure provided by Amazon.
Follow the instructions on the button site, and you should create something that looks like this:
I have already set up a custom action in the above image while testing that sends an email to my account when the button is pressed. Make sure that you are getting the email when the button is pressed before continuing on to hooking up the Lambda function. If you are having problems, search the IoT docs a bit and turn on logging and some other things to see if you can find out what may be going wrong. If you are using another "button" make sure again that you can get it to send you the email!
Add another action to the email rule to call the lambda function. Chose the name of the function that you just created. In my case I selected "heatControl" and saved.
If you've set things up properly and the button is working, when you click the button, the red light should eventually come on. Be patient the IoT button is very energy efficient! When clicked it powers up, connects to wifi, sends the data while the LED is blinking, and then turns itself off again.
Pressing the button twice or double clicking the button, should send a single that will, when done, turn off the relay, the red light, and your heat! Success!
You've created a button which you can take with you, hook up to the internet anywhere and turn on or off your heat, hottub, coffee machine, etc!! Have fun playing with the device, and the great Amazon and Particle resources to make IoT insanely powerful!
Be safe when switching larger voltage loads, inductive loads, and items you are not sure about. Good luck!