Hello,
I have incorrectly placed esp thermostats in my house, so I wanted to add external sensors to them. I have a Switchbot Meter, so I wanted to add it to one of the thermostats, but did not find any useful data on how to do it other than using a bluetooth proxy and using home assistant. This would work, but it would create an unnecessary step and if HA goes down I would loose the sensor values.
Experimented with the readings and the logic seems pretty simple. Now it works without HA, but I thought I will share it, maybe somebody finds it useful. Battery reading are not exact, but it could be a good indicator (228 seems to be the max and capped around 2.9V, 140 was reported with a battery that was used for 2 years and I measured 2.116V on it, had no issue, but I considered it low enough to be counted as 0.
Here is a template:
sensor:
- platform: template
name: "External sensor Temperature"
id: room_temp
unit_of_measurement: "°C"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 1
- platform: template
name: "External sensor Humidity"
id: room_humidity
unit_of_measurement: "%"
device_class: "humidity"
state_class: "measurement"
accuracy_decimals: 0
- platform: template
name: "External sensor Battery"
id: room_battery
unit_of_measurement: "%"
device_class: "battery"
state_class: "measurement"
accuracy_decimals: 0
filters:
- calibrate_linear:
- 140 -> 0
- 228 -> 100
esp32_ble_tracker:
on_ble_advertise:
- mac_address: C4:59:63:49:FF:64
then:
- lambda: |-
for (auto &data : x.get_service_datas()) {
if (data.uuid.get_uuid().uuid.uuid16 == 0x0D00 && data.data.size() >= 6) {
// Temperature: Byte 4 (integer offset 128) + Byte 3 (decimal /10)
float t_integer = (int)data.data[4] - 128;
float t_decimal = (float)data.data[3] / 10.0;
float final_temp = t_integer + t_decimal;
// Humidity: Byte 5
float final_hum = data.data[5];
// Battery: Byte 2
float raw_batt = data.data[2];
id(room_temp).publish_state(final_temp);
id(room_humidity).publish_state(final_hum);
id(room_battery).publish_state(raw_batt);
}
}