Be Smart, Go Local.

How to Integrate SwitchBot Meter Pro and Meter Pro (CO2) in ESPHome

Guide for integrating SwitchBot Meter Pro and Meter Pro (CO2) thermometers in Home Assistant by parsing BLE byte data with ESPHome.

A few months ago, I published a comprehensive guide on capturing BLE advertisement data from the SwitchBot Outdoor Thermometer using an ESP32 board. The process involved capturing, decoding, and parsing byte-level data in ESPHome, transforming it into functional sensors for Home Assistant.

It’s a detailed and somewhat intricate procedure, heavily reliant on the availability of key information to kickstart the process. If you want to deep dive into the technicalities of BLE decoding, I highly recommend checking out the article. It provides an in-depth look at my thought process and the challenges of decoding one-byte characteristics, a common approach used by SwitchBot and many other manufacturers.

SwitchBot Meter Pro (CO2) Added to Home Assistant via ESPHome Featured Image

In this article, I won’t be revisiting the entire process in detail. Instead, I’ll highlight the key differences I encountered while integrating the SwitchBot Meter Pro and SwitchBot Meter Pro (CO2) thermometers.

For the complete code, feel free to skip to the end.

Why use an ESP32 to capture BLE data?

In the comment section of the last article, I got asked several times why use an ESP32 board to parse data and not just use the official SwitchBot integration. For reference, the integration works wonderfully by simply using your server’s Bluetooth radio or even using an ESP32 as a Bluetooth Proxy.

I prefer using ESP32s for everything Bluetooth-related, as I have them everywhere throughout my smart home setup in one form or another. Here’s a few key differences I would list as advantages over using built-in Bluetooth radios:

  • Extended Range and Reliability: An ESP32 can be strategically placed closer to devices, ensuring stronger BLE signal reception compared to a central system with a fixed Bluetooth radio (e.g RPi).
  • Custom Parsing and Control: ESPHome allows for advanced customization and direct parsing of BLE byte data, enabling precise handling of unsupported or locked device features. Additionally, you can configure custom reporting intervals and Bluetooth scanning windows, optimizing performance and saving battery life.
  • Active and Passive Connections: With an ESP32, you can choose between active and passive BLE scanning, providing greater flexibility to balance real-time responsiveness with power efficiency and reducing interference with other Bluetooth devices.
  • Centralized BLE Hub: With an ESP32, you can manage multiple BLE devices from a single node, consolidating communications and reducing dependency on Home Assistant’s Bluetooth integrations for various vendors. For example, I can capture BLE packets from a SwitchBot thermometer, a Xiaomi temperature sensor or a HHCCJCY10 plant sensor on a single node.
  • Scalability: Multiple ESP32 devices can be deployed across your home to cover large areas, ensuring consistent BLE coverage and reducing signal dead zones. I simply reuse other ESP32-based devices I already use in my home to capture data from a random device. For example, I use AirGradient’s ONE sensor to capture data from a temperature sensor in the bedroom.

Understanding BLE Advertisement Bytes for SwitchBot Meter Pro and Meter Pro (CO2)

When integrating the SwitchBot Meter Pro and Meter Pro (CO2) with ESPHome, understanding the structure of their BLE advertisement data is crucial. Each version uses specific bytes within the advertisement packet to represent temperature, humidity, battery level, and—on the CO2 model—carbon dioxide levels.

SwitchBot Meter Pro Byte Structure

The SwitchBot Meter Pro has the following byte structure:

  • Temperature: Bytes 8 and 9.
    • Byte 8’s lower 4 bits (0x0F) represent the decimal part;
    • Byte 9’s upper 7 bits (0x7F) represent the whole number part.
    • Byte 9’s highest bit (0x80) indicates the sign (0 = positive, 1 = negative).
    • Example: Byte 8 = 0x05 (0.5), Byte 9 = 0x98 (24, positive), Temperature = 24.5°C.
  • Humidity: Byte 10.
    • The lower 7 bits (0x7F) represent the humidity percentage.
    • Example: Byte 10 = 0x64, Humidity = 100%.
  • Battery: Byte 2.
    • The lower 7 bits (0x7F) represent the battery percentage.
    • Example: Byte 2 = 0x50, Battery = 80%.
  • Service Data Identifier: Byte 0 (first byte of service data).
    • Indicates the device type. Value: 0x34 (52).

SwitchBot Meter Pro (CO2) Byte Structure

The SwitchBot Meter Pro (CO2) has the following byte structure:

  • Temperature: Bytes 8 and 9.
    • Byte 8’s lower 4 bits (0x0F) represent the decimal part;
    • Byte 9’s upper 7 bits (0x7F) represent the whole number part.
    • Byte 9’s highest bit (0x80) indicates the sign (0 = positive, 1 = negative).
    • Example: Byte 8 = 0x05 (0.5), Byte 9 = 0x98 (24, positive), Temperature = 24.5°C.
  • Humidity: Byte 10.
    • The lower 7 bits (0x7F) represent the humidity percentage.
    • Example: Byte 10 = 0x64, Humidity = 100%.
  • Battery: Byte 2.
    • The lower 7 bits (0x7F) represent the battery percentage.
    • Example: Byte 2 = 0x50, Battery = 80%.
  • CO2: Bytes 13 and 14.
    • Combined as a 16-bit big-endian integer. Byte 13 = High byte, Byte 14 = Low byte.
    • Example: Byte 13 = 0x03, Byte 14 = 0xE8, CO2 = (0x03 << 8) | 0xE8 = 1000 ppm.
  • Service Data Identifier: Byte 0 (first byte of service data).
    • Indicates the device type. Value: 0x35 (53).

Flashing the ESP32 Board

For capturing BLE characteristics from the SwitchBot Meter Pro and Meter Pro (CO2), any ESP32 will do the job. I recently talked about a tiny ESP board that can be used as a Bluetooth proxy, which will serve as an esp32_ble_tracker for this purpose.

My base code for this board looks like this:

esphome:
  name: esp32-c3-super-mini
  friendly_name: ESP32-C3 Super Mini

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino
    

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "XXXXX"

ota:
  - platform: esphome
    password: "XXXXX"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32-C3-Super-Mini"
    password: "XXXXX"

captive_portal: 

You will notice I’m using the arduino framework instead of esp-idf. When the bluetooth_proxy configuration is enabled, the esp-idf framework is recommended because it uses less memory and is more stable. For capturing packets with a passive esp32_ble_tracker component, the arduino framework works better.

Meter Pro Full Code

Here’s the full code for capturing SwitchBot Meter Pro BLE data with a generic ESP32 board. Replace the MAC address and adapt the config to your ESP32 board:

SwitchBot Meter Pro Added to Home Assistant via ESPHome
Meter Pro in Home Assistant with ESPHome

Meter Pro (CO2) Full Code

Here’s the full code for capturing SwitchBot Meter Pro (CO2) BLE data with a generic ESP32 board. Replace the MAC address and adapt the config to your ESP32 board.

SwitchBot Meter Pro (CO2) Added to Home Assistant via ESPHome
Meter Pro (CO2) in Home Assistant with ESPHome

Combined Code (both devices)

Here’s the full code for capturing BLE data of both devices with a generic ESP32 board. Replace the MAC address and adapt the config to your ESP32 board.

SwitchBot Meter Pro and Meter Pro (CO2) Added to Home Assistant via ESPHome
Meter Pro and Meter Pro (CO2) in Home Assistant with ESPHome

Device Availability

The SwitchBot Meter Pro and Meter Pro (CO2) are excellent indoor thermometers and air quality sensors. You can get them on the official SwitchBot webstore or various Amazon stores around the world. Here’s where they are available:

SwitchBot Meter Pro Review: Non-CO2 Technical Specification SmartHomeScene

SWITCHBOT WEBSTORE
Meter Pro (US) | Meter Pro (EU)


United States | United Kingdom
Germany | Netherlands | France
*If links fail to open, try disabling your AdBlocker.
USE CODE BFCM30 FOR 30% OFF

SwitchBot Meter Pro Review: CO2 Technical Specification SmartHomeScene

SWITCHBOT WEBSTORE
Meter Pro CO2 (US) | Meter Pro CO2 (EU)


United States | United Kingdom
Germany | Netherlands | France
*If links fail to open, try disabling your AdBlocker.
USE CODE BFCM30 FOR 30% OFF

Leave a Comment