Full home temperature monitoring with $4 sensors

Published: by

  • Categories:

Problem statement

Every weekend project starts with a problem, here, it's about monitoring temperature/humidity around multiple places in the house without spending significant money on devices.

Answer is, a aliexpress order of the following:-

Overview

  • Temperature/Humidity Sensors: These act as a super cheap sensor modules that I keep around the house, however, they only advertise data via Bluetooth. So, that's where the next device comes in.
  • ESP32: This device receives the data over Bluetooth from these devices and we collect this in Home Assistant via ESPHome based API running on these boards. Note, one ESP32 can actually connect to many sensors which is where the affordability comes in, only limit is the bluetooth signal.

Steps

Prepare Sensors

To keep things more open & easy, we'll flash the newly bought sensors with custom firmware. This time, I've chosen to use pvvx/ATS_MiThermometer. This project is a fork of another popular firmware atc1441/ATC_MiThermometer

  • Setup the new sensors in Mi app.
    • I wonder if this step is necessary, I did it anyway as it was my time playing around with these sensors. I wanted to see what the vanilla experience looks like.
  • Flash them with Custom Firmware by visiting the following webpage, yes, all you need is to visit this webpage via your phone.
    • Follow instructions here
    • Make sure you note down the mac addresses of devices. Those MAC Addresses are the only thing you need to make your configuration work, as these devices are bluetooth based.

Prepare ESP32

We'll be using ESPHome as a firmware choice, because, it's my first ESP32 project so I want to keep it easy by only messing around with yaml files, nothing else.

My advice is to proceed on a linux system, as I was getting a a lot of flash failures when working on Mac OS.

  • Install esphome
pip3 install esphome
  • Ensure you're part of dialout account group, so that you're able to write to serial devices without needing root access. Your first flash of esp board would be over USB. Later, once it's flashed once, it can be done over internet.
$ sudo useradd -a -G dialout shadyabhi

# you'll need to logout/login to take effect, or, create a new login shell. 
$ su - $USER

# you can confirm that you've the new group applied via executing
$ groups
shadyabhi adm dialout cdrom sudo dip plugdev input kvm lpadmin lxd sambashare libvirt microk8s
  • Create the right starter ESPHome yaml which we'll modify later with our sensor data in the next step.
$ esphome wizard temp-sensors.yaml

# Answer some basic questions:- 
# 
# Board type: esp32dev
  • Finally, add find mac addresses of sensors in the yaml. Following lines need to be added to start gathering sensor data and sending to Home Assistant.
esp32_ble_tracker:

sensor:
  - platform: pvvx_mithermometer
    mac_address: "A4:C1:38:xx:xx:xx"         # Fill appropriate mac address (source: flasher webpage)
    temperature:
      name: "Office Temperature"
    humidity:
      name: "Office Humidity"
    battery_level:
      name: "Office Temp Sensor Battery-Level"
    battery_voltage:
      name: "Office Temp Sensor Battery-Voltage"

  - platform: pvvx_mithermometer
    mac_address: "A4:C1:38:xx:xx:xx"         # Fill appropriate mac address (source: flasher webpage)
    temperature:
      name: "Garage Temperature"
    humidity:
      name: "Garage Humidity"
    battery_level:
      name: "Garage Temp Sensor Battery-Level"
    battery_voltage:
      name: "Garage Temp Sensor Battery-Voltage"
  • As a bonus, I also added sensors around tracking bluetooth signals for these devices.
  - platform: ble_rssi
    mac_address: A4:C1:38:xx:xx:xx
    name: "Office Mi Temperature sensor signal rssi"

  - platform: ble_rssi
    mac_address: A4:C1:38:xx:xx:xx
    name: "Garage Mi Temperature sensor signal rssi"
  • Flash the board with config
$ esphome run temp-sensors.yaml

# You'll be asked to choose flash-type, for first attempt, it has to be via USB. 
# In my case, device path is: /dev/ttyACM0

Troubleshooting

ESPHome

Logs

  • To check ESPHome logs,
    # As the device is setup already, you can now do operations over Wifi.
    # Discovery is done via DNS via `.local` hostname, so it should be automagical.
    $ esphome logs temp-sensors.yaml
    

DNS connectivity issues

  • If esphome is unable to find your device over DNS, it means that your local router isn't setup to auto-serve devices over DNS via mDNS. For me, I started my "adventure" with the following official wiki.