Introduction: WiFi Enabled Outlet With Optional Temperature Control Automation (TempBuddy Control)

Important Information:

This design is ideal for smaller space-heaters that don't draw many amps. While the Solid-state relay can handle more amps the design doesn't dissipate heat well enough for larger space heaters. Tried it on a larger one in my shed and eventually the box got too hot to touch and some of the internal plastic bits melted slightly.

They make heat-syncs for these solid-state relays when one wants to control more power, so I will be doing a new design of this device for higher amperage draws. When it is complete I will make a new instructable to showcase it, so check-back later to see the new design once it is done.


Backstory...

My bedroom is in the coldest room of the house. In the winter time if I set the heat so it is a decent temperature in my bedroom then the rest of the house is boiling hot. So, I decided some time ago to get a cheap space heater that I keep in my room. The only problem is, the space heater doesn't do a very good job a keeping the temperature a constant comfortable temperature. When I turn it on at night, I usually fall asleep and then wake up to it being super hot in my bedroom and have to turn it off and hope it cools down quickly so I can be comfortable enough to fall asleep again.

So, I came up with this device I like to call the "TempBuddy Control".

About the Device...

As, you may, or likely not know... I created an instructable in which I created a WiFi enabled thermometer that can be used to keep an eye on the temperature and humidity remotely via a self hosted web page that the device served up on the network it was attached to.

Link to that Instructable: https://www.instructables.com/WiFi-Enabled-TemperatureHumidity-Sensor-Using-ESP8/

Well, since I had already built a couple of those devices I figured that I would build a device that could use temperature information from one of those devices and use it to decide when to turn on and off an outlet that I could plug my space-heater into. That way this device can leverage the temperature information and the space-heater to maintain a comfortable temperature in my bedroom.

So, that is where this device came into being. Not only can this device be setup to get temp information from a TempBuddy device and use it to control an outlet but I decided to allow it to control either a device for heating like a space-heater or a cooling device like a fan or small air-conditioner. In addition to its ability to Automatically control the outlet the device is able to be placed into Manual mode so that a user can access its internally hosted web page and manually turn on or off the attached device remotely from the wireless network.


Important:To get the full benefit of this device's functionality you would also need to make the prior mentioned TempBuddy device. However you can use this device to manually control an outlet via the web interface without it.


Get device IP...

To find out what IP Address the device was assigned on your network you can briefly press the factory-reset button during normal operation and the device will flash out the last octet of the IP Address using an externally attached LED. If for some reason you aren't sure what the first 3 octets of the IP Address on the network it connected to are, then you can hold down the factory-reset button for more than 6 seconds and the device will flash out the entire IP Address.

You might me wondering how the IP Address is flashed out when you have an IP Address like 192.168.123.71...

Well, no... You don't have to count out 192 flashes, then 168 flashes, then 123 flashes, then 71... That would take forever and be hard to do or even tolerate. Instead, I wrote the code for the device so that it works as follows:

Each digit of each octet is flashed individually, there is a small rapid flash between each digit, there are 2 small rapid flashes between octets and when all octets have been flashed there is a long rapid flash to indicate this.

IP Signaling Example...

I will demonstrate how this works below by representing a single flash of the LED as a dash '-'. I will represent the post digit rapid flash with three asterisks '***', and finally I will represent the end of sequence's (end of IP) long flash using 10 asterisks '**********'.

Using the above the IP address of 192.168.123.71 would be flashed out as follows:

1 9 2 . 1 6 8 . 1 2 3 . 7 1

- *** - - - - - - - - - *** - - *** *** - *** - - - - - - *** - - - - - - - - *** *** - *** - - *** - - - *** *** - - - - - - - *** - **********

The short button press version of the above would simply be the last octet so in this case it would be:

7 1

- - - - - - - *** - **********

In the steps below I will walk you through how to create one of these devices.


Security Related:

Communication with this Device is NOT encrypted. This means that when configuring the settings of the device using the admin page, the data is transmitted to and from the client in clear text on the network you and the device are connected to. The potential for compromise is highest when doing initial settings with the device in AP mode as there is no password used for the TempBuddy network. Be cautious as this could result in the leaking of target network's SSID and Password when initially setup, also if changing the device's admin password don't use one that you use for other sensitive things as it will be sent to the device in clear text. I hope to one day add in SSL capabilities but haven't gotten around to it yet so it is what it is, which is still useful to me.

