this is how I decode raw bthome directly on a esp32 with esphome,
you can probably use esphome over commandline on windows and just not connect it to homeassistant and skip arduino just a thought. anyway here are the code.
esphome:
name: ble-32-tst
platformio_options:
board_build.f_cpu: 80000000L
preferences:
flash_write_interval: 999min
wifi:
fast_connect: true
ssid: "xxxxxxxxx"
password: "xxxxxxxxxxx"
output_power: 10
power_save_mode: HIGH #HIGH NONE LIGHT
#use_address: ble-32-nrf.local
esp32:
board: esp32dev
framework:
type: esp-idf
version: recommended
# Enable logging
logger:
baud_rate: 0
#level: NONE # DEBUG # NONE
# Enable Home Assistant API
api:
ota:
esp32_ble_tracker:
scan_parameters:
active: false
duration: 33s
interval: 100ms #161ms #1100ms
window: 99ms #160ms #1090ms
on_ble_service_data_advertise:
- mac_address: 38:1F:8D:FD:91:5A #BTH01- 915A
service_uuid: FCD2
then:
- lambda: |-
ESP_LOGD("ble_adv", "ble data: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x ", x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10],x[11],x[12],x[13],x[14],x[15],x[16]);
int16_t temp_int = ((((x[6] & 0xff) | (x[7] & 0xff) << 8)));
float temp = temp_int/100.0;
float hum = ((((x[9] & 0xff) | (x[10] & 0xff) << 8)))/100.0;
float volt = ((((x[12] & 0xff) | (x[13] & 0xff) << 8)))/1000.0;
//ESP_LOGD("ble_BTH01", "temp %.2f hum %.2f volt %.3f",temp,hum,volt);
if(x[5]==0x02&&x[8]==0x03&&x[11]==0x0C&&temp>(-40)&&temp<100&&hum>0&&hum<101&&volt>0&&volt<4)
{
id(BTH01_temperature_).publish_state(temp);
id(BTH01_humidity_).publish_state(hum);
id(BTH01_volt_).publish_state(volt);
}
- mac_address: 38:1F:8D:ED:D8:4A #TH05- D84A
service_uuid: FCD2
then:
- lambda: |-
ESP_LOGD("ble_adv", "ble data: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x ", x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10],x[11],x[12],x[13],x[14],x[15],x[16]);
int16_t temp_int = ((((x[6] & 0xff) | (x[7] & 0xff) << 8)));
float temp = temp_int/100.0;
float hum = ((((x[9] & 0xff) | (x[10] & 0xff) << 8)))/100.0;
float volt = ((((x[12] & 0xff) | (x[13] & 0xff) << 8)))/1000.0;
//ESP_LOGD("ble_TH05", "temp %.2f hum %.2f volt %.3f",temp,hum,volt);
if(x[5]==0x02&&x[8]==0x03&&x[11]==0x0C&&temp>(-20)&&temp<100&&hum>0&&hum<101&&volt>0&&volt<4)
{
id(TH05_temperature_).publish_state(temp);
id(TH05_humidity_).publish_state(hum);
id(TH05_volt_).publish_state(volt);
}
sensor:
- platform: ble_rssi
mac_address: '38:1F:8D:ED:D8:4A'
name: "rssi TH05"
filters:
- filter_out: nan # <-- Processing will stop here on unknown values.
- median:
window_size: 10
- platform: template
name: "TH05 humidity"
unit_of_measurement: '%'
accuracy_decimals: 2
device_class: "humidity"
state_class: "measurement"
id: TH05_humidity_
filters:
- median:
window_size: 7
send_every: 6
#- delta: 0.05
- platform: template
name: "TH05 temperature"
unit_of_measurement: °C
accuracy_decimals: 2
device_class: "temperature"
state_class: "measurement"
id: TH05_temperature_
filters:
- median:
window_size: 7
send_every: 6
# - delta: 0.05
- platform: template
name: "TH05 volt"
accuracy_decimals: 3
unit_of_measurement: V
device_class: "voltage"
state_class: "measurement"
id: TH05_volt_
filters:
- median:
window_size: 7
send_every: 6
##-------------------------------------------------------------------------------
##-----------------------------------------------------------------------------
- platform: ble_rssi
mac_address: '38:1F:8D:FD:91:5A'
name: "rssi BTH01"
filters:
- filter_out: nan # <-- Processing will stop here on unknown values.
- median:
window_size: 10
- platform: template
name: "BTH01 humidity"
unit_of_measurement: '%'
accuracy_decimals: 2
device_class: "humidity"
state_class: "measurement"
id: BTH01_humidity_
filters:
- median:
window_size: 7
send_every: 6
#- delta: 0.05
- platform: template
name: "BTH01 temperature"
unit_of_measurement: °C
accuracy_decimals: 2
device_class: "temperature"
state_class: "measurement"
id: BTH01_temperature_
filters:
- median:
window_size: 7
send_every: 6
# - delta: 0.05
- platform: template
name: "BTH01 volt"
accuracy_decimals: 3
unit_of_measurement: V
device_class: "voltage"
state_class: "measurement"
id: BTH01_volt_
filters:
- median:
window_size: 7
send_every: 6
just look at https://bthome.io/format/
to identify in what order it sends the sensor data
the code above is to decode data from Tuya sensor updated with https://github.com/pvvx/THB2