project: an immersion heater that turns itself when the water is hot – using a Sonoff POW.

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. Other energy monitoring smart relays can be used but the POWr2 is used here.

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.

As of 2020 you no longer need to re-program Sonoff wifi smart plugs to control them with Home Assistant

Since this project was created, AlexxIT created a custom_component for Sonoff devices which should be able to tell Home Assistant its power usage and be controllable. If you don’t want to use AlexxIT’s excellent but unofficial integration use the following procedure. If you want to use the Sonoff integration, skip to setting up the automation: see how we programmed the heater.

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 
substitutions:
   devicename: immersion_heater
  
 esphome:
   name: {devicename}
   platform: ESP8266
   board: esp01_1m
 
wifi:
   ssid: "YOUR_SSID"
   password: "YOUR WIFI PASSWORD"
   manual_ip:
     # Set this to the IP you want for the ESP
     static_ip: 192.168.1.11
     # Set this to the IP address of the router. Often ends with .1
     gateway: 192.168.1.1
     # The subnet of the network. 255.255.255.0 works for most home networks.
     subnet: 255.255.255.0

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

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

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

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

sensor:
  - 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 *