Skip to content

Commit

Permalink
ShellyBLU H&T SBHT-003C decoder (#554)
Browse files Browse the repository at this point in the history
* ShellyBLU H&T SBHT-003C decoder

* Button Hold to int 11, also for SBBT-002C

* SBHT_003C encrypted decoder added
  • Loading branch information
DigiH authored Sep 2, 2024
1 parent 629fa5f commit 9856916
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/devices/SBBT-002C.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ The button press type is encoded as:
* 2 - Double click
* 3 - Triple click
* 9 - Long press
* 11 - Button hold
17 changes: 17 additions & 0 deletions docs/devices/SBHT-003C.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ShellyBLU H&T

|Model Id|[SBHT-003C](https://github.com/theengs/decoder/blob/development/src/devices/SBHT_003C_json.h)|
|-|-|
|Brand|Shelly|
|Model|ShellyBLU H&T|
|Short Description|Humidity and temperature sensor|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power Source|CR2032|
|Exchanged Data|temperature, humidity, button press type, battery, packet ID|
|Encrypted|Yes/No - Optional|

The button press type is encoded as:

* 1 - Single short click
* 11 - Button hold
2 changes: 2 additions & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class TheengsDecoder {
SBDW_002C_ENCR,
SBMO_003Z,
SBMO_003Z_ENCR,
SBHT_003C,
SBHT_003C_ENCR,
BLE_ID_MAX
};

Expand Down
4 changes: 4 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
#include "devices/SBDW_002C_ENCR_json.h"
#include "devices/SBMO_003Z_json.h"
#include "devices/SBMO_003Z_ENCR_json.h"
#include "devices/SBHT_003C_json.h"
#include "devices/SBHT_003C_ENCR_json.h"


const char* _devices[][2] = {
Expand Down Expand Up @@ -236,4 +238,6 @@ const char* _devices[][2] = {
{_SBDW_002C_ENCR_json, _SBDW_002C_ENCR_json_props},
{_SBMO_003Z_json, _SBMO_003Z_json_props},
{_SBMO_003Z_ENCR_json, _SBMO_003Z_ENCR_json_props},
{_SBHT_003C_json, _SBHT_003C_json_props},
{_SBHT_003C_ENCR_json, _SBHT_003C_ENCR_json_props},
};
5 changes: 3 additions & 2 deletions src/devices/SBBT_002C_json.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const char* _SBBT_002C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"tag\":\"1106\",\"condition\":[\"servicedata\",\"=\",14,\"index\",0,\"40\",\"|\",\"servicedata\",\"=\",14,\"index\",0,\"44\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"SBBT-002C\"],\"properties\":{\"packet\":{\"condition\":[\"servicedata\",2,\"00\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"batt\":{\"condition\":[\"servicedata\",6,\"01\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]},\"button\":{\"condition\":[\"servicedata\",10,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",12,2],\"lookup\":[\"00\",0,\"01\",1,\"02\",2,\"03\",3,\"04\",9]},\"mac\":{\"condition\":[\"manufacturerdata\",\"=\",30],\"decoder\":[\"revmac_from_hex_data\",\"manufacturerdata\",18]}}}";
const char* _SBBT_002C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"tag\":\"1106\",\"condition\":[\"servicedata\",\"=\",14,\"index\",0,\"40\",\"|\",\"servicedata\",\"=\",14,\"index\",0,\"44\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"SBBT-002C\"],\"properties\":{\"packet\":{\"condition\":[\"servicedata\",2,\"00\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"batt\":{\"condition\":[\"servicedata\",6,\"01\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]},\"button\":{\"condition\":[\"servicedata\",10,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",12,2],\"lookup\":[\"00\",0,\"01\",1,\"02\",2,\"03\",3,\"04\",9,\"fe\",11]},\"mac\":{\"condition\":[\"manufacturerdata\",\"=\",30],\"decoder\":[\"revmac_from_hex_data\",\"manufacturerdata\",18]}}}";
/*R""""(
{
"brand":"Shelly",
Expand All @@ -22,7 +22,8 @@ const char* _SBBT_002C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Butto
"01", 1,
"02", 2,
"03", 3,
"04", 9]
"04", 9,
"fe", 11]
},
"mac":{
"condition":["manufacturerdata", "=", 30],
Expand Down
62 changes: 62 additions & 0 deletions src/devices/SBHT_003C_ENCR_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const char* _SBHT_003C_ENCR_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T encrypted\",\"model_id\":\"SBHT-003C_ENCR\",\"tag\":\"010602\",\"condition\":[\"servicedata\",\"=\",36,\"index\",0,\"45\",\"|\",\"servicedata\",\"=\",40,\"index\",0,\"45\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"SBHT-003C\"],\"properties\":{\"cipher\":{\"condition\":[\"servicedata\",\"=\",36],\"decoder\":[\"string_from_hex_data\",\"servicedata\",2,18]},\"_cipher\":{\"condition\":[\"servicedata\",\"=\",40],\"decoder\":[\"string_from_hex_data\",\"servicedata\",2,22]},\"ctr\":{\"condition\":[\"servicedata\",\"=\",36],\"decoder\":[\"string_from_hex_data\",\"servicedata\",20,8]},\"_ctr\":{\"condition\":[\"servicedata\",\"=\",40],\"decoder\":[\"string_from_hex_data\",\"servicedata\",24,8]},\"mic\":{\"condition\":[\"servicedata\",\"=\",36],\"decoder\":[\"string_from_hex_data\",\"servicedata\",28,8]},\"_mic\":{\"condition\":[\"servicedata\",\"=\",40],\"decoder\":[\"string_from_hex_data\",\"servicedata\",32,8]},\"mac\":{\"condition\":[\"manufacturerdata\",\"=\",30],\"decoder\":[\"revmac_from_hex_data\",\"manufacturerdata\",18]}}}";
/*R""""(
{
"brand":"Shelly",
"model":"ShellyBLU H&T encrypted",
"model_id":"SBHT-003C_ENCR",
"tag":"010602",
"condition":["servicedata", "=", 36, "index", 0, "45", "|", "servicedata", "=", 40, "index", 0, "45", "&", "uuid", "index", 0, "fcd2", "&", "name", "index", 0, "SBHT-003C"],
"properties":{
"cipher":{
"condition":["servicedata", "=", 36],
"decoder":["string_from_hex_data", "servicedata", 2, 18]
},
"_cipher":{
"condition":["servicedata", "=", 40],
"decoder":["string_from_hex_data", "servicedata", 2, 22]
},
"ctr":{
"condition":["servicedata", "=", 36],
"decoder":["string_from_hex_data", "servicedata", 20, 8]
},
"_ctr":{
"condition":["servicedata", "=", 40],
"decoder":["string_from_hex_data", "servicedata", 24, 8]
},
"mic":{
"condition":["servicedata", "=", 36],
"decoder":["string_from_hex_data", "servicedata", 28, 8]
},
"_mic":{
"condition":["servicedata", "=", 40],
"decoder":["string_from_hex_data", "servicedata", 32, 8]
},
"mac":{
"condition":["manufacturerdata", "=", 30],
"decoder":["revmac_from_hex_data", "manufacturerdata", 18]
}
}
})"""";*/

const char* _SBHT_003C_ENCR_json_props = "{\"properties\":{\"cipher\":{\"unit\":\"hex\",\"name\":\"ciphertext\"},\"ctr\":{\"unit\":\"hex\",\"name\":\"counter\"},\"mic\":{\"unit\":\"hex\",\"name\":\"message integrity check\"},\"mac\":{\"unit\":\"string\",\"name\":\"MAC address\"}}}";
/*R""""(
{
"properties":{
"cipher":{
"unit":"hex",
"name":"ciphertext"
},
"ctr":{
"unit":"hex",
"name":"counter"
},
"mic":{
"unit":"hex",
"name":"message integrity check"
},
"mac":{
"unit":"string",
"name":"MAC address"
}
}
})"""";*/
74 changes: 74 additions & 0 deletions src/devices/SBHT_003C_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const char* _SBHT_003C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T\",\"model_id\":\"SBHT-003C\",\"tag\":\"0106\",\"condition\":[\"servicedata\",\"=\",20,\"index\",0,\"44\",\"|\",\"servicedata\",\"=\",24,\"index\",0,\"44\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"SBHT-003C\"],\"properties\":{\"packet\":{\"condition\":[\"servicedata\",2,\"00\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"batt\":{\"condition\":[\"servicedata\",6,\"01\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]},\"hum\":{\"condition\":[\"servicedata\",10,\"2e\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",12,2,false,false]},\"button\":{\"condition\":[\"servicedata\",14,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",16,2],\"lookup\":[\"01\",1,\"fe\",11]},\"tempc\":{\"condition\":[\"servicedata\",14,\"45\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",16,4,true,false],\"post_proc\":[\"/\",10]},\"_tempc\":{\"condition\":[\"servicedata\",18,\"45\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",20,4,true,false],\"post_proc\":[\"/\",10]},\"mac\":{\"condition\":[\"manufacturerdata\",\"=\",30],\"decoder\":[\"revmac_from_hex_data\",\"manufacturerdata\",18]}}}";
/*R""""(
{
"brand":"Shelly",
"model":"ShellyBLU H&T",
"model_id":"SBHT-003C",
"tag":"0106",
"condition":["servicedata", "=", 20, "index", 0, "44", "|", "servicedata", "=", 24, "index", 0, "44", "&", "uuid", "index", 0, "fcd2", "&", "name", "index", 0, "SBHT-003C"],
"properties":{
"packet":{
"condition":["servicedata", 2, "00"],
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false]
},
"batt":{
"condition":["servicedata", 6, "01"],
"decoder":["value_from_hex_data", "servicedata", 8, 2, false, false]
},
"hum":{
"condition":["servicedata", 10, "2e"],
"decoder":["value_from_hex_data", "servicedata", 12, 2, false, false]
},
"button":{
"condition":["servicedata", 14, "3a"],
"decoder":["string_from_hex_data", "servicedata", 16, 2],
"lookup":["01", 1,
"fe", 11]
},
"tempc":{
"condition":["servicedata", 14, "45"],
"decoder":["value_from_hex_data", "servicedata", 16, 4, true, false],
"post_proc":["/", 10]
},
"_tempc":{
"condition":["servicedata", 18, "45"],
"decoder":["value_from_hex_data", "servicedata", 20, 4, true, false],
"post_proc":["/", 10]
},
"mac":{
"condition":["manufacturerdata", "=", 30],
"decoder":["revmac_from_hex_data", "manufacturerdata", 18]
}
}
})"""";*/

