ESPhome-Controlled Power Strip

Integration 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.

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.

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
  platform: ESP8266
  board: esp12e

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

captive_portal:

logger:
  level: DEBUG

ota:
  password: !secret ota_password

api:

status_led:
  pin: GPIO13

web_server:

switch:
  - platform: gpio
    name: "Front speakers"
    icon: "mdi:monitor-speaker"
    pin: GPIO5
    restore_mode: ALWAYS_OFF

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

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

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

Update 2025

Since then I modified the configuration various times.

Right now, with all the features added/corrected over time, and with all the modifications required by newer ESPhome releases, the configuration is:

esphome:
  name: power-strip-51-front
  friendly_name: Power strip front speakers

esp8266:
  board: esp12e

logger:

api:
  encryption:
    key: "xxx"

ota:
  - platform: esphome
    password: "xxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: False

  ap:
    ssid: "Power-Strip-51-Front"
    password: "xxx"

captive_portal:
    
status_led:
  pin: GPIO13

web_server:

switch:
  - platform: gpio
    name: "Front speakers"
    icon: "mdi:monitor-speaker"
    pin: GPIO5
    restore_mode: ALWAYS_OFF 

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

  - platform: wifi_signal
    name: "Front Speakers Wifi"
    unit_of_measurement: "dB"
    update_interval: 60s
    device_class: "signal_strength"
    state_class: "measurement"

  - platform: adc
    pin: VCC
    name: "VCC Voltage"
    accuracy_decimals: 2
    device_class: "voltage"
    state_class: "measurement"
    entity_category: diagnostic

button:
  - platform: restart
    name: "Restart"

First revision: 2019-11-19.