Skip to content

Commit 9ad9382

Browse files
authored
THB1 Decoder (#624)
Decoder for THB1 Tuya Thermo-Hygrometer with PVVX firmware in BTHome v2 format
1 parent e97c8af commit 9ad9382

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

docs/devices/THB1.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Tuya THB1
2+
3+
4+
|Model Id|[THB1](https://github.com/theengs/decoder/blob/development/src/devices/THB1_json.h)|
5+
|-|-|
6+
|Brand|Tuya|
7+
|Model|THB1 Thermo-Hygrometer|
8+
|Short Description|Temperature and humidity sensor with PVVX firmware|
9+
|Communication|BLE broadcast|
10+
|Frequency|2.4Ghz|
11+
|Power Source|CR2032|
12+
|Exchanged Data|temperature, humidity, battery, voltage|
13+
|Encrypted|No|

src/decoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class TheengsDecoder {
140140
MOPEKA,
141141
T201,
142142
T301,
143+
THB1,
143144
NUT,
144145
NUTALE,
145146
ITAG,

src/devices.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#include "devices/Mopeka_json.h"
9292
#include "devices/T201_json.h"
9393
#include "devices/T301_json.h"
94+
#include "devices/THB1_json.h"
9495
#include "devices/tracker_json.h"
9596
#include "devices/iNodeEM_json.h"
9697
#include "devices/ARANET4_json.h"
@@ -225,6 +226,7 @@ const char* _devices[][2] = {
225226
{_Mopeka_json, _Mopeka_json_props},
226227
{_T201_json, _T201_json_props},
227228
{_T301_json, _T301_json_props},
229+
{_THB1_json, _THB1_json_props},
228230
{_tracker_json_nut, _tracker_json_props},
229231
{_tracker_json_nutale, _tracker_json_props},
230232
{_tracker_json_itag, _tracker_json_props},

src/devices/THB1_json.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const char* _THB1_json = "{\"brand\":\"Tuya\",\"model\":\"THB1 Thermo-Hygrometer\",\"model_id\":\"THB1\",\"tag\":\"0102\",\"condition\":[\"servicedata\",\"=\",28,\"index\",0,\"40\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"THB1\"],\"properties\":{\"packet\":{\"condition\":[\"servicedata\",2,\"00\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"tempc\":{\"condition\":[\"servicedata\",10,\"02\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",12,4,true,true],\"post_proc\":[\"/\",100]},\"hum\":{\"condition\":[\"servicedata\",16,\"03\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",18,4,true,false],\"post_proc\":[\"/\",100]},\"batt\":{\"condition\":[\"servicedata\",6,\"01\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]},\"volt\":{\"condition\":[\"servicedata\",22,\"0c\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",24,4,true,false],\"post_proc\":[\"/\",1000]}}}";
2+
/* R""""(
3+
{
4+
"brand":"Tuya",
5+
"model":"THB1 Thermo-Hygrometer",
6+
"model_id":"THB1",
7+
"tag":"0102",
8+
"condition":["servicedata", "=", 28, "index", 0, "40", "&", "uuid", "index", 0, "fcd2", "&", "name", "index", 0, "THB1"],
9+
"properties":{
10+
"packet":{
11+
"condition":["servicedata", 2, "00"],
12+
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false]
13+
},
14+
"tempc":{
15+
"condition":["servicedata", 10, "02"],
16+
"decoder":["value_from_hex_data", "servicedata", 12, 4, true, true],
17+
"post_proc":["/", 100]
18+
},
19+
"hum":{
20+
"condition":["servicedata", 16, "03"],
21+
"decoder":["value_from_hex_data", "servicedata", 18, 4, true, false],
22+
"post_proc":["/", 100]
23+
},
24+
"batt":{
25+
"condition":["servicedata", 6, "01"],
26+
"decoder":["value_from_hex_data", "servicedata", 8, 2, false, false]
27+
},
28+
"volt":{
29+
"condition":["servicedata", 22, "0c"],
30+
"decoder":["value_from_hex_data", "servicedata", 24, 4, true, false],
31+
"post_proc":["/", 1000]
32+
}
33+
}
34+
})"""";*/
35+
36+
const char* _THB1_json_props = "{\"properties\":{\"packet\":{\"unit\":\"int\",\"name\":\"packet id\"},\"tempc\":{\"unit\":\"°C\",\"name\":\"temperature\"},\"hum\":{\"unit\":\"%\",\"name\":\"humidity\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"},\"volt\":{\"unit\":\"V\",\"name\":\"voltage\"}}}";
37+
/*R""""(
38+
{
39+
"properties":{
40+
"packet":{
41+
"unit":"int",
42+
"name":"packet id"
43+
},
44+
"tempc":{
45+
"unit":"°C",
46+
"name":"temperature"
47+
},
48+
"hum":{
49+
"unit":"%",
50+
"name":"humidity"
51+
},
52+
"batt":{
53+
"unit":"%",
54+
"name":"battery"
55+
},
56+
"volt": {
57+
"unit": "V",
58+
"name": "voltage"
59+
}
60+
}
61+
})"""";*/

tests/BLE/test_ble.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ const char* expected_uuid_name_svcdata[] = {
351351
"{\"brand\":\"Sensor Easy\",\"model\":\"SE MAG\",\"model_id\":\"SE_MAG\",\"type\":\"CTMO\",\"open\":true,\"cont\":true}",
352352
"{\"brand\":\"Sensor Easy\",\"model\":\"SE MAG\",\"model_id\":\"SE_MAG\",\"type\":\"CTMO\",\"open\":false,\"cont\":true}",
353353
"{\"brand\":\"SwitchBot\",\"model\":\"Outdoor Meter\",\"model_id\":\"W340001X\",\"type\":\"THB\",\"batt\":65}",
354+
"{\"brand\":\"Tuya\",\"model\":\"THB1 Thermo-Hygrometer\",\"model_id\":\"THB1\",\"type\":\"THB\",\"acts\":true,\"packet\":239,\"tempc\":17.94,\"tempf\":64.292,\"hum\":60.72,\"batt\":74,\"volt\":2.748}",
354355
};
355356

356357
const char* expected_uuid[] = {
@@ -1137,6 +1138,7 @@ const char* test_uuid_name_svcdata[][4] = {
11371138
{"SE MAG Open","0x2a06","P MAG CCCCCC","2400"},
11381139
{"SE MAG Closed","0x2a06","P MAG CCCCCC","2900"},
11391140
{"SwitchBot Outdoor Meter Servicdata", "0xfd3d", "WoIOSensorTH", "770041"},
1141+
{"THB1 PVVX", "0xfcd2", "THB1-3F9E5D", "4000ef014a02020703b8170cbc0a"},
11401142
};
11411143

11421144
TheengsDecoder::BLE_ID_NUM test_uuid_name_svcdata_id_num[]{
@@ -1232,6 +1234,7 @@ TheengsDecoder::BLE_ID_NUM test_uuid_name_svcdata_id_num[]{
12321234
TheengsDecoder::BLE_ID_NUM::SE_MAG,
12331235
TheengsDecoder::BLE_ID_NUM::SE_MAG,
12341236
TheengsDecoder::BLE_ID_NUM::SBOT_S,
1237+
TheengsDecoder::BLE_ID_NUM::THB1,
12351238
};
12361239

12371240
// uuid test input [test name] [uuid] [data source] [data]

0 commit comments

Comments
 (0)