const char* _SBHT_003C_json_props = "{\"properties\":{\"packet\":{\"unit\":\"int\",\"name\":\"packet id\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"},\"hum\":{\"unit\":\"%\",\"name\":\"humidity\"},\"button\":{\"unit\":\"int\",\"name\":\"button press type\"},\"tempc\":{\"unit\":\"°C\",\"name\":\"temperature\"},\"mac\":{\"unit\":\"string\",\"name\":\"MAC address\"}}}";
/*R""""(
{
"properties":{
"packet":{
"unit":"int",
"name":"packet id"
},
"batt":{
"unit":"%",
"name":"battery"
},
"hum":{
"unit":"%",
"name":"humidity"
},
"button":{
"unit":"int",
"name":"button press type"
},
"tempc":{
"unit":"°C",
"name":"temperature"
},
"mac":{
"unit":"string",
"name":"MAC address"
}
}
})"""";*/
21 changes: 21 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ const char* expected_name_mac_uuid_mfgsvcdata[] = {
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Motion\",\"model_id\":\"SBMO-003Z\",\"type\":\"CTMO\",\"acts\":true,\"cont\":true,\"packet\":2,\"batt\":100,\"lux\":132,\"motion\":true,\"mac\":\"60:EF:AB:AA:BB:CC\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Motion\",\"model_id\":\"SBMO-003Z\",\"type\":\"CTMO\",\"acts\":true,\"cont\":true,\"packet\":5,\"batt\":100,\"lux\":36,\"motion\":false,\"mac\":\"60:EF:AB:AA:BB:CC\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Motion encrypted\",\"model_id\":\"SBMO_003Z_ENCR\",\"type\":\"CTMO\",\"acts\":true,\"cont\":true,\"encr\":2,\"cipher\":\"cc08edf25d61cc0f42b6\",\"ctr\":\"00112233\",\"mic\":\"18cd3624\",\"mac\":\"60:EF:AB:AA:BB:CC\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T\",\"model_id\":\"SBHT-003C\",\"type\":\"THB\",\"acts\":true,\"cont\":true,\"packet\":78,\"batt\":100,\"hum\":63,\"tempc\":22.3,\"tempf\":72.14,\"mac\":\"AA:BB:CC:DD:EE:FF\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T\",\"model_id\":\"SBHT-003C\",\"type\":\"THB\",\"acts\":true,\"cont\":true,\"packet\":78,\"batt\":100,\"hum\":63,\"button\":1,\"tempc\":22.3,\"tempf\":72.14,\"mac\":\"AA:BB:CC:DD:EE:FF\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T\",\"model_id\":\"SBHT-003C\",\"type\":\"THB\",\"acts\":true,\"cont\":true,\"packet\":174,\"batt\":100,\"hum\":56,\"tempc\":25,\"tempf\":77,\"mac\":\"AA:BB:AA:BB:AA:BB\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T\",\"model_id\":\"SBHT-003C\",\"type\":\"THB\",\"acts\":true,\"cont\":true,\"packet\":174,\"batt\":100,\"hum\":56,\"button\":11,\"tempc\":25,\"tempf\":77,\"mac\":\"AA:BB:AA:BB:AA:BB\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T encrypted\",\"model_id\":\"SBHT-003C_ENCR\",\"type\":\"THB\",\"acts\":true,\"cont\":true,\"encr\":2,\"cipher\":\"e1a236ace4b4086167\",\"ctr\":\"4bfbd366\",\"mic\":\"8c080c2e\",\"mac\":\"AA:BB:CC:DD:EE:FF\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T encrypted\",\"model_id\":\"SBHT-003C_ENCR\",\"type\":\"THB\",\"acts\":true,\"cont\":true,\"encr\":2,\"cipher\":\"c85de27369ce3f84750015\",\"ctr\":\"aae9d466\",\"mic\":\"b801349b\",\"mac\":\"AA:BB:CC:DD:EE:FF\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU H&T encrypted\",\"model_id\":\"SBHT-003C_ENCR\",\"type\":\"THB\",\"acts\":true,\"cont\":true,\"encr\":2,\"cipher\":\"3a25e3518e72c92f6dfef8\",\"ctr\":\"e9e9d466\",\"mic\":\"96b53b8a\",\"mac\":\"AA:BB:CC:DD:EE:FF\"}",
};

