Introduction: Wifi Smart Strip 2.0
Hi everyone, I'm happy to show you the second version of my WiFi smart strip project, now with the integration with Home Assistant. You can found the first version on my instructable profile if you want to see it.
There are a lot of improvement in this new design :
- Instead of using three different boards (5V power supply, NodeMCU and 4-relay-board) with jumper between them, now there is a PCB. We save a lot of space and connections are stronger
- Now we can see wich outlet is powered on thanks to 3 different led, one for each outlet.
- We can also control the 3 outlets with phisycal push button, not only with voice.
- There is also a temperature sensor, that we can choose to use for the internal smart strip temperature or for the room temperature where the smart strip is located. (In my case I chose the second option)
- Thanks to Home Assistant we can set up a lot of automations that involves our strip.
- After powered on the strip for the first time, you will be able to program it via ota (wireless), so you will not need anymore to connect your Esp12f to the USB port of your pc.
Like the previous version we control only 3 of the 4 outlets in the "smart" way. The last outlets is directly connected to the 220V.
Pay attention with 220V, if you don't know what are you doing you can seriously risk your life!
I am not responsible for anything!
Step 1: Necessary Materials
These are all the components we are going to use:
- 1x Hi-Link 5V power supply
- 1x little 2 screw terminal (for AC input)
- 3x 3 screw termianl (relay output)
- 2x 100uF Electrolytic Capacitor
- 1x AMS117 3.3V regulator
- 3x push button
- 1x ESP12F
- 3x 1K Ohm resistor
- 3x 5K Ohm resistor
- 3x BC547 NPN transistor
- 3x PC817 Optocoupler
- 3x Coloured led
- 3x IN4007 diode
- 3x 5V relay
- 1x DHT11 temperature sensor
- Electric cables
- Cables for leds and push buttons(better some thicker cables to avoid electrical disturbances)
- A USB to Serial converter
- 1x Mammut Clamp
- Hot glue
- Obviously everything else I used in the first version of the strip
There are a lot of components but this is not as difficult to assembly as it seems!
Step 2: Program the Esp12f
The first thing you need is to program the esp12f before soldering it to the pcb.
There are a lot of breakout boards really useful for programming this board, so you can choose wich one you prefer, but fortunately I had some very thin jumper that could be inserted in the small hole of the esp12f pins. So they are able to make the necessary "contact" with pins of the board.
Now you have to connect the board with the USB to Serial converter in this way:
Esp12f -------- Usb to Serial
VCC --> 3.3V
CH-PD --> 3.3V
GND --> GND
GPIO15 --> GND
GPIO0 --> GND
TX --> RX
RX --> TX
Now you can plug your USB to Serial converter in the pc and you should be able to see the new serial port through the Arduino Ide.
Then I suggest you to join this great Facebook Community for ESP8266 for the Smart Home to download the firmware. Obviously is 100% free. There you can find the github project with the code and also with the configuration for the integration with Home-Assistant.
After downloading the firmware you have to run the jar tool that will create the configuration file to upload on the esp12f. In the tool you have to setup your WiFi SSID and password, your mqtt broker, username, and password.
Then you have to select all the other things that you can see in the pictures, obviously with the same pin settings. However, everything is explained in the Wiki.
After the configuration file is generated, open SmartHome_v50beta5nc.ino in the Arduino IDE. Then select the type of your board (in my case everything worked with "NodeMCU 1.0 esp12e").
You have to do one last thing if you want to use the DHT11 temperature sensor instead of the DHT22. You have to go to routine_termostato.ino and change the line DHTTYPE DHT22 with DHTTYPE DHT11. Then save and upload the code.
You are done! Now we can solder everything on the pcb.
Step 3: Solder Everything to the Pcb
Before starting, obviously you can modify the pcb, if you want. For example you can choose different type of screw terminal if for some reasons you don't like mine!
Here you can download the gerber file of the pcb:
Well, after printed it we can start to solder.
My skills are not so developed, and you can easily see with my esp12f soldering, so I hope you can do better than me! I modified a bit the original pcb I used because there were some errors, but I didn't want to make print it again. There is only one thing I couldn't change, the transistors direction. You have to solder them in the opposite way compared to what is designed on to the pcb (as you can see in the previous image).
The value of resistors below the esp12f is of 5K (they are pulldown resistors for the push button), and the value of the resistors below the optocouplers is of 1k (they are connected to the bases of the transistors).
Pay attention to everything you are going to solder, especially the two electrolytic capacitors that has polarity, so if you solder them wrong they could explode. Also the optocoupler and diodes need to be soldered in the right way!
Instead of soldering push buttons, leds and the temperature sensor directly to the pcb, connect them to wires and then solder wires to the printed circuit. For push buttons you only need to solder the two higher pins. The other two are useless. (The longer leg of the led must be connected to the higher pin, the shorter leg to the lower one and, for the push buttons, the two leg that must be connected are those ones that are closer to each other).
In this way you can place leds, push buttons and dht11 (or dht22) everywhere you want in the case of the strip. In the Intro image you can see where I choose to put them.
Now we can drill all the holes where we want for these components!
Step 4: Drill the Strip
There is not a lot to say, decide where you want to put the sensor, push buttons and led and drill the holes!
Mine are not perfect and not even aligned, so, again, do it better than me :)
Step 5: Assembly the Smart Strip
Before inserting the pcb in the strip, I suggest to already connect the electric wires to the AC input and to the relay output, as you can see in the image of two steps ago.
Now make all the connections between the board and the four outlets. If you don't know how to do that you can read and see images on my instructable of the first version of this strip. Connections are the same of that images!
After inserting temperature sensor, push buttons and leds, secure their cables with hot glue and try to isolate everything in order to avoid electrical distrubances.
Now you can close the strip, and connect it to the 220V. If you followed well this guide averything should work without any problem!
Step 6: Setting Up With Home Assistant
You should be able to see now the smart strip ip address. If you don't know how to do that, download the Fing application, scan the WiFi network and you should be able to recognize the right ip address.
Type that ip in your browser and you will be connected the esp12f web server.
There you can control indipendently all the three outlets, but not the fourth one.
That one is directly connected to 220V!
Now, in the wiki of the project (from where you downloaded the firmware) you can easily find all the code to add to your configuration.yaml for Home Assistant.
In the wiki, in the down-left corner, you had to select "Interruttore". Then you can copy and paste the code in to your configuration.yaml three times beacause you have to control three outlets. Pay attention that you have to change the number in "interruttore/1" and "interruttore/1/ack" with 2 and then with 3 in order to have three different entities! In availabilty_topic you have to delete all the numbers and write the MAC address of you smart strip, without capital letters and without ":" .
Then for the temperature sensor select "Termostato" and copy only the first two blocks of code, in order to measure temperature and humidity. Remember to change the availability topic.
Save the file, check the configurations and if everything is ok you can reboot Home Assistant.
Now you should be able to control the three outlets and monitor temperature and humidity of the room (or of the internal strip if you soldered the sensor directly to the pcb)!
Step 7: Enjoy!
Congratulations, now you can involve your smart strip in every automations you want through Home Assistant. Then, if you want to control it through voice, you can also connect Home Assistant with Alexa or Google Assistant and your done!