Advertisement
Kat81inTX

ESPHome BLE Client for TDWLB-LC-RPPF

Jan 10th, 2025
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.96 KB | Source Code | 0 0
  1. substitutions:
  2.   name: "esphome-ble-bridge"
  3.   friendly_name: "ESP32-S3 BLE Bridge"
  4.   local_tdwlb_lcrppf_mac: !secret tdwlb_lcrppf_mac
  5.  
  6. esphome:
  7.   name: ${name}
  8.   friendly_name: ${friendly_name}
  9.   min_version: 2024.6.0
  10.   name_add_mac_suffix: false
  11.   platformio_options:
  12.     board_build.f_flash: 40000000L
  13.     board_build.flash_mode: dio
  14.     board_build.flash_size: 4MB
  15.  
  16. esp32:
  17.   board: esp32-s3-devkitc-1
  18.   variant: esp32s3
  19.   framework:
  20.     type: esp-idf
  21.     sdkconfig_options:
  22.       CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
  23.       CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y
  24.  
  25. # Enable logging for debugging
  26. logger:
  27.   level: INFO
  28.  
  29. # Enable Home Assistant API
  30. api:
  31. # Enable Over-The-Air updates
  32. ota:
  33.   - platform: esphome
  34.     password: !secret ota_password
  35.  
  36. # Allow WiFi provisioning via serial
  37. improv_serial:
  38. # WiFi configuration
  39. wifi:
  40.   ssid: !secret wifi_ssid
  41.   password: !secret wifi_password
  42.   power_save_mode: light
  43.  
  44. captive_portal:
  45. bluetooth_proxy:
  46.   active: true
  47.  
  48. esp32_ble_tracker:
  49.   id: ble_tracker
  50.   scan_parameters:
  51.     active: true
  52.     interval: 320ms
  53.     window: 30ms
  54.  
  55. ble_client:
  56.   - mac_address: !secret tdwlb_lcrppf_mac
  57.     id: tdwlb_lcrppf
  58.     auto_connect: true
  59.  
  60. text_sensor:
  61.   - platform: ble_client
  62.     ble_client_id: tdwlb_lcrppf
  63.     service_uuid: "180A"
  64.     characteristic_uuid: "2A24"
  65.     name: "Model Number"
  66.     icon: "mdi:information-outline"
  67.     id: pressure_sensor_model_number
  68.  
  69.   - platform: ble_client
  70.     ble_client_id: tdwlb_lcrppf
  71.     service_uuid: "180A"
  72.     characteristic_uuid: "2A29"
  73.     name: "Manufacturer"
  74.     icon: "mdi:information-outline"
  75.     id: pressure_sensor_manufacturer
  76.  
  77.   - platform: ble_client
  78.     ble_client_id: tdwlb_lcrppf
  79.     service_uuid: "180A"
  80.     characteristic_uuid: "2A25"
  81.     name: "Serial Number"
  82.     icon: "mdi:information-outline"
  83.     id: pressure_sensor_serial_number
  84.  
  85.   - platform: ble_client
  86.     ble_client_id: tdwlb_lcrppf
  87.     service_uuid: "180A"
  88.     characteristic_uuid: "2A26"
  89.     name: "Firmware Revision"
  90.     icon: "mdi:information-outline"
  91.     id: pressure_sensor_firmware_revision
  92.  
  93. sensor:
  94.    
  95. # Pressure sensor
  96.   - platform: ble_client
  97.     ble_client_id: tdwlb_lcrppf
  98.     type: characteristic
  99.     service_uuid: "CC4A6A80-51E0-11E3-B451-0002A5D5C51B"
  100.     characteristic_uuid: "835AB4C0-51E4-11E3-A5BD-0002A5D5C51B"
  101.     name: "Tank Pressure"
  102.     unit_of_measurement: "psi"
  103.     accuracy_decimals: 1
  104.     device_class: "pressure"
  105.     notify: true
  106.     lambda: |-
  107.       // Extract the 16-bit unsigned integer raw value from the byte array
  108.       uint16_t raw = (x[0] << 8) | x[1];
  109.       // Scale the raw value directly
  110.       float pressure_psi = raw / 10.0;
  111.       return pressure_psi;
  112.    
  113. # Temperature sensor
  114.   - platform: ble_client
  115.     ble_client_id: tdwlb_lcrppf
  116.     type: characteristic
  117.     service_uuid: "CC4A6A80-51E0-11E3-B451-0002A5D5C51B"
  118.     characteristic_uuid: "2A1C"
  119.     name: "Tank Temperature"
  120.     id: tank_temperature
  121.     unit_of_measurement: "°F"
  122.     accuracy_decimals: 1
  123.     device_class: "temperature"
  124.     notify: true
  125.     lambda: |-
  126.       // Extract the first byte that contains the internal / external flag bit (bit 3)
  127.       uint8_t flag = x[0];
  128.       // Extract the 32-bit raw value from the byte array
  129.       uint32_t temp_raw = (x[1] << 24) | (x[2] << 16) | (x[3] << 8) | x[4];
  130.       // Convert to signed float representing °C
  131.       float celsius = *reinterpret_cast<float*>(&temp_raw);
  132.       // convert to °F
  133.       float farenheit = celsius * 9.0 / 5.0 + 32.0;
  134.       return farenheit;
  135.  
  136.   # Battery level
  137.   - platform: ble_client
  138.     ble_client_id: tdwlb_lcrppf
  139.     type: characteristic
  140.     service_uuid: "180F"
  141.     characteristic_uuid: "2A19"
  142.     name: "Battery Level"
  143.     unit_of_measurement: "%"
  144.     icon: "mdi:battery"
  145.     update_interval: 60s
  146.  
  147. button:
  148.   - platform: safe_mode
  149.     id: button_safe_mode
  150.     name: Safe Mode Boot
  151.  
  152.   - platform: factory_reset
  153.     id: factory_reset_btn
  154.     name: Factory reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement