ESPhome-Controlled Power Strip

Integration of a power strip with Home Assistant using a ESP8266 and ESPhome

I needed a power strip which can be turned on and off remotely to power the active speakers of my AV receiver.

Since I wanted some sockets always powered (for example, the AV receiver) and some switchable (the speakers), I decided to prepare a custom power strip using modular components.

Given previous positive experiences with GEWISS, I chose an enclosure GW27007, Schuko modules GW20246 and Italian modules GW20203 (useful for many devices even outside Italy), and a switch GW20503. The always-on modules were chosen in red color variant.

Enclosure Schuko Italian

If you can find all the components in the same (online or not) shop, you should be able to get an enclosure for one single Schuko and the Schuko module at about 10 Euro and all the electronics for 5 Euro, which makes the project about as expensive as many ready-made WiFi plugs. The only cheaper one I could find is the Gosund WiFi plug, which can be also flashed directly with ESPhome and already provides power measurements.

Construction

I used 2.5 mm2 solid copper wires for most internal connections. Only the connections to the electronic components and to the external power cord were done with thinner wires (the voltage rating was taken into account).

Thin wires don't go well together with very thick solid wires because each fastening screw of the Gewiss modules pulls a plate which holds a wire on each side and if one is much thicker, the thinner one is not held tightly. As solution I doubled the thin wires and used some solder to keep them in the shape. In theory this is BAD because solder tends to flow slowly with time under pressure and makes the connections loose, but in this case there is no movement of the wires at all, so I accepted it.

I noticed that one side of the enclosure is wider than the other one for placing stickers on it, so I could fit the relays and the ESP8266 inside the enclosure. However, I had to use single relays, the double ones didn't fit.

The relays are placed in parallel with the manual switch, because I want to control the power strip even if the software fails.

I drilled a hole at the end of the enclosure and I placed a neon indicator lamp in it to indicate power status. For those interested, Gewiss offers an indicator module GW20603 which requires no modifications.

You can see an open power strip and a closed one in the following image.

Assembled

Software

Regarding the electronics part, I used ESPhome, since it provides all I needed and it's very easy to program.

I placed all the values constant for multiple units in external files ("!secret"), I enabled the access point ("ap") mode with a captive portal so that I can connect to the ESPhome even if it fails to connect to my main WiFi network, I enabled logging and over-the-air updates, I set it to connect to Home Assistant without any secret key (I don't want to update each ESPhome if I reinstall Home Assistant or if something happens), the webserver so that I can control the ESPhome units even without Home Assistant, just by connecting to it, and I set an output pin for the switching of the relays. Since they come for free, I also added uptime and WiFi strength sensors.

You can find the source code here:

esphome:
  name
: power_strip_51_front
#  name: power_strip_51_rear
  platform
: ESP8266
  board
: esp12e

wifi
:
  ssid
: !secret wifi_ssid
  password
: !secret wifi_password
  ap
:
    ssid
: !secret ap_ssid
    password
: !secret ap_pass

captive_portal
:

# Enable logging
logger
:
  level
: DEBUG
# to disable it:
#  baud_rate: 0

ota
:
  password
: !secret ota_password

api
:
#  password: !secret esplibapi_password

status_led
:
  pin
: GPIO13

web_server
:

switch
:
  - platform
: gpio
    name
: "Front speakers"
    icon
: "mdi:monitor-speaker"
#    name: "Rear speakers"
#    icon: "mdi:surround-sound-5-1"
    pin
: GPIO5
#    pin: GPIO4
    restore_mode
: ALWAYS_OFF

sensor
:
  - platform
: uptime
    name
: "Uptime Front Speakers"
#    name: "Uptime Rear Speakers"
    icon
: "mdi:timelapse"

  - platform
: wifi_signal
    name
: "WiFi Strength Front Speakers"
#    name: "WiFi Strength Rear Speakers"
    unit_of_measurement
: "dB"
    update_interval
: 60s

The resulting WiFi signal strength in Home Assistant looks like this:

WiFi strength

Author: Olaf Marzocchi

First revision: 2019-11-19.
Last revision: 2019-11-20.