project: smart immersion heater

Domestic hot water can be heated by a gas / oil central heating boiler or by an electrical immersion heater. I choose to take advantage of half-price nighttime electricity and use an immersion heater. Its mechanical timer is a pain to use, adjust or even turn off. And then it’s guesswork to choose turn on and turn off heating times. But with an overnight heating session, the tank water is always hot by morning and there’s enough hot water to last until the next morning.

Keen to know how best to use the water heater, I bought a Sonoff POWR2 wifi relay. The Sonoff POWR2 (£9.50) can measure the electricity used, run a schedule and is easily and remotely adjusted.

The Sonoff POWR2 normally connects to an app (ewelink). This app can set a schedule, however it doesn’t provide the history of the electricity used in between on times. So I set about giving it that feature by flashing it with ESPhome firmware. I would then be able to view the history in Home Assistant, my home automation app, as well as control the switch.

How to re-program a Sonoff wifi smart plug and control it with Home Assistant

The Sonoff smart plug contains an ESP8266 chip. Its firmware can be replaced with different firmware so that you can use it in Home Assistant. The result is a hike in capability and convenience – but the procedure appeared a bit scary first time I saw it:

  1. Open the Sonoff and solder four male pin headers to VCC, GND, TX and RX. Don’t connect this to mains power until you’re away from the computer and the socket has been reassembled!
  2. Use female-to-male Dupont jumper cables to connect the Sonoff to a FTDI UART board set at 3.3v.
  3. Use the code in the ESPhome node for this plug. Validate and compile the code into a binary file on your PC.
  4. Hold down the Sonoff reset button as you plug the FTDI into a USB socket on your computer. You can now release the reset button.
  5. Use Esphome-flasher to upload the binary file to the Sonoff.

Edit the code in ESPhome

What we’re trying to do is to add our own more useful code to an ESP chip and thus replace the manufacturers code. In the ESPhome code below we add our wifi password and network settings. We can also add a reboot switch or wifi signal meter but below is all we need. I use this code a lot in my other projects.

# Enter the name you want to use 
   devicename: immersion_heater
   name: {devicename}
   platform: ESP8266
   board: esp01_1m
   ssid: "YOUR_SSID"
   password: "YOUR WIFI PASSWORD"
     # Set this to the IP you want for the ESP
     # Set this to the IP address of the router. Often ends with .1
     # The subnet of the network. works for most home networks.

  - platform: cse7766
   name: "water heater current"
   icon: "mdi:current-ac"
   name: "water heater voltage"
   icon: "mdi:power-socket-uk"
   name: "water heater power"
   id: my_power
  - platform: total_daily_energy
    name: "water heater energy today"
    power_id: my_power 

# Enable useful feedback
# Enable a connection to the Home Assistant API 
  password: "YOUR Home ASSISTANT API password"

# OTA ENABLES over the air edits of this from now on
  password: ""

# The following can be omitted 
  - platform: restart
    name: ${devicename} restart 

  - platform: wifi_signal
    name: ${devicename} wifi signal
    update_interval: 600s

Add the flashed ESP to Home Assistant

In Home Assistant click as follows: Configuration > Setup integrations > ESPhome > Enter the IP address > done.

You can now control the heater

See how we programmed the heater

Leave a Reply

Your email address will not be published. Required fields are marked *