Xiaomi LYWSDCGQ BLE Sensor

The xiaomi_lywsdcgq sensor platform lets you track the output of Xiaomi LYWSDCGQ Bluetooth Low Energy devices using the ESP32 Bluetooth Low Energy Tracker Hub. This component will track the temperature, humidity and optionally the battery level of the device every time the sensor sends out a BLE broadcast. Note that contrary to other implementations, ESPHome can track as many LYWSDCGQ devices at once as you want.

../../_images/xiaomi_lywsdcgq-full.jpg

Xiaomi Temperature and Humidity Sensor over BLE.

../../_images/xiaomi_lywsdcgq-ui.png
# Example configuration entry
esp32_ble_tracker:

sensor:
  - platform: xiaomi_lywsdcgq
    mac_address: 7A:80:8E:19:36:BA
    temperature:
      name: "Xiaomi LYWSDCGQ Temperature"
    humidity:
      name: "Xiaomi LYWSDCGQ Humidity"
    battery_level:
      name: "Xiaomi LYWSDCGQ Battery Level"

Configuration variables:

  • mac_address (Required, MAC Address): The MAC address of the Xiaomi LYWSDCGQ device.
  • temperature (Optional): The information for the temperature sensor.
    • name (Required, string): The name for the temperature sensor.
    • id (Optional, ID): Set the ID of this sensor for use in lambdas.
    • All other options from Sensor.
  • humidity (Optional): The information for the humidity sensor
    • name (Required, string): The name for the humidity sensor.
    • id (Optional, ID): Set the ID of this sensor for use in lambdas.
    • All other options from Sensor.
  • battery_level (Optional): The information for the battery level sensor
    • name (Required, string): The name for the battery level sensor.
    • id (Optional, ID): Set the ID of this sensor for use in lambdas.
    • All other options from Sensor.

Setting Up Devices

To set up Xiaomi LYWSDCGQ devices you first need to find their MAC Address so that ESPHome can identify them. So first, create a simple configuration without any xiaomi_lywsdcgq entries like so:

esp32_ble_tracker:

After uploading the ESP32 will immediately try to scan for BLE devices such as the Xiaomi LYWSDCGQ. When it detects these sensors, it will automatically parse the BLE message print a message like this one:

Got Xiaomi LYWSDCGQ 7A:80:8E:19:36:BA Got temperature=23.4°C, humidity=65.0%

Note that it can sometimes take some time for the first BLE broadcast to be received. You can speed up the process by pressing the grey bluetooth button on the back of the device.

Then just copy the address (7A:80:8E:19:36:BA) into a new sensor.xiaomi_lywsdcgq platform entry like in the configuration example at the top.

Note

The ESPHome Xiaomi integration listens passively to packets the xiaomi device sends by itself. ESPHome therefore has no impact on the battery life of the device.