Introduction: Quick and Easy ESP8266 Plug Via OpenHAB

Here's a relativity affordable plug for those whom wish to build their own hardware. This is a hold-over instructable to give me a little more time to finish my Moteino series



  • Solder Gun
  • Glue Gun
  • PC
  • Solder Extractor
  • Voltage meter

WARNING! High voltage may cause severe personal injury or death disconnect all power supplies before tampering with the electrical enclosure.

Check out my other tutorials

Part 1 openHAB and Zwave - Getting Started

Part 2 openHAB, MQTT, and ESP Easy - Build your own DIY Node

Turn a cheap WiFi plug into an openHAB ESP8266 switchable plug

Installing openHAB2 on Raspberry Pi

Intro - Creating a PCB board for the Moteino (design, etching, and soldering)

Step 1: Preparing the Power Supply

  1. Pull the housing off of the USB power supply. there will be two parts attached to each other. Be careful not to damage this ribbon cable. You can discard the housing and metal prongs, while keeping the wires, from the plug.
  2. Use the solder gun and extractor to remove the USB housing. I find it helpful to use a flat head screwdriver to help pry the housing off.
  3. Prepare to attach the pigtail to the power supply. I use a plain extension cord and cut off the female side for the pigtail. There are two wires that where attached to the metal prongs. These are the 120vac leads. It doesn't matter which you connect to the the USB. Be sure to only use the neutral and hot wires, not the ground.
    1. Cut 1 (one) 4" (inches) piece of the cord for the relay and plug.
    2. Cut the extension cord to your preferred length. I recommend leaving the ground long enough to hook to the plug (about 4".) I missed this, the ground, in the video.
    3. Strip the wire ends for a connection
    4. slip on some heat shrink tubing on each individual wire to cover any exposed copper.
    5. Solder the wires together making sure that you to leave sharp edges that will break through the heat shrink tubing.
    6. Pull the heat shrink tubing over the exposed wires and heat to seal the wires.
    7. Hot glue the wires to the board for extra protection.
  4. Place the power supply in a safe/secure place that will allow you to safety plug it in to test the 5 vdc for positive and negative.
  5. Use the voltage meter to test the leads and note the + & - on the board with a permanent marker.
  6. Cut the spare micro USB to about 4-5" (inches) to power the Wemos ESP. You will need to retain the micro USB side of the cord for this. Pray that the wires are color coated red for + and black for -.
  7. Strip and solder the USB to the board the red wire goes to the + (positive) and the black wire goes to the - (negative) from your voltage test in 5.
  8. Glue the power supply and extension cord wire down onto the lower plate of the box. I use quite a bit of glue here to prevent the cord from pulling out.

Step 2: Build Out the ESP and Relay

Both the relay shield and the Wemos come with headers.

  • Line up and solder the female headers onto the top of the Wemos.
  • Line up and solder the male headers onto the bottom of the relay shield.

That's it for the ESP hardware. The relay is set to GPIO 5 in the Arduino configuration.

Step 3: Load the Firmware Onto the ESP

I'm using ESP Easy for the easy of use.

Go here and download the firmware.

I'm using R120 as it is the stable version as of 12-27-16.

  • Download the zip file and extract to C:\Esp8266 to match this tutorial (You can place where ever you like.)
  • Plug the ESP into your PC and open the Computer Management program. Use Computer Management to open COM ports to find out which port the ESP is on. My ESP is on COM 3.
  • Open windows command prompt by pressing the Windows key and typing
  • Navigate to the ESP Easy folder you extracted the zip file to by typing
cd C:\Esp8266
  • start the ESP app and filling with the following

Comport (example 3, 4, ..) :


Flash Size (example 512, 1024, 4096) :


Build (example 71, 72, ..) :


If all goes well, the blue led will start flashing and the window will show progress with dots. Once complete, power cycle the ESP. After a few seconds, you will see a new wireless WAP with a SSID of ESP_# (# some single digit number). If you do not have an SSID, boot the ESP while monitoring the serial port via Arduino or putty to see if you can find the problem within the log. I'll proceed as if you have the SSID is up and running.

  • Connect to the ESP_# SSID
  • The network password is configesp
  • Open your favorite browser and go to Your PC will be given an IP address by the ESP.
  • The page will say "Welcome to ESP Easy" and you can select your network from available SSIDs.
  • Type in your WIFI network password then "connect"
  • The ESP will connect to your network and give you the new IP address provided by your gateway.
  • Switch you WIFI connection back to your network and log in to your ESP via this given IP address.
  • In the video, I opened up openHAB to pulling the naming scheme that I use for plugs. I opened items and added this plug. Custom plug icons are included in the attached photos.
Switch	Esp_Portable_Plug02	"Portable Plug 2"	<plug>	(<christmas_lights>All,Quick_Access,Random_Switches)	{mqtt=">[mymosquitto:/PorPlg2/gpio/5:command:ON:1],>[mymosquitto:/PorPlg2/gpio/5:command:OFF:0]"}</christmas_lights>

Back to the ESP

  • Set the name to match your openHAB item
  • IMPORTANT ACTION - Set the password on the "WPA AP Mode Key" field. I use

    GRC's Ultra High Security Password Generator to get my passwords. Changing this will change the password on the ESP_# network and help you secure this node. If you don't change this and the ESP disconnects from your network, it is feasible for someone to log into the ESP and get your network credentials.

  • Set the reset of the fields necessary for connecting to openHAB
Name: PorPlg2<br>SSID: your network 
WPA AP Mode Key: random number
Unit nr:  1 
Controller IP: (your openHAB IP address)
Controller Port: 1883 
Sensor Delay: 60
  • Click Tools -> Logs in the ESP GUI and check for connectivity to openHAB

You should see a "Connected to Broker" line in the log.

Step 4: Place All the Components Into the Box and Button It Up.

Use the diagram as a wiring guide for the relay and plug.

  • Solder the stripped ends of the 120v leads and the 4" spare wire. This will prevent the wire from fraying out and decrease the chances of an electrical short.
  • Screw the green wire (ground) to the green screw on the plug. This is usually located at the top or bottom of the plug.
  • Run the black wire (hot) from to the 120v lead onto the middle connector on the relay.
  • Run the spare 4" wire from the NO (normally open) connector on the relay to the darker color screw on the plug
  • Run the white wire (neutral) from the 120v lead directly to the plug.
  • Tuck the ESP/Relay into the box. Be careful not to place it in on the power supply. This may create an electric short.
  • Place the duplex plug in the box and mount the cover.

You are done! Enjoy.

Step 5: Video of the Build