Skip to content

Commit 7496e66

Browse files
authored
Merge pull request #1328 from custom-components/XMPIRO2SXS
Add support for Xiaomi Human Body Sensor 2S (XMPIRO2SXS)
2 parents a82d31e + 8b93e95 commit 7496e66

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

custom_components/ble_monitor/ble_parser/xiaomi.py

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
0x11C2: "SV40",
7777
0x3F0F: "RS1BB",
7878
0x38BB: "PTX",
79+
0x3531: "XMPIRO2SXS",
7980
}
8081

8182
# Structured objects for data conversions

custom_components/ble_monitor/const.py

+2
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@ class BLEMonitorBinarySensorEntityDescription(
17801780
'K9BB-1BTN' : [["battery", "rssi"], ["one btn switch"], []],
17811781
'MS1BB(MI)' : [["battery", "rssi"], ["button"], ["opening"]],
17821782
'HS1BB(MI)' : [["illuminance", "battery", "rssi"], [], ["motion"]],
1783+
'XMPIRO2SXS' : [["illuminance", "battery", "rssi"], [], ["motion"]],
17831784
'XMWXKG01YL' : [["rssi"], ["two btn switch left", "two btn switch right"], []],
17841785
'XMWXKG01LM' : [["battery", "rssi"], ["one btn switch"], []],
17851786
'PTX' : [["battery", "rssi"], ["one btn switch"], []],
@@ -1894,6 +1895,7 @@ class BLEMonitorBinarySensorEntityDescription(
18941895
'XMZNMS04LM' : 'Xiaomi',
18951896
'XMZNMS08LM' : 'Xiaomi',
18961897
'MJZNZ018H' : 'Xiaomi',
1898+
'XMPIRO2SXS' : 'Xiaomi',
18971899
'ZX1' : '8H Sleep',
18981900
'CGC1' : 'Qingping',
18991901
'CGD1' : 'Qingping',

custom_components/ble_monitor/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
"btsocket>=0.2.0",
1515
"pyric>=0.1.6.3"
1616
],
17-
"version": "12.10.0"
17+
"version": "12.10.1"
1818
}

custom_components/ble_monitor/test/test_xiaomi_parser.py

+28
Original file line numberDiff line numberDiff line change
@@ -1064,3 +1064,31 @@ def test_Xiaomi_PTX(self):
10641064
assert sensor_msg["one btn switch"] == "toggle"
10651065
assert sensor_msg["button switch"] == "single press"
10661066
assert sensor_msg["rssi"] == -52
1067+
1068+
def test_Xiaomi_XMPIRO2SXS(self):
1069+
"""Test Xiaomi parser for XMPIRO2SXS."""
1070+
self.aeskeys = {}
1071+
data_string = "043E260201000043ea2d958edc1a020106161695fe485931350b64799117331ef4020000c5d2f6acCC"
1072+
data = bytes(bytearray.fromhex(data_string))
1073+
1074+
aeskey = "685d647dc5e7bc9bcfcf5a1357bd2114"
1075+
1076+
is_ext_packet = True if data[3] == 0x0D else False
1077+
mac = (data[8 if is_ext_packet else 7:14 if is_ext_packet else 13])[::-1]
1078+
mac_address = mac.hex()
1079+
p_mac = bytes.fromhex(mac_address.replace(":", "").lower())
1080+
p_key = bytes.fromhex(aeskey.lower())
1081+
self.aeskeys[p_mac] = p_key
1082+
# pylint: disable=unused-variable
1083+
ble_parser = BleParser(aeskeys=self.aeskeys)
1084+
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)
1085+
1086+
assert sensor_msg["firmware"] == "Xiaomi (MiBeacon V5 encrypted)"
1087+
assert sensor_msg["type"] == "XMPIRO2SXS"
1088+
assert sensor_msg["mac"] == "DC8E952DEA43"
1089+
assert sensor_msg["packet"] == 11
1090+
assert sensor_msg["data"]
1091+
assert sensor_msg["motion"] == 1
1092+
assert sensor_msg["motion timer"] == 1
1093+
assert sensor_msg["illuminance"] == 51.0
1094+
assert sensor_msg["rssi"] == -52

docs/_devices/Xiaomi_XMPIRO2SXS.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
manufacturer: Xiaomi
3+
name: Xiaomi Human Body Sensor 2S
4+
model: XMPIRO2SXS
5+
image: XMPIRO2SXS.png
6+
physical_description:
7+
broadcasted_properties:
8+
- illuminance
9+
- motion
10+
- battery
11+
- rssi
12+
broadcasted_property_notes:
13+
- property: illuminance
14+
note: is measured in lux.
15+
- property: motion
16+
note: Motion state is ‘motion detected’ or ‘clear’.
17+
broadcast_rate:
18+
active_scan:
19+
encryption_key: True
20+
custom_firmware:
21+
notes: >
22+
- You can use the [reset_timer](configuration_params#reset_timer) option if you want to use a different time to set the sensor to `motion clear`.
23+
---

docs/assets/images/XMPIRO2SXS.png

9.81 KB
Loading

0 commit comments

Comments
 (0)