UPDATE: Version 5.2.1 of the firmware uses SSL to secure data between the device and client. Also it has improved authentication protecting the admin page. The latest firmware is available on my GitHub page here: https://github.com/birdoffire1549/TempBuddy_Control

Supplies

  • ESP8266MOD - ESP8266 ESP-12 ESP-12F NodeMcu Mini D1 Module
  • Solid State Relay - SSR-25 DA
  • 15A Electrical Outlet
  • Small single device USB Charger
  • LED
  • 1k Ohm Resistor
  • 10k Ohm Resistor
  • Small Push Button (Normally Open)
  • Small BreadBoard for Soldering
  • A Three Pronged Cord (Old Computer Cable or Extension Cord)
  • 3 Old 4-wire USB-A Cables; At least one of them with a USB-Micro connector.
  • USB-A Female plug-in port
  • 4" Galvanized Steel Square Electrical Box
  • 1-Gang Galvanized Steel 1" Raised 4" Square Electrical Box Mud Ring
  • Two 3/8" Non-Metallic (NM) Clamp Connectors
  • Outlet Cover
  • Gel Control Super Glue
  • Various colored solid core 22 gauge wire
  • Assorted sized Shrink Tubes
  • Solder
  • Soldering Iron
  • Hot Glue Gun
  • Electrical Tape

Step 1: Design the Circuit

Well, actually I started with building the prototype. I've never really been a by the book kind of guy when it comes to the idea of drawing out a circuit design before I build it. But for the sake of this instructable here is the circuit design.

In the design you can see that the ESP8266 is basically the brains of the device and it drives the LED indicator and Solid-State Relay as well as receives input from the attached Push Button and the USB Port. Basically all of the operational logic behind this circuit is derived from the software that runs the ESP8266 Device.

So let's talk about each of these components really quick.

S1) Reset/IP-Flash Button...

I added what I call, the Factory Reset/IP-Flash button. The purpose of this button is more complex than simply factory resetting the device. The idea is, that one holds down the Reset button while the device is unplugged, then plugs in the device while still holding the button. This will cause all of the device's settings to be erased and set back to a predetermined factory version of the settings. Also this button functions as a way to find out what the device's IP Address is without having the device hooked up to a computer and reading it over the serial interface. As such the Reset button is a multi-purpose button. It can be used to cause the device to "Flash out" the IP Address, as described in the Introduction section of this instructable. The Factory Reset button (S1) is used with a 10k Ohm resistor (R2) in such a way that the resistor pulls the input pin Low, and once the button is pressed then the input is pulled to High.

LED1) IP-Indicator LED...

The IP-Indicator LED is used as mentioned prior to "Flash out" the IP Address of the Device. As you can see from the diagram, it is connected to ground with a 1K Ohm resistor (R1) in series. The resistor is simply a current limiting resistor and the value of it is just my go-to value for such things.

U1) Solid-State Relay...

The solid-state relay (U1) is what allows the low-powered ESP to control the high-powered outlet. It is a fairly basic circuit component so there really isn't much I need to say about it. It hooks up directly to the ESP and then to ground.

Step 2: Build Prototype

The porto-board build was perhaps the most important part of the journey to the final device. This temporary device allowed me to play around with the device while I wrote the code, as well as it was super helpful in the debugging process of the code. The prototype is how I make sure everything is working the way I want it to and that the design is acceptable before I start soldering components. I have found that using a prototype really helps cut down on wasted components when I decide mid design that something needs to change.

Step 3: Write the Code

As always this is my favorite part of the design process. This is when I start to see the build function and the pieces really start to come together. I tend to use Arduino IDE for all of my code writing needs when it comes to micro-processors but that may change in the near future as I find it kinda limiting in some ways especially when it comes to creating and maintaining new custom library files. I feel I should be able to open and edit those files in the IDE without them being in my sketch folder but that is a No Go with Arduino IDE, but for now it is what I use.

I have basically attached all of the code files here from my project's sketch directory. Of course, as with all things Arduino IDE related the one with the '.ino' extension is the main file. I have also uploaded my code to my GitHub account and will keep the latest versions of the code out there for others to view, fork and download as needed.

