ESPHome 2026.8.1
Loading...
Searching...
No Matches
inkbird_ibsth1_mini.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "inkbird_ibsth1_mini";
7
9 ESP_LOGCONFIG(TAG, "Inkbird IBS TH1 MINI");
10 LOG_SENSOR(" ", "Temperature", this->temperature_);
11 LOG_SENSOR(" ", "External Temperature", this->external_temperature_);
12 LOG_SENSOR(" ", "Humidity", this->humidity_);
13 LOG_SENSOR(" ", "Battery Level", this->battery_level_);
14}
15
17 // The below is based on my research and reverse engineering of a single device
18 // It is entirely possible that some of that may be inaccurate or incomplete
19
20 // for Inkbird IBS-TH1 Mini device we expect
21 // 1) expected mac address
22 // 2) device address type == PUBLIC
23 // 3) no service data
24 // 4) one manufacturer data
25 // 5) the manufacturer data should contain a 16-bit uuid amd a 7-byte data vector
26 // 6) the 7-byte data component should have data[2] == 0 and data[6] == 8
27
28 // the address should match the address we declared
29 if (device.address_uint64() != this->address_) {
30 ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
31 return false;
32 }
33 if (device.get_address_type() != ble_device_base::BLE_ADDR_TYPE_PUBLIC) {
34 ESP_LOGVV(TAG, "parse_device(): address is not public");
35 return false;
36 }
37 if (!device.get_service_datas().empty()) {
38 ESP_LOGVV(TAG, "parse_device(): service_data is expected to be empty");
39 return false;
40 }
41 const auto &mnf_datas = device.get_manufacturer_datas();
42 if (mnf_datas.size() != 1) {
43 ESP_LOGVV(TAG, "parse_device(): manufacturer_datas is expected to have a single element");
44 return false;
45 }
46 const auto &mnf_data = mnf_datas[0];
47 if (mnf_data.uuid.type() != ble_device_base::ESPBTUUID::Type::UUID16) {
48 ESP_LOGVV(TAG, "parse_device(): manufacturer data element is expected to have uuid of length 16");
49 return false;
50 }
51 if (mnf_data.data.size() != 7) {
52 ESP_LOGVV(TAG, "parse_device(): manufacturer data element length is expected to be of length 7");
53 return false;
54 }
55 if ((mnf_data.data[6] != 8) && (mnf_data.data[6] != 6)) {
56 ESP_LOGVV(TAG, "parse_device(): unexpected data");
57 return false;
58 }
59
60 // sensor output encoding
61 // data[5] is a battery level
62 // data[0] and data[1] is humidity * 100 (in pct)
63 // uuid is a temperature * 100 (in Celsius)
64 // when data[2] == 0 temperature is from internal sensor (IBS-TH1 or IBS-TH1 Mini)
65 // when data[2] == 1 temperature is from external sensor (IBS-TH1 only)
66
67 // Create empty variables to pass automatic checks
68 auto temperature = NAN;
69 auto external_temperature = NAN;
70
71 // Read bluetooth data into variable
72 auto measured_temperature = ((int16_t) mnf_data.uuid.uuid16()) / 100.0f;
73
74 // Set temperature or external_temperature based on which sensor is in use
75 if (mnf_data.data[2] == 0) {
76 temperature = measured_temperature;
77 } else if (mnf_data.data[2] == 1) {
78 external_temperature = measured_temperature;
79 } else {
80 ESP_LOGVV(TAG, "parse_device(): unknown sensor type");
81 return false;
82 }
83
84 auto battery_level = mnf_data.data[5];
85 auto humidity = ((mnf_data.data[1] << 8) + mnf_data.data[0]) / 100.0f;
86
87 // Send temperature only if the value is set
88 if (!std::isnan(temperature) && this->temperature_ != nullptr) {
90 }
91 if (!std::isnan(external_temperature) && this->external_temperature_ != nullptr) {
92 this->external_temperature_->publish_state(external_temperature);
93 }
94 if (this->humidity_ != nullptr) {
95 this->humidity_->publish_state(humidity);
96 }
97 if (this->battery_level_ != nullptr) {
98 this->battery_level_->publish_state(battery_level);
99 }
100
101 return true;
102}
103
104} // namespace esphome::inkbird_ibsth1_mini
esp_ble_addr_type_t get_address_type() const
Definition ble_device.h:204
uint64_t address_uint64() const
Return MAC as packed uint64 (byte 0 in LSB — matches esp32's address_uint64).
const std::vector< ServiceData > & get_service_datas() const
Definition ble_device.h:225
const std::vector< ServiceData > & get_manufacturer_datas() const
Definition ble_device.h:224
bool parse_device(const ble_device_base::ESPBTDevice &device) override
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
uint16_t temperature
Definition sun_gtil2.cpp:12