project: monitor temperature around the house

The Xiaomi Mijia sensor runs for ages on a AAA battery and it can be stuck to a wall to show the temperature and humidity. It’s an attractive Bluetooth Low Energy device that beams out measurements for under £10. If I install an app (Mi Home) I can receive those readings from across the room and wonder what’s the point. The point and the value of this sensor is that I can e.g. connect it to Home Assistant and show a graph of how well the storage heater copes against the cold outside. (Till now, knowing when to set the heater timer has been guesswork). If you have a room that’s too hot or cold, seeing its temperature history offers clues to correct that.

There’s one caveat – the Xiaomi Mijia will need to be in Bluetooth range of the device (eg Raspberry Pi) running Home Assistant. Further down the page I’ll show a great workaround so that you can measure temperature in remote areas of the house. First though, here’s what to do to connect your Xiaomi Mijia to Home Assistant:

  • Use a Bluetooth app on your phone to pair or search for new devices. You’ll soon see the MJ_xxx device – click on that for details and note the Device Bluetooth address. You want to enter that in place of 4C:65:A8:D9:E0:EE in bold below.
  • Now go to the Home assistant Configurator and open configuration.yaml. Add the following code and save the file.
  - platform: mitemp_bt
    mac: '4C:65:A8:D9:E0:EE'
    name: Mi living room 
      - temperature   
      - humidity 
Summary: go to the Configurator and open configuration.yaml. Add the code above and save the file. I have two sensors hence there are two entries above. The Device Bluetooth address is also called the Bluetooth mac address. There are several apps that will help you find a mac address.
Go next to Configuration > Server Control >
> Configuration validation > RESTART server (if the configuration was valid)

To display the feature/s just added, we must restart Home Assistant. When Home Assistant is live again, go to the frontend or Overview. Click Configure UI > + choose a ‘card’ and add this code

  entity: sensor.Mi_living_room_humidity
  entity: sensor.Mi_living_room_temerature
  type: history-graph 

An ESP32 can collect readings from a remote Xiaomi Mijia temperature sensor

The Xiaomi Mijia has a tiny internal aerial and it needs to be in Bluetooth range of the device (eg Raspberry Pi) running Home Assistant. To get readings from further away, I use an ESP32 board powered with a USB charger. The ESP32 picks up the temperature readings over Bluetooth and then it relays them to Home Assistant over the network wifi. That might seem extravagant and troublesome, however this Bluetooth feature can piggyback onto an ESP32 that you’ve already set up to do something else (e.g. reading the electricity meter).

How to use ESPHome to collect readings from a remote Xiaomi Mijia

I jump ahead here to assume that you have an ESP32 set up (see the tutorial) to monitor something or initiate something like turn on the lights, when you enter the kitchen. In short, you previously used ESPhome to type a list of settings, your wifi password; a network address, a title or name plus a few other things. You then used ESPhome to compile this into a firmware file which you uploaded to an ESP32 chip.

With the fiddly bit done, you now want to turn on the Bluetooth features of the ESP32 chip. Go to the ESPHome section in Home Assistant. It may already have a few entries or ‘nodes’ like this:

The main dashboard of the ESPhome section in Home Assistant

Edit the ‘node’ or entry that you want to add Bluetooth to, and paste in this text. You’ll need to edit the bold items below and match the Bluetooth mac address to your Xiaomi Mijia.


  - platform: xiaomi_lywsdcgq
    mac_address: '58:2D:34:22:E1:69'
      name: "hall temperature"
      name: "hall humidity"
      name: "hall battery"

SAVE and then UPLOAD this and that’s pretty much it. When you previously uploaded firmware you added an over-the-air (OTA) capability to the ESP32 so you need not connect it with wires this time.

Finally, go to the Home Assistant Overview, click Configure UI > + > History Graph. Then add this code to display a graph of the Xiaomi Mijia which is now presumably in Bluetooth range of the ESP32 we’ve been editing:

  entity: sensor.mi_humidity
  entity: sensor.mi_temerature
  type: history-graph 
sample graph
note the inverse relationship between temperature and humidity. It gets cold at night – cold air ‘dissolves’ less water therefore there is more ‘undissolved’ water in the air hence you detect higher humidity. The ratio of temp : humidity should be clear. The graph tells you that the humidity falls as the room heats up. So where has the humidity gone?

4 Responses

  1. Shehzad says:

    I am trying to follow your tutorial but unable to even get past the page for home assistant url, is there any way that i could read historical temperature without home assistant?

    • roger says:

      A temperature vs time graph is indeed very useful – it’s so useful that it’s tragic or shocking that the app for these home temperature devices don’t provide a history graph.

      For me Home Assistant is too versatile to ignore. It provides graphs of
      heating oil level,
      house electricity use,
      appliance electricity use,
      cooking oven temperature,
      position of the sun (solar panels)
      outdoor temperature
      freezer temperature

      The path to this amount of DIY home automation was troublesome. If you have a Raspberry Pi already I would persist to make progress with Home Assistant or indeed another automation platform.

  2. Andy Cox says:

    What kind of range are you getting from the Mijia to the Raspberry Pi? Thanks.

    • roger says:

      Whether the Mijia is linked to a Pi or an ESP32 the Bluetooth reaches across a five metre room at home. The range is not very good. The signal does go through a wall but it wouldn’t get any distance into the next room.

      To recap: to get a good range, and perhaps take temperatures in every room of a house, this project puts an ESP32 in a central place in a house. This project makes recording the history of Mijia temperatures in every room possible – I use one ESP32 to relay the readings to a Pi. I put this ESP32 in the central hall and it can pick up Mijia readings from the immediate rooms.

      In short different Mijias each send over a short distance to one ESP32 which relays the readings over the house wifi.

Leave a Reply

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