Skip to content

Commit

Permalink
SwitchBot Contact Sensor (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiH authored Jul 12, 2022
1 parent f903849 commit 0988f08
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = {
'devices/RDL52832',
'devices/RuuviTag_RAWv1',
'devices/RuuviTag_RAWv2',
'devices/SBCS',
'devices/SBCU',
'devices/SBMS',
'devices/SBMT',
Expand Down
12 changes: 12 additions & 0 deletions docs/devices/SBCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SwitchBot Contact Sensor

|Model Id|[W120150X](https://github.com/theengs/decoder/blob/development/src/devices/SBCS_json.h)|
|-|-|
|Brand|SwitchBot|
|Model|Contact Sensor|
|Short Description|Contact sensor|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power source|2 AAA|
|Exchanged data|contact, movement, light level, scope tested, battery|
|Encrypted|No|
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TheengsDecoder {
IBT_2X,
RUUVITAG_RAWV1,
RUUVITAG_RAWV2,
SBCS,
SBCU,
SBMS,
SBMT,
Expand Down
2 changes: 2 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "devices/RDL52832_json.h"
#include "devices/RuuviTag_RAWv1_json.h"
#include "devices/RuuviTag_RAWv2_json.h"
#include "devices/SBCS_json.h"
#include "devices/SBCU_json.h"
#include "devices/SBMS_json.h"
#include "devices/SBMT_json.h"
Expand Down Expand Up @@ -100,6 +101,7 @@ const char* _devices[][2] = {
{_IBT_2X_json, _IBT_2X_json_props},
{_RuuviTag_RAWv1_json, _RuuviTag_RAWv1_json_props},
{_RuuviTag_RAWv2_json, _RuuviTag_RAWv2_json_props},
{_SBCS_json, _SBCS_json_props},
{_SBCU_json, _SBCU_json_props},
{_SBMS_json, _SBMS_json_props},
{_SBMT_json, _SBMT_json_props},
Expand Down
64 changes: 64 additions & 0 deletions src/devices/SBCS_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const char* _SBCS_json = "{\"brand\":\"SwitchBot\",\"model\":\"Contact Sensor\",\"model_id\":\"W120150X\",\"condition\":[\"servicedata\",\"=\",18,\"index\",0,\"64\",\"&\",\"uuid\",\"index\",0,\"0d00\"],\"properties\":{\"contact\":{\"condition\":[\"servicedata\",7,\"bit\",2,0],\"decoder\":[\"bit_static_value\",\"servicedata\",7,1,\"closed\",\"open\"]},\"_contact\":{\"condition\":[\"servicedata\",7,\"bit\",2,1],\"decoder\":[\"static_value\",\"timeout not closed\"]},\"movement\":{\"decoder\":[\"bit_static_value\",\"servicedata\",2,2,false,true]},\"lightlevel\":{\"decoder\":[\"bit_static_value\",\"servicedata\",7,0,\"dark\",\"bright\"]},\"scopetested\":{\"condition\":[\"servicedata\",2,\"bit\",3,0],\"decoder\":[\"static_value\",false]},\"batt\":{\"condition\":[\"servicedata\",4,\"bit\",3,0],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"_batt\":{\"condition\":[\"servicedata\",4,\"bit\",3,1],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false],\"post_proc\":[\"-\",128]}}}";
/*R""""(
{
"brand":"SwitchBot",
"model":"Contact Sensor",
"model_id":"W120150X",
"condition":["servicedata", "=", 18, "index", 0, "64", "&", "uuid", "index", 0, "0d00"],
"properties":{
"contact":{
"condition":["servicedata", 7, "bit", 2, 0],
"decoder":["bit_static_value", "servicedata", 7, 1, "closed", "open"]
},
"_contact":{
"condition":["servicedata", 7, "bit", 2, 1],
"decoder":["static_value", "timeout not closed"]
},
"movement":{
"decoder":["bit_static_value", "servicedata", 2, 2, false, true]
},
"lightlevel":{
"decoder":["bit_static_value", "servicedata", 7, 0, "dark", "bright"]
},
"scopetested":{
"condition":["servicedata", 2, "bit", 3, 0],
"decoder":["static_value", false]
},
"batt":{
"condition":["servicedata", 4, "bit", 3, 0],
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false]
},
"_batt":{
"condition":["servicedata", 4, "bit", 3, 1],
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false],
"post_proc":["-", 128]
}
}
})"""";*/

const char* _SBCS_json_props = "{\"properties\":{\"contact\":{\"unit\":\"string\",\"name\":\"contact\"},\"movement\":{\"unit\":\"status\",\"name\":\"movement\"},\"lightlevel\":{\"unit\":\"string\",\"name\":\"light level\"},\"scopetested\":{\"unit\":\"status\",\"name\":\"scope tested\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"}}}";
/*R""""(
{
"properties":{
"contact":{
"unit":"string",
"name":"contact"
},
"movement":{
"unit":"status",
"name":"movement"
},
"lightlevel":{
"unit":"string",
"name":"light level"
},
"scopetested":{
"unit":"status",
"name":"scope tested"
},
"batt":{
"unit":"%",
"name":"battery"
}
}
})"""";*/
9 changes: 9 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ const char* expected_uuid[] = {
"{\"brand\":\"Xiaomi/VegTrug\",\"model\":\"MiFlora\",\"model_id\":\"HHCCJCY01HHCC\",\"tempc\":32,\"tempf\":89.6}",
"{\"brand\":\"SwitchBot\",\"model\":\"Motion Sensor\",\"model_id\":\"W110150X\",\"movement\":false,\"led\":false,\"sensingdistance\":\"middle\",\"lightlevel\":\"dark\",\"batt\":55}",
"{\"brand\":\"SwitchBot\",\"model\":\"Motion Sensor\",\"model_id\":\"W110150X\",\"movement\":true,\"led\":true,\"scopetested\":false,\"sensingdistance\":\"long\",\"lightlevel\":\"bright\",\"batt\":85}",
"{\"brand\":\"SwitchBot\",\"model\":\"Contact Sensor\",\"model_id\":\"W120150X\",\"contact\":\"closed\",\"movement\":true,\"lightlevel\":\"bright\",\"batt\":92}",
"{\"brand\":\"SwitchBot\",\"model\":\"Contact Sensor\",\"model_id\":\"W120150X\",\"contact\":\"open\",\"movement\":false,\"lightlevel\":\"dark\",\"batt\":87}",
"{\"brand\":\"SwitchBot\",\"model\":\"Contact Sensor\",\"model_id\":\"W120150X\",\"contact\":\"timeout not closed\",\"movement\":true,\"lightlevel\":\"bright\",\"scopetested\":false,\"batt\":65}",
};

// Service data test input [test name] [data]
Expand Down Expand Up @@ -377,6 +380,9 @@ const char* test_uuid[][4] = {
{"VegTrug flora", "fe95", "servicedata", "7120bc030163b6658d7cc40d0410024001"},
{"Switchbot_MotionSensor", "0d00", "servicedata", "73b037000045"},
{"Switchbot_MotionSensor", "0d00", "servicedata", "7340d50000f2"},
{"Switchbot_Contact", "0d00", "servicedata", "64c05c010000000000"},
{"Switchbot_Contact", "0d00", "servicedata", "6480d7020000000000"},
{"Switchbot_Contact", "0d00", "servicedata", "6440c1050000000000"},
};

TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
Expand Down Expand Up @@ -429,6 +435,9 @@ TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
TheengsDecoder::BLE_ID_NUM::HHCCJCY01HHCC,
TheengsDecoder::BLE_ID_NUM::SBMS,
TheengsDecoder::BLE_ID_NUM::SBMS,
TheengsDecoder::BLE_ID_NUM::SBCS,
TheengsDecoder::BLE_ID_NUM::SBCS,
TheengsDecoder::BLE_ID_NUM::SBCS,
};

template <typename T>
Expand Down

0 comments on commit 0988f08

Please sign in to comment.