Xiaomi Temperature Humidty BLE Sensor
%author% via %publisher%
Home / Integrating Mi/QingPing BLE sensors into Home Assistant without a Gateway
Editor's picks Home Assistant Integrations

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

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 %"

Leave a Comment

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

DON’T MISS OUT!
Subscribe To Newsletter
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Give it a try, you can unsubscribe anytime.
close-link