Software apps and online services
Hand tools and fabrication machines
Hello. Let's start with some safety!
To do this project, you must be familiar with electronic circuits and safety practices. You are dealing with main line AC power indirectly. If you are unsure, you shouldn't be messing with this. The risk of fire is real from improper wiring/soldering as with most projects. Please, be safe!
So the story starts by me shopping at Lowes for a new bathroom light and ran across a GE smart outlet that was marked down from $30 to $13 so I decided to buy it. Got home, installed the app, got it setup just fine. Well the myTouchSmart app isn't the best in my opinion. It works but now I need to use this app to control one device? Maybe HomeKit since most my devices are controlled by that... nope, doesn't support it. Hmmmm...
So I decided to open it up and see the setup inside thinking maybe I can flash new firmware or something. It uses a TA triangular bit for the screws and luckily I had one. First time I used it I think! Got it open and sure enough there was a wifi chip soldered on the board. After some googling the model & such, there is a way to the flash firmware but it was in Chinese and I don't speak Chinese... and looked overly complicated and proprietary. I did manage to find a pinout of just the chip which helped with the 3.3v and ground. The chip runs on 3.3v & being fed 3.3v so that is perfect for the ESP8285. So I decided "ok maybe something hardware..."
- DO NOT OPEN THE OUTLET WHILE IT IS PLUGGED IN. I CANT EMPHASIZE THIS ENOUGH!
- DO NOT PLUG IT IN WITHOUT IT COMPLETELY CLOSED/ASSEMBLED!
- WAIT A COUPLE MIN AFTER YOU UNPLUG IT FOR THE POWER TO DRAIN.
I removed the case & internal board and there looked like there was enough space behind where the existing chip is. Great!Software Setup
I did the software part first and wrote a quick program to control the relay, the led, and the push button along with Blynk for additional control. Also integrated a on/off timer so it can be automated. I went with Blynk for remote control because I have used it on many other projects and it just works. About six months ago I migrated to my own Blynk server. Pair that with a noip.com free forwarding hostname (because I have a dynamic IP from my ISP), and never been happier.
Lets setup the Blynk app first so we know when it comes online initially. I'm assuming you already have it installed and am a little familiar with it. In the Blynk app, create a new project. Title it whatever you want it to show as. For device, we want to select ESP8266 even though it is a ESP8285. Doesn't make a difference for us. Connection type should be wifi. Now select your theme, dark or light. That only effects how it looks. Now click "Create Project." It should bring you to the initial blank page and email you the token for the project. How you add widgets is by clicking on the black grid while stopped and the menu will pop up to select your widgets. Here are your virtual pins and widgets for the project:
Current time - labeled value - V6
Signal - labeled value - V31
On/off button - styled button - V0
On/off times - Time Input - V20 - set format to HH:MM:SS & allow start stop input to on
On/off override - styled button - V21
Reset - button or styled button - V30
Our RTC for timekeeping - RTC - No pin needed
Arrange them however you want. Here is mine:
When you are done click on the play button in the upper right hand corner. It will say offline but yes we know that. It will also have emailed you a token number which we need to put into our program for it to register with Blynk. Enter it in where it says auth="" along with your wifi info. Make sure you got it in there correctly! If you don't you can't connect to your wifi or Blynk.Uploading
Time to upload our program to the ESP8285! I made sure to include the ability for over-the-air programming. Who wants to open it up and try to do a serial upload of a new program should you need to change something?? Not me. I set a static address for the ESP8285 with my network so I know the IP always should I need to upload or whatever. I did though, set it up to upload by serial initially (you have to) to test my program and correct any issues. I had pins on the necessary pads initially & then just used some jumper wires.
To program the ESP8285 by serial, just like the ESP8266, you need to pull gpio 0 low at power on to enter programming mode. Use your USB-TTL to make the connection for the upload. Make sure to only use a regulated 3.3v for power and connect it to VCC and EN. I used the supplied 3.3v from the TTL. TX-->RX, and RX-->TX. and obviously GND to GND.
Now to upload we need to select our board in Arduino IDE or PlatformIO. You need to have the ESP8266 frameworks installed in whichever one you do and I'm assuming you have that done. If not, this shows you how in Arduino IDE.
Select the configuration for the board. It should be something like this but could vary slightly:
Now let's put the chip into flash/programming mode. Ground your gpio 0 pin and either ground the reset pin momentarily to reset the chip or just plug in your TTL adapter and power it on that way. Once you have done this, lets upload our program. Select your port from the "Tools" menu in Arduino IDE. Now upload. If everything goes as planned, the program compiles and uploads to the ESP8285 successfully! Don't disconnect it yet form your TTL. Lets see if Blynk works.
Open your Blynk app if its not already, and make sure your program is "playing." You can tell by if it shows a small square stop button in the upper right hand side. Just to the left of that is a board icon and it should have a red badge on it indicating the board is offline or not connected to the Blynk server. Within 10 seconds or so after uploading our program, that red badge should disappear and it will display "project X online". Thats a great sign! Blynk is working and your program is running!!! Should you need to change something after its all assembled, the OTA works good. It lists the device in your Arduino ports menu & otherwise the upload is normal. Don't interrupt it or you will have to take it apart to refresh it.
Lets move on.Hardware
Back to the hardware, I start by removing the existing wifi chip. I absolutely hate removing solder & I'm not good at it so I carefully cut it off at the pins. Next I identified the the 3 wire ribbon going to the LED & switch hardware using a multimeter. I connected one side to the board pin and then probed each wire to identify which pins were used. Here is my chicken scratch...
For my chip I'm using a ESP8285. Its pretty much the same as the 8266 but has more memory and better wifi performance. I just have very good results with these chips and they program the exact same as the 8266 with Arduino/PlatformIO. I also used it because that's the thinest chip I had lying around. I had pins attached so had to remove the first (ugh). Then I tested just laying it in there with the board to make sure there was plenty of clearance and it did in fact fit.
Next I started soldering the wires onto the smart outlet's board. Below are the pins that I needed to control it.
Ok time to match up the wires with the pins I wanted to use on the ESP8285. It has 0, 2, 4, 13, 14, 16 and the TX/RX pin. I picked 4, 12, & 13. My reason being 0 and 2 are control pins for flashing. I've had problems using these pins in other projects at initial power on. So let's avoid those. 16 is used for sleeping. Don't want that either. Make sure you don't cut your wires too short. You want to be able to glue the ESP8285 down. You also need to solder two pins together: enable (en) & power (vcc). If the enable pin isn't pulled HIGH the chip will never turn on. I accomplished this with a tiny bit of of a single, solid cat5 wire.
Next you want to secure the ESP8285 to the front case. We do this because we don't want it rattling around and we def don't want it touching any other electronics inside. I use a hot glue gun because if you need to remove the chip in the future, it isn't too difficult but yet it creates a good bond. Make sure it's the normal temp plastic glue and not the low temp variety.
Ok, you should be able to put the main board back in. If you have slack on the wires, carefully tuck them along the side by where the ESP8285 is. But try to make them as short as possible. Make sure they are not pinched and that your ESP8285 stayed glued to the case. It might not be a bad idea to put a layer of liquid electrical tape over the metal case & top of the ESP8285 that is facing the main board. If it does come loose for whatever reason its protected then. Screw in the two holding screws on the board and power plugs. Now put on the back case and screw it down.
Thats it for the hardware side.
Ok now to test it. Plug in your hacked smart outlet. It should be completely assembled and physically finished. Watch the Blynk app. Again, within about 10 seconds you will get the message saying XXXX online.
Click on the on/off button in the app. You will hear a click from the outlet and the blue light should turn on. Test to see if it is in-fact relaying power by plugging something into it. Pushing the button in the app again should make it power off. The blue indicator LED should also turn on/off with it respectively. In the app, check the signal level. In my experience with my home wifi setup, you want it to be higher than -75 to be reliable. -83 is my cutoff for connectivity. You results will vary because of variables like your house layout, router quality, interference, chip, etc; but that gives you an idea of levels.
Looks good doesn't it!
For use with HomeKit, I use Homebridge. It runs on my home server and I have Blynk and Nest functionality thru HomeKit. Works great. The plugin you need is called Homebridge Blynk Platform - homebridge-blynk-platform v0.2.5 or newer. You just search for it in their repo thru the server page and it should find it. There are two in there so make sure you get the one developed by @peterwoj. The other doesn't work so good as it appears to be stale. I attached the part of the config file that deals with Blynk and its accessories. Now you have the option to use the Blynk app or your Home app on your iPhone/iPad/Mac!
If you followed these instructions you will have a new working smart plug! Please feel free to follow me @kritch83 on twitter to see some other projects too.