This project's GitHub link is: https://github.com/birdoffire1549/TempBuddy/tree/main/TempBuddy_Control

It is important to note that my code relies on some common ESP8266 Libraries that can be added to the Arduino IDE as needed. Also, some of them come with the Board Install so make sure you use the Board Manager to install the 'esp8266 by ESP8266 Community' manager. Also, you can use the Library Manager to search for and install 'ESP_EEPROM by j-watson' library.

*UPDATE:* I discovered a bug in the original code which caused the Manual Controls to stop working when Auto Controls were disabled while the controlled device was on. I have since fixed that bug and updated the code on github as well as here.


Uploading the Sketch...

To upload the sketch within the Arduino IDE, plug in the ESP board into the USB port of your computer you are using the IDE on, and then once the IDE recognizes the connection to the device select the dropdown at the top of the IDE window and then click 'Select other board and port...'. From this screen you can seach for 'Generic ESP8266 Module' under boards and select it, then select the port under ports that the device is connected to. Next, click the OK button. Now you should be able to upload the sketch via the IDE to the ESP Module. Once the upload is complete you can open the serial monitor of the IDE and connect to the module using 115200 for the speed. You should see all kinds of logging from the device in the serial monitor telling you what the device is doing and whatnot. Maybe play around with the device while keeping it connected to serial and see all the different things that get logged out from the device.

FYI: I do plan on improving the logging for the device at some point, and when I do I will update this instructable to let you know that the update has been made.

Step 4: Configure the Device

Once the device is programmed and running for the first time, you should find that it transmits a WiFi network called 'TempBuddy_Ctrl'. You can connect to the network from a computer or smartphone without using a password. Just keep the password field blank. Once connected you may have to tell our phone or computer to stay connected to the network despite not having Internet access. Then open a web browser and navigate to http://192.168.4.1/admin. Once there you will see a page requesting a password. Simpy use the default password 'admin' and it should take you to the settings page. Once at the settings page you can configure the device to join a local WiFi network as well as make some other adjustments and customizations. Once you save the settings, if you updated the WiFi settings then the device will reboot and join the desired network. Give the device 5 to 10 seconds after reboot to join the network and then use the Reset button to either get the last octet of the IP Address it obtained using a quick press, or using a long press of 6 seconds or more you can obtain the full IP Address. Once you have the IP Address for the device, simply open a web-browser on any computer or smartphone on that network and type in the IP Address for the address and you should be greeted with the Information Page where the device's information is listed and there should be Manual Controls at the bottom of the page if not in Automatic mode, or special controls for Automatic Mode's temperature settings if in Automatic mode.

Step 5: Building the Final Version

Before attempting to assemble the final version of the device, try to place the components into the box and get a feel for how they will be arranged to fit properly so the box can be assembled with everything fitting.

Step 6: Add Cord to Case

As can be seen in the above image, the cord is cut and stripped back so that the individual wires are exposed. Pictured here are 3 wires as it is a 3 pronged plug. The green wire is attached to the ground prong. The brown wire was attached to the hot prong. The blue wire was attached to the neutral prong. I used a multimeter to ensure which wire was connected to which prong. It is important for the safety of those who may be exposed to the device during operation that the wires be determined and used correctly, some feel that hot and neutral are interchangeable but really it is unsafe to do so, for reasons that are beyond the scope of this tutorial. As you can see if you zoom in on the picture, the cord is secured to the box using one of the 3/8" Non-Metallic (NM) Clamp Connectors.

Step 7: Add Relay, Button, LED, ETC.

There is a lot going on in this step but it is actually pretty simple when I break it down.

The Reset Button...

In this picture the Reset button is seen attached to the side of the enclosure with yellow wires attached to it. First I soldered some yellow solid core 22 gauge wire to the leads of the switch and then put some yellow shrink-tube on the exposed portions of leads so that nothing would short out if it touched the metal box. The color of the wire really doesn't matter and neither does the color of the shrink tube, I simply chose yellow just because. Next I prepared the Push Button for glueing to the box. To do this I used a shrink tube that slightly fit over the part of the button that stuck out, then I shrank it to the button. Then I took another shrink tube of the same size and shrank it over the shrink tube I just attached to the button.

Why did I do that!?

