Skip to content

Commit

Permalink
Add Linptech KS1 en KS1BP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernst79 committed Jul 6, 2024
1 parent ea9868f commit b6a9fd2
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 0 deletions.
127 changes: 127 additions & 0 deletions custom_components/ble_monitor/ble_parser/xiaomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
0x38BB: "PTX",
0x3531: "XMPIRO2SXS",
0x3F4C: "PS1BB",
0x3A61: "KS1",
0x3E17: "KS1BP",
}

# Structured objects for data conversions
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}

Expand Down
48 changes: 48 additions & 0 deletions custom_components/ble_monitor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"], []],
Expand Down Expand Up @@ -1989,6 +2035,8 @@ class BLEMonitorBinarySensorEntityDescription(
'MS1BB(MI)' : 'Linptech',
'HS1BB(MI)' : 'Linptech',
'PS1BB' : 'Linptech',
'KS1' : 'Linptech',
'KS1BP' : 'Linptech',
'XMWXKG01YL' : 'Xiaomi',
'XMWXKG01LM' : 'Xiaomi',
'PTX' : 'Xiaomi',
Expand Down
4 changes: 4 additions & 0 deletions custom_components/ble_monitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions docs/_devices/Linptech_KS1.md
Original file line number Diff line number Diff line change
@@ -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).
---
32 changes: 32 additions & 0 deletions docs/_devices/Linptech_KS1BP.md
Original file line number Diff line number Diff line change
@@ -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).
---
Binary file added docs/assets/images/Linptech_KS1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/Linptech_KS1BP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6a9fd2

Please sign in to comment.