const char* expected_uuid_name_svcdata[] = {
Expand Down Expand Up @@ -807,6 +814,13 @@ const char* test_name_mac_uuid_mfgsvcdata[][6] = {
{"SBMO-003Z", "60:EF:AB:AA:BB:CC", "SBMO-003Z", "0xfcd2", "a90b0101000b05000accbbaaabef60", "4400020164059033002101"},
{"SBMO-003Z", "60:EF:AB:AA:BB:CC", "SBMO-003Z", "0xfcd2", "a90b0101000b05000accbbaaabef60", "440005016405100e002100"},
{"SBMO-003Z encrypted", "60:EF:AB:AA:BB:CC", "SBMO-003Z", "0xfcd2", "a90b0101000b05000accbbaaabef60", "45cc08edf25d61cc0f42b60011223318cd3624"},
{"SBHT-003C", "AA:BB:CC:DD:EE:FF", "SBHT-003C", "0xfcd2", "a90b0111000b03000affeeddccbbaa", "44004e01642e3f45df00"},
{"SBHT-003C", "AA:BB:CC:DD:EE:FF", "SBHT-003C", "0xfcd2", "a90b0111000b03000affeeddccbbaa", "44004e01642e3f3a0145df00"},
{"SBHT-003C", "AA:BB:AA:BB:AA:BB", "SBHT-003C", "0xfcd2", "a90b0111000b03000abbaabbaabbaa", "4400ae01642e3845fa00"},
{"SBHT-003C", "AA:BB:AA:BB:AA:BB", "SBHT-003C", "0xfcd2", "a90b0111000b03000abbaabbaabbaa", "4400ae01642e383afe45fa00"},
{"SBHT-003C encrypted", "AA:BB:CC:DD:EE:FF", "SBHT-003C", "0xfcd2", "a90b0111000b03000affeeddccbbaa", "45e1a236ace4b40861674bfbd3668c080c2e"},
{"SBHT-003C encrypted", "AA:BB:CC:DD:EE:FF", "SBHT-003C", "0xfcd2", "a90b0111000b03000affeeddccbbaa", "45c85de27369ce3f84750015aae9d466b801349b"},
{"SBHT-003C encrypted", "AA:BB:CC:DD:EE:FF", "SBHT-003C", "0xfcd2", "a90b0111000b03000affeeddccbbaa", "453a25e3518e72c92f6dfef8e9e9d46696b53b8a"},
};

TheengsDecoder::BLE_ID_NUM test_name_mac_uuid_mfgsvcdata_id_num[]{
Expand All @@ -818,6 +832,13 @@ TheengsDecoder::BLE_ID_NUM test_name_mac_uuid_mfgsvcdata_id_num[]{
TheengsDecoder::BLE_ID_NUM::SBMO_003Z,
TheengsDecoder::BLE_ID_NUM::SBMO_003Z,
TheengsDecoder::BLE_ID_NUM::SBMO_003Z_ENCR,
TheengsDecoder::BLE_ID_NUM::SBHT_003C,
TheengsDecoder::BLE_ID_NUM::SBHT_003C,
TheengsDecoder::BLE_ID_NUM::SBHT_003C,
TheengsDecoder::BLE_ID_NUM::SBHT_003C,
TheengsDecoder::BLE_ID_NUM::SBHT_003C_ENCR,
TheengsDecoder::BLE_ID_NUM::SBHT_003C_ENCR,
TheengsDecoder::BLE_ID_NUM::SBHT_003C_ENCR,
};

// uuid name test input [test name] [uuid] [device name] [service data]
Expand Down

0 comments on commit 9856916

Please sign in to comment.