JulianHartline.com Rotating Header Image

Remote control hot tub

If you’ve ever owned a hot tub, you’ve surely been driving home from a long day or night wishing that the hot tub would be ready for you when you got home. I decided to do something about this.

Because we’re renting, I decided that instead of trying to pull apart the wall unit for controlling the hot tub, I’d go with the more mundane approach of wiring up a servo to push the hot tub button on command. I chose the Electric Imp as my platform primarily because I’ve been experimenting with it recently for another project that I’m working on. Having worked only with PIC microprocessors before, I found the Electric Imp to be surprisingly intuitive and easy to set up and  use. Instead of spending hours tinkering with a breadboard full of wires and a resistor or two, the Electric Imp fits easily into a development board, can be powered by a mini-USB cable, and configures itself to your home WiFi network without too much difficulty through a mobile app.

The Electric Imp, once connected to your wireless network, is accessible via the Electric Imp web application that allows you to track all of your devices and upload code to each one of them as well as configure the way that they interact with each other.

Once getting past some of the initial setup woes inherent in every tinkering project, the programming and wiring was very simple.

2013-06-19 23.15.49

The servo is attached to the wall unit using mounting tape. Glued to the servo is a piece of chopstick to extend the reach of the arm so that it is able to press the button. The green wires are connected to a photoresistor that is positioned over the “heater” indicator LED. This allows us to keep track of whether the hot tub is on or off and display the status to the user.

You can see clearly on the right hand side the Electric Imp and the power supply. On the left are a few unused components that just happen to be sitting on my breadboard. (related to the aforementioned “other” project)

// These are used for the "tapping" of the button
// The servo normally sits in the "up" position.
// When hot tub is to be toggled, we switch to the "down" position
// wait for the delay, and then return to the up position
const up = 0.0634;
const down = 0.047;
const delay = 0.2;

// We use this output to reflect whether the hot tub is on or off (based on the photoresistor)
local tub_status = OutputPort("hot_tub_status");

// The servo
hardware.pin9.configure(PWM_OUT, 0.025, up);

// The photoresistor

// This is the toggle button for the hot tub
class servo extends InputPort {
 name = "Toggle Hot tub"
 type = "number"

 function set(value) {
 // We ignore the value sent, and simply set the servo position, wait the delay and then reset
 imp.wakeup(delay, resetPosition);

 function resetPosition() {

// This function runs every second to update the status of the hot tub.
function checkStatus() {
 local value = hardware.pin8.read();
 local hotTubStatus = value > 6000;

 //server.log(format("value: %.2f", value));

imp.configure("Hot Tub Controller", [servo()], [tub_status]);


The code is pretty simple. The two main components are the servo control and the photosensor status updates. Electric Imp makes it extremely easy to monitor analog inputs and generate the pulse width modulation that the servo needs.

To push the button, we simply wait for the input signal (which comes from HTTP as we’ll see soon) and tap the button using the servo when we get one. The tap is simply done by twitching the servo, waiting for it to complete its movement, and then twitching it back. It took a bit of tweaking to get these values correct. You’ll also notice that when we initialize the input, we use the default position “up.”

The final component is the photoresistor. The code is simply checking the photoresistor every second and using a constant threshold of 6000 to determine whether the light is on or not. This was pretty easy to come up with, though I will note that testing with the lights both on and off and using a piece of black electrical tape to block the light both helped.


The Electric Imp uses a rather jenky “Planner” interface to keep track of your Imps and wire up their inputs and outputs. While I definitely see the value in being able to rewire your imps in different ways while leaving the firmware as a consistent driver for each module, the programmer in me was not enthralled by the somewhat buggy drag and drop interface.

You can see in this image that the input is an HTTP module which provides a URL that responds to post requests. In this case the value of the POST request is ignored. Every time a POST request is successfully made, we execute the hot tub toggle code.

The output is for tracking the status LED. This was a bit more tricky. The way they have this set up is that the Imp will make a POST request with the data that it gets from your output port. In this case we send either a true or a false. I’ve configured this so that it hits my website with the status update every second. This status is then stored and provided to users visiting the web interface.


2013-06-19 23.14.51

I quickly threw together a mobile interface using Twitter’s Bootstrap framework (for the button style). Hitting the button will make a POST request to the Imp. The status is polled every second using Javascript from the status stored on the website. A separate mechanism receives the Imp’s POST request to the server to update that state.

This project was surprisingly easy to throw together. The Electric Imp is a pretty remarkable platform that allows for a lot of power with a very low learning curve. The Imp seems to be a pretty new piece of technology and the interface is still a bit rough around the edges and there seemed to be no semblance of security on controlling your Imp through HTTP. I would definitely not recommend this as an option to control your door locks, for example.


Comments are closed.