Measurement of flow and return temperatures of a heating system
with SONOFF devices and Home Assistant.
I used Sonoff because they are all in one with power supply and box.
But before we use them, we should know some important details about them.
The device will not boot into its regular operating mode if GPIO02 is pulled low at boot and so the GPIO02 is useless.
Below you will find a table of all usable GPIO pins of the Sonoff Basic and a configuration file that exposes all of the basic functions.
(Started on 20 Dec. 2022)
Sonoff Basic R2 V1.0
|GPIO00||Button (inverted)||turn buzzer off|
|GPIO01||TX pin (C1 Pin 2)|
|GPIO03||RX pin (C1 Pin 3)||High at BOOT
It’s suitable for 3xDS18B20
(PMW It’s suitable for Buzzer)
|GPIO02||Free||Boot fails if pulled-down|
|GPIO13||Green LED (inverted)||OK|
Water binary Sensor
I’m using GPIO03 (Rx) for DS18B20 temperature sensors, which does not have any boot function restrictions.
The GPIO14 is definitely not connected (Sonoff Basic R2 V1.0) so I solder a wire to the chip to access the GPIO14.
Connect Sonoff device for Esphome install
Connect USB FTDI programmer to the computer, hold down the basic broad button to connect GPIO0 to GND while the device is booting to put it in Programming and Flash mode.
Note: We supply USB power to Sonoff via FTDI and make sure you set 3.3V setting on FTDI, 5V will cause damage.
- 3x DS18B20 temperature Sensor
- moisture sensor (3.3V-5V) binary leakage sensor
- 1x 4.7k Ohms Resistor
The rain board module uses a voltage comparator LM393 and the result is given to output in two formats, digital (0 and 1) and analog AO.
- Open ESPHome Interface and click on the New Device button.
- Enter device name of your choice as well as your WiFi name and password.
- In the next dialog, click on Pick specific Board radio button and select the Generic ESP8266 (for example Sonoff) click Next button.
- lick Install button and you will have ESPHome installed on your ESP device.
When the ESP installation is finished, the Sonoff device will be automatically added in the ESPHome Dashboard.
Remove the Sonoff BASIC cover and de-solder the relay and add a buzzer with a 220 ohm resistor instead.
The DS18B20 are “onewire” bus sensors. So we connecting all of the DS18B20s in parallel, sharing all of the VDD, GND and signal pin.
Next we connect signal pins to digital pin GPIO03 (RX) on the Sonoff.
Temperature Sensors are wired according to the following scheme.
The 4.7 kOhm resistor be soldered between the DS1820 signal pin and VCC.
Getting Sensor IDs
In order to get the address of each DS sensor, simply start the firmware on your device with a configured Dallas hub and observe the log output (the log level must be set to at least debug!).
Note that you don’t need to define the individual Dallas sensors just yet, as the scanning will happen even with no sensors connected.
For example with this configuration:
Device name: sonoff_1 Device type: Generic 8266 wifi: ssid: !secret wifi_ssid password: !secret wifi_password # Example configuration entry dallas: - pin: GPIO03 # Note you don't have to add any sensors at this point
Some specifics about the code above
- The water sensor exposes the entity binary_sensor. That becomes on if a water leak is detected by the sensor’s probe.
- The automation trigger is based on the changing state (on / off) of this entity.
- The notification message will be sent to your smartphone via the alarm_stream to be sure the vibrate/silent ringer mode won’t avoid your device to ring.
The code is checked into GitHub at: forgani/Temperatures-of-a-heating-system
-> 3-phase energy monitoring with ESPHome