Integrating Mi/QingPing BLE sensors into Home Assistant without a Gateway

Xiaomi Temperature Humidty BLE Sensor

Some Xiaomi temperature sensors advertise sensor data over Bluetooth Low Energy (BLE) packets. The data is encoded but we can decode it and make this data available in Home Assistant.

A quick search revealed a library that can decode the service data for these devices. I played with this for a bit but ended up finding a much easier solution. As it turns out, the different values for temperature and humidty have been converted to hex format and concatenated, forming the servicedata string in the BLE message.

I can see these messages on the MQTT server via a Bluetooth to MQTT gateway. I linked to a previous post below for how to set up OpenMQTTGateway and the advantages of RF and BLE devices over Wifi.

MQTT Payload received by OpenMQTTGateway
{"id":"58:2D:34:11:D5:E1","name":"Qingping Temp & RH Lite","rssi":-78,"distance":7.85288,"servicedata":"30586f0626e1d511342d5808"}

Home Assistant Template Sensors

Given all this information– and some help from the community–we are able to create some Jinja templates to extract the correct values and convert them to temperature and humidity values.

- platform: mqtt
  name: "Bedroom Mi Temp"
  device_class: temperature
  state_topic: "home/gw/BTtoMQTT/582D3411D5E1"
  value_template: "{{ ((value_json.servicedata[10:12] | int(value_json.servicedata[10:12], 16)))/10 }}"
  unit_of_measurement: "°C"
- platform: mqtt
  name: "Bedroom Mi Hum"
  device_class: humidity
  state_topic: "home/gw/BTtoMQTT/582D3411D5E1"
  value_template: "{{ ((value_json.servicedata[12:14] | int(value_json.servicedata[12:14], 16)))/10 }}"
  unit_of_measurement: "Hum %"

Related posts

Troubleshooting Intermittent WiFi Issues: Solving “Host Unreachable, No IP Route” Error on Android and NUC Devices

How to Optimize Docker Builds with Nexus OSS for Apt, Maven, Docker and NPM Dependencies

Troubleshooting Asus Xonar U7: Blinking LED and Connectivity Issues

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More