Well, I did it because it helps to keep the Super Glue from running into the button and destroying it. Also, it gave me something protruding that I was able to clamp onto to keep the button snug against the side of the box while the glue dried. Speaking of Glueing... I really recommend using Gel Control, Super Glue as it isn't really runny and will better stay where you put it.

As for gluing the button to the box, you will notice that the box has two holes in each side towards the top. I simply used Super Glue (Gel Control) to glue the Push Button into one of the holes, attaching a clamp to the attached shrink tube to keep it snug against the box. Once the glue dried I simply pulled the shrink tube off the button giving it a tug. I like the way the button mounted here turned out as it sits recessed in the hole so it cannot be accidently pressed. Instead you have to use a pen or something to press it intentionally.

The LED...

I used Blue for the LED because I feel like it is a noticeable color and wouldn't be misconstrued as an alert or warning indicator. For mounting the LED I did drill out the hole just slightly larger, as I wanted the LED to stick out through the hole but did not want the rim around the base of the LED to come through the hole. This allows for a clamp to be used to hold the LED in place while the securing Super Glue (Gel Control) is drying. Before glueing the LED into place I soldered a red wire to the positive lead and a black wire to the negative lead and used colored shrink tube to cover the exposed metal portions of the leads to prevent shorting out. Then I glued the LED into place.

The Relay...

So I used something called Alien Tape to attach the relay to the bottom of the box but really any strong double sided tape could likely be used. Just make sure the High Voltage side of the Relay is facing the more open part of the box as it will need more room for the connecting wires and such.

Wiring up the Cord...

As you can see from the picture, I also wired up the cord to the USB Power Supply, Relay and Outlet. To wire up the cord I attached the brown (hot) wire to one of the terminals on the switching side of the relay, also connected to that same terminal is another piece of the Brown wire which connects to the smaller post of the USB Power Adapter. I soldered the wire to the post of the power adapter and placed some shrink tube on it to cover all the exposed metal to prevent shorts. Next I cut the Blue (neutral) wire and attached a bit of it to the remaining post on the USB Power Adapter and used some shrink tube to cover the exposed metal. Then I soldered the incoming blue wire to the blue wire that was attached to the USB Power Supply along with a third piece of blue wire and covered the connections with shrink tube. Finally I attached the other end of the additional piece of blue wire to the neutral side of the outlet. At this point the USB Power Supply is now connected to be powered up whenever the device is plugged in regardless of the relay's switched state. Now to connect the Black (sometimes hot) wire as shown in the picture. I used black wire because I ran out of the brown and black is normally used in house wiring scenarios to indicate the hot wire. One side of the black wire connects to the currently empty terminal on the switching side of the relay and then the other end of the wire attached directly to the hot side of the outlet. At this point to complete the high-voltage wiring only one more wire needs connected. The ground wire (Green) needs connected to the grounding terminal on the outlet. I would say to also connect it to the metal box too, but when the adapter plate for the outlet is attached and the outlet is mounted, ground will be electrically connected to the entirety of the box anyway.


Step 8: Attaching the ESP

Ok, at this point you will need to wire up and solder the wires for the Button, LED, and Low Power side of the Relay to the ESP. As you can see from the picture I used a small board to solder all of the connections to in order to connect everything to the ESP device. Once all the wires were soldered into place along with the needed Resistors, I then used Alien Tape to stick the board to the box next to the Relay and bent the wires such that they kept out of the way as much as possible and against the sides of the box.

Step 9: Connecting ESP to Power

In this step I actually modified a USB-A to USB-Micro charging cable to reduce its size by splicing out a length of the wire and soldering the wires inside back together, shrink tubing the whole thing to create a small USB Cable to plug the ESP into the USB Power Adapter. As you can see in the image with the ESP Plugged in the power adapter tucks away nicely into the box.

Please Note:As it stands the only way to update the software on the device is to open up the device and unplug the ESP from the Power Supply then plug in a cable from it to your computer to program and update the ESP. Maybe this is fine if you plan on just programming it once but it is too cumbersome for regular updates. I have since modified my version of the device to include a USB-A female port that I can use with a custom cable setup inside the device and a custom cable on the outside to plug my computer into for programming the device. It works really well and I will talk about how it did it at the end of this instructable.

Step 10: Electrical Tape and Close

