Collecting Temperature Data from ELA Bluetooth Puck with ESPHome


ELA Innovations sells Bluetooth Low Energy based IDs and Sensors in different flavor ranging from ID, Temperature, Temperature and Humidity to Digital IO and more. From some tests I had a Temperatue and a Temperature and Humidity lying around and tried to connect them to my Home Assistand installation. The Pucks are configured with a Smartphone App and I have set them to a Update intervall of 2 seconds and the usage of Bluetooth Service Data for the actual data. That way the Buck should last between 5-7 Year with their unreplaceable battery.

To connect sensors easily to Home Assisant the ESPHome framework exists which let you build Firmware for ESP8266 and ESP32 Microcontoller using a quite simple configuration syntax based on YAML Files.

I have choosen a ESP32-WROOM-32 Board from AZ-Deliver for my experiment, because the ESP32 supports 2.4 GHz Wifi and Bluetooth up to Version 4.2. The current version of ESPHome 1.15.3 supports tracking ble devices with the component esp32_ble_tracker. Format and IDs of the Bluetooth Service Data Element are well defined the actual documentation of the ELA pucks.

The config is listening for the MAC Adress of the Puck and the Service UUIDs for Temperatore and Huminity.

esp32_ble_tracker:
  on_ble_service_data_advertise:
    - mac_address: 11:22:33:44:55:66
      service_uuid: 2a6e
    - mac_address: 11:22:33:44:55:66
      service_uuid: 2a6f

Since the ELA Bluetooth Pucks are not supported natively in ESPHome, I had to add some lambda to the configuration which are mostly short snippets of C++ code that will be placed in the generated code.

esp32_ble_tracker:
  on_ble_service_data_advertise:
    - mac_address: 11:22:33:44:55:66
      service_uuid: 2a6e
      then:
        - lambda: |-
            const int16_t temp_val = (x[1] << 8) + x[0];
            const float temperature = temp_val / 100.0;
            
            id(ble_temp).publish_state(temperature);
    - mac_address: 11:22:33:44:55:66
      service_uuid: 2a6f
      then:
        - lambda: 'id(ble_hum).publish_state(x[0]);'

A working sample looks like this:

esphome:
  name: btscanner
  platform: ESP32
  board: nodemcu-32s

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "BT Scnnr Fllbck Htspt"
    password: !secret ap_password

time:
  - platform: sntp
    id: sntp_time
    
captive_portal:

logger:

api:
  reboot_timeout: 0s
  
ota:

web_server:
  port: 80

esp32_ble_tracker:
  on_ble_service_data_advertise:
    - mac_address: 11:22:33:44:55:66
      service_uuid: 2a6e
      then:
        - lambda: |-
            const int16_t temp_val = (x[1] << 8) + x[0];
            const float temperature = temp_val / 100.0;
            
            id(ble_aussen_temp).publish_state(temperature);
          
    - mac_address: 11:22:33:44:55:66
      service_uuid: 2a6f
      then:
        - lambda: 'id(ble_aussen_hum).publish_state(x[0]);'
    - mac_address: 22:33:44:55:66:77
      service_uuid: 2a6e
      then:
        - lambda: |-
            const int16_t temp_val = (x[1] << 8) + x[0];
            const float temperature = temp_val / 100.0;
            
            id(ble_innen_temp).publish_state(temperature);

  scan_parameters:
    interval: 166ms
    window: 30ms
    duration: 60s
    active: false

sensor:
  - platform: ble_rssi
    mac_address: 11:22:33:44:55:66
    name: "BLE aussen RSSI"
  - platform: template
    name: "BLE aussen Temperatur"
    id: ble_aussen_temp
    accuracy_decimals: 2
  - platform: template
    name: "BLE aussen Humidity"
    id: ble_aussen_hum
    accuracy_decimals: 0
  - platform: ble_rssi
    mac_address: 22:33:44:55:66:77
    name: "BLE innen RSSI"
  - platform: template
    name: "BLE innen"
    id: ble_innen_temp
    accuracy_decimals: 2
    

I hope that helps other to get there pucks up and running this Home Assistand and ESPHome.