diff --git a/custom_components/ble_monitor/ble_parser/xiaomi.py b/custom_components/ble_monitor/ble_parser/xiaomi.py index 52ba55c9..5005744e 100755 --- a/custom_components/ble_monitor/ble_parser/xiaomi.py +++ b/custom_components/ble_monitor/ble_parser/xiaomi.py @@ -78,6 +78,8 @@ 0x38BB: "PTX", 0x3531: "XMPIRO2SXS", 0x3F4C: "PS1BB", + 0x3A61: "KS1", + 0x3E17: "KS1BP", } # Structured objects for data conversions @@ -700,6 +702,13 @@ def obj3003(xobj): # The following data objects are device specific. For now only added for # LYWSD02MMC, XMWSDJ04MMC, MJWSD05MMC, XMWXKG01YL, LINPTECH MS1BB(MI), HS1BB(MI), K9BB # https://miot-spec.org/miot-spec-v2/instances?status=all + +def obj4801(xobj): + """Temperature""" + (temp,) = struct.unpack("f", xobj) + return {"temperature": temp} + + def obj4803(xobj): """Battery""" batt = xobj[0] @@ -731,6 +740,12 @@ def obj4806(xobj): return {"moisture detected": wet} +def obj4808(xobj): + """Humidity""" + (humi,) = struct.unpack("f", xobj) + return {"humidity": humi} + + def obj4810(xobj): """Sleep State""" sleep_state = xobj[0] @@ -1050,6 +1065,12 @@ def obj4e1c(xobj): return {"device reset": xobj[0]} +def obj5003(xobj): + """Battery""" + batt = xobj[0] + return {"battery": batt} + + def obj5010(xobj): """Sleep State""" sleep_state = xobj[0] @@ -1073,12 +1094,111 @@ def obj5403(xobj): return {"battery": xobj[0]} +def obj5414(xobj): + """Mode""" + mode = xobj[0] + return {"mode": mode} + + def obj5601(xobj): """Low Battery""" low_batt = xobj[0] return {"low battery": low_batt} +def obj560c(xobj, device_type): + """Click""" + if device_type in ["KS1", "KS1BP"]: + click = xobj[0] + if click == 1: + result = { + "four btn switch 1": "toggle", + "button switch": "single press", + } + elif click == 2: + result = { + "four btn switch 2": "toggle", + "button switch": "single press", + } + elif click == 3: + result = { + "four btn switch 3": "toggle", + "button switch": "single press", + } + elif click == 4: + result = { + "four btn switch 4": "toggle", + "button switch": "single press", + } + else: + result = None + return result + else: + return None + + +def obj560d(xobj, device_type): + """Click""" + if device_type in ["KS1", "KS1BP"]: + click = xobj[0] + if click == 1: + result = { + "four btn switch 1": "toggle", + "button switch": "double press", + } + elif click == 2: + result = { + "four btn switch 2": "toggle", + "button switch": "double press", + } + elif click == 3: + result = { + "four btn switch 3": "toggle", + "button switch": "double press", + } + elif click == 4: + result = { + "four btn switch 4": "toggle", + "button switch": "double press", + } + else: + result = None + return result + else: + return None + + +def obj560e(xobj, device_type): + """Click""" + if device_type in ["KS1", "KS1BP"]: + click = xobj[0] + if click == 1: + result = { + "four btn switch 1": "toggle", + "button switch": "long press", + } + elif click == 2: + result = { + "four btn switch 2": "toggle", + "button switch": "long press", + } + elif click == 3: + result = { + "four btn switch 3": "toggle", + "button switch": "long press", + } + elif click == 4: + result = { + "four btn switch 4": "toggle", + "button switch": "long press", + } + else: + result = None + return result + else: + return None + + def obj5a16(xobj): """Bed occupancy""" event = xobj[0] @@ -1124,10 +1244,12 @@ def obj5a16(xobj): 0x100E: obj100e, 0x2000: obj2000, 0x3003: obj3003, + 0x4801: obj4801, 0x4803: obj4803, 0x4804: obj4804, 0x4805: obj4805, 0x4806: obj4806, + 0x4808: obj4808, 0x4810: obj4810, 0x4811: obj4811, 0x4818: obj4818, @@ -1158,10 +1280,15 @@ def obj5a16(xobj): 0x4e16: obj4e16, 0x4e17: obj4e17, 0x4e1c: obj4e1c, + 0x5003: obj5003, 0x5010: obj5010, 0x5011: obj5011, 0x5403: obj5403, + 0x5414: obj5414, 0x5601: obj5601, + 0x560c: obj560c, + 0x560d: obj560d, + 0x560e: obj560e, 0x5a16: obj5a16, } diff --git a/custom_components/ble_monitor/const.py b/custom_components/ble_monitor/const.py index 2610685b..38ddf5d7 100755 --- a/custom_components/ble_monitor/const.py +++ b/custom_components/ble_monitor/const.py @@ -1722,6 +1722,50 @@ class BLEMonitorBinarySensorEntityDescription( device_class=None, state_class=None, ), + BLEMonitorSensorEntityDescription( + key="four btn switch 1", + sensor_class="SwitchSensor", + update_behavior="Instantly", + name="ble four button switch 1", + unique_id="btn_switch_1_", + icon="mdi:gesture-tap-button", + native_unit_of_measurement=None, + device_class=None, + state_class=None, + ), + BLEMonitorSensorEntityDescription( + key="four btn switch 2", + sensor_class="SwitchSensor", + update_behavior="Instantly", + name="ble four button switch 2", + unique_id="btn_switch_2_", + icon="mdi:gesture-tap-button", + native_unit_of_measurement=None, + device_class=None, + state_class=None, + ), + BLEMonitorSensorEntityDescription( + key="four btn switch 3", + sensor_class="SwitchSensor", + update_behavior="Instantly", + name="ble four button switch 3", + unique_id="btn_switch_3_", + icon="mdi:gesture-tap-button", + native_unit_of_measurement=None, + device_class=None, + state_class=None, + ), + BLEMonitorSensorEntityDescription( + key="four btn switch 4", + sensor_class="SwitchSensor", + update_behavior="Instantly", + name="ble four button switch 4", + unique_id="btn_switch_4_", + icon="mdi:gesture-tap-button", + native_unit_of_measurement=None, + device_class=None, + state_class=None, + ), BLEMonitorSensorEntityDescription( key="remote", sensor_class="BaseRemoteSensor", @@ -1849,6 +1893,8 @@ class BLEMonitorBinarySensorEntityDescription( 'MS1BB(MI)' : [["battery", "rssi"], ["button"], ["opening"]], 'HS1BB(MI)' : [["illuminance", "battery", "rssi"], [], ["motion"]], 'PS1BB' : [["battery", "rssi", "pressure present duration", "pressure not present duration", "pressure present time set", "pressure not present time set"], [], ["reset", "pressure state"]], + 'KS1' : [["battery", "rssi"], ["four btn switch 1", "four btn switch 2", "four btn switch 3", "four btn switch 4"], []], + 'KS1BP' : [["temperature", "humidity", "battery", "rssi"], ["four btn switch 1", "four btn switch 2", "four btn switch 3", "four btn switch 4"], []], 'XMPIRO2SXS' : [["illuminance", "battery", "rssi"], [], ["motion"]], 'XMWXKG01YL' : [["rssi"], ["two btn switch left", "two btn switch right"], []], 'XMWXKG01LM' : [["battery", "rssi"], ["one btn switch"], []], @@ -1989,6 +2035,8 @@ class BLEMonitorBinarySensorEntityDescription( 'MS1BB(MI)' : 'Linptech', 'HS1BB(MI)' : 'Linptech', 'PS1BB' : 'Linptech', + 'KS1' : 'Linptech', + 'KS1BP' : 'Linptech', 'XMWXKG01YL' : 'Xiaomi', 'XMWXKG01LM' : 'Xiaomi', 'PTX' : 'Xiaomi', diff --git a/custom_components/ble_monitor/sensor.py b/custom_components/ble_monitor/sensor.py index fcf1bd18..1b0b13ad 100644 --- a/custom_components/ble_monitor/sensor.py +++ b/custom_components/ble_monitor/sensor.py @@ -395,6 +395,10 @@ class BaseSensor(RestoreSensor, SensorEntity): # | | |**three btn switch left # | | |**three btn switch middle # | | |**three btn switch right + # | | |**four btn switch 1 + # | | |**four btn switch 2 + # | | |**four btn switch 3 + # | | |**four btn switch 4 # | |--BaseRemoteSensor (Class) # | | |**remote # | | |**fan remote diff --git a/docs/_devices/Linptech_KS1.md b/docs/_devices/Linptech_KS1.md new file mode 100644 index 00000000..97673a65 --- /dev/null +++ b/docs/_devices/Linptech_KS1.md @@ -0,0 +1,30 @@ +--- +manufacturer: Linptech +name: Smart Wireless Switch KS1 +model: KS1 +image: Linptech_KS1.png +physical_description: +broadcasted_properties: + - four btn switch 1 + - four btn switch 2 + - four btn switch 3 + - four btn switch 4 + - battery + - rssi +broadcasted_property_notes: + - property: four btn switch 1 + note: returns 'short press', 'double press' or 'long press' + - property: four btn switch 2 + note: returns 'short press', 'double press' or 'long press' + - property: four btn switch 3 + note: returns 'short press', 'double press' or 'long press' + - property: four btn switch 4 + note: returns 'short press', 'double press' or 'long press' +broadcast_rate: +active_scan: +encryption_key: Probably (not confirmed yet) +custom_firmware: +notes: + - There are two different versions of this switch, without temperature/humidity (KS1) and with temperature/humidity (KS1). + - The switch sensor state will return to `no press` after the time set with the [reset_timer](configuration_params#reset_timer) option. It is advised to change the reset time to 1 second (default = 35 seconds). +--- diff --git a/docs/_devices/Linptech_KS1BP.md b/docs/_devices/Linptech_KS1BP.md new file mode 100644 index 00000000..04d60349 --- /dev/null +++ b/docs/_devices/Linptech_KS1BP.md @@ -0,0 +1,32 @@ +--- +manufacturer: Linptech +name: Smart Wireless Switch KS1 Pro +model: KS1BP +image: Linptech_KS1BP.png +physical_description: +broadcasted_properties: + - temperature + - humidity + - four btn switch 1 + - four btn switch 2 + - four btn switch 3 + - four btn switch 4 + - battery + - rssi +broadcasted_property_notes: + - property: four btn switch 1 + note: returns 'short press', 'double press' or 'long press' + - property: four btn switch 2 + note: returns 'short press', 'double press' or 'long press' + - property: four btn switch 3 + note: returns 'short press', 'double press' or 'long press' + - property: four btn switch 4 + note: returns 'short press', 'double press' or 'long press' +broadcast_rate: +active_scan: +encryption_key: Probably (not confirmed yet) +custom_firmware: +notes: + - There are two different versions of this switch, without temperature/humidity (KS1) and with temperature/humidity (KS1BP). + - The switch sensor state will return to `no press` after the time set with the [reset_timer](configuration_params#reset_timer) option. It is advised to change the reset time to 1 second (default = 35 seconds). +--- diff --git a/docs/assets/images/Linptech_KS1.png b/docs/assets/images/Linptech_KS1.png new file mode 100644 index 00000000..986e47b4 Binary files /dev/null and b/docs/assets/images/Linptech_KS1.png differ diff --git a/docs/assets/images/Linptech_KS1BP.png b/docs/assets/images/Linptech_KS1BP.png new file mode 100644 index 00000000..9d356d9a Binary files /dev/null and b/docs/assets/images/Linptech_KS1BP.png differ