It can't really be seen from this picture but I covered the exposed high voltage terminals of the relay with electrical tape and I wrapped the outlet terminals with electrical tape as well. Then I applied the 1 gang adapter cover for the box and attached the outlet. In the second picture you can see what the completed device looks like with the outlet cover added.

Step 11: The Later Added USB Port

Ok, so like I mentioned before, I ended up adding a USB port for programming the device without taking it apart. To do this I salvaged a Female USB-A port from an old device I had sitting around the house. This is when things got tricky and a little aggravating for a while. Turns out that Female USB-A ports are meant to be used on the Computer or Power supplying end of things. You see I figured I could use it on my device and then just use a USB-A to USB-C cable and connect the USB-C end of the cable into my computer and the USB-A Male end of the cable to my device. Nope!!! Turns out that's where things get complicated. Well, I liked the size of the USB-A Female Port and it fit nicely into the design of my device as you can see from the pictures above, so I wasn't willing to use something else so I made it work.

Long story short...

I had to build (splice together) a special cable that is USB-A Male on both ends. One end I can plug into my device, the other end I can either plug into a USB-A port on my computer or I can place a USB-C adapter on the end of the cable and then plug it into my computer's USB-C Port. This cable was made by cutting the micro ends off of two 4 wire USB-A to USB-Micro cables and then soldering the Red wires together, the Black wires together, the White wires together and the Green wires together. Then I finished the cable off with shrink tube to cover the splices.

Internal Mods for External USB Port...

In order for the USB port to be able to be used to program the ESP. I changed the design of the cable that runs from the USB Power Supply to the ESP such that the cable now looks like a 'Y'. One end of the new cable plugs into the USB Power Supply, another end plugs into the ESP Device and the 3rd end is connected to the USB-A Female port. I have attached a diagram of what this adaption looks like electrically. One important note is that, with this adaptation the TempBuddy Control Device must be plugged into a wall outlet while programming the device. The ESP will not be getting its power from the computer while programming.

Not sure if you will notice from the above pictures but, to mount the USB Port into the 3/8" Non-Metallic (NM) Clamp Connector I very lightly tighten the clamp on the port and then poured Hot Glue into the clamp around the port to completely secure the port into place. You need to make sure the wires are soldered to the back side of the port prior to glueing into place. Once the Hot Glue dries you can attach the clamp into one of the punch-outs on the box then after the port is attached to the box wire up the rest of the cable, or wire up the whole of the cable before attaching the clamp port to the box if you are sure you can fit the rest of the cable back through the hole of the box. That didn't work for me and I had to assemble the cable with the port already attached to the box.

Step 12: Lessons Learned

So what did I learn from this project?


USB-A to USB-C cables are not the same both directions...

So yah, turns out that USB-A to USB-C cables will only work if the A end is attached to a computer or power supply and the C end is attached to the device. Gets even more interesting if you place a USB-C adapter on the A end of the cable and try to use it between a computer and device. It will work in one direction but not the other. Turns out USB-C is far more electrically complicated that I thought they were and there are loading resistors that must be present to enable different kinds/directions of communication.

Arduino IDE doesn't support custom libraries well...

This is just something that annoyed me that I ran into. If you want to create a custom library for use with Arduino IDE, you can copy the files into the library folder within the workspace but once there you cannot edit the library files within the IDE. Unless you pull them back into your sketch folder. I thought I had found a way around that by creating linking the files into the sketch location but then the IDE did something unexpected and decided to satisfy all of my import statements in the library code with libraries from various places in my computer system that weren't compatible with the device I was working on and I couldn't figure out how to stop that so I just put the custom library files back into my sketch folder.

WiFi Signal Strength...

Well, actually this isn't something I learned as I already knew it, but did observe it with this project so it is worth mentioning. Yes, it is true that metal boxes cut down on the WiFi signal strength of the devices inside them. I do most of my project building outside the house in a shed that is in the backyard, and typically with these ESP devices I can reach the wireless in the house just fine. With this project though I needed to connect to the shed's WiFi when I was out there working on things and then connect to the House WiFi when I was in there. Even though the metal case did cut down the signal some, it really wasn't that big of a difference and was by no means a deal breaker for me on this project.

Step 13: That's All

Well, that is all I got for this instructable. If you stuck with me until the end, thanks a lot and I really hope you enjoyed it and found at least parts of it useful and informational.