Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/switchbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
SupportedModels.HYGROMETER_CO2.value: [Platform.SENSOR],
SupportedModels.CONTACT.value: [Platform.BINARY_SENSOR, Platform.SENSOR],
SupportedModels.MOTION.value: [Platform.BINARY_SENSOR, Platform.SENSOR],
SupportedModels.PRESENCE_SENSOR.value: [Platform.BINARY_SENSOR, Platform.SENSOR],
SupportedModels.HUMIDIFIER.value: [Platform.HUMIDIFIER, Platform.SENSOR],
SupportedModels.LOCK.value: [
Platform.BINARY_SENSOR,
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/switchbot/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

from switchbot import SwitchbotModel

from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
Expand Down Expand Up @@ -98,6 +100,12 @@ def __init__(
self._sensor = binary_sensor
self._attr_unique_id = f"{coordinator.base_unique_id}-{binary_sensor}"
self.entity_description = BINARY_SENSOR_TYPES[binary_sensor]
# Presence sensors should use occupancy device class instead of motion
if (
binary_sensor == "motion_detected"
and coordinator.model == SwitchbotModel.PRESENCE_SENSOR
):
self._attr_device_class = BinarySensorDeviceClass.OCCUPANCY
Comment on lines +103 to +108
Copy link
Author

@lukasmalkmus lukasmalkmus Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this bit but I didn't want to interfere with existing sensors by changing this, globally.

Copy link

@borgqueenx borgqueenx Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say the light sensor can be called that as well. Unfortunately no lux values so not a lux sensor, but still a light level sensor. Just trying to help out with correct labeling, hope it can be merged soon, bought 7 of these in the hope they were supported, but they were not (yet). Haha.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, this might not just be the labeling, which is why I was careful.

And yes, same mistake. Bought a bunch just to find out they are not (yet) compatible, lol 🤦


@property
def is_on(self) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/switchbot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SupportedModels(StrEnum):
CONTACT = "contact"
PLUG = "plug"
MOTION = "motion"
PRESENCE_SENSOR = "presence_sensor"
HUMIDIFIER = "humidifier"
LOCK = "lock"
LOCK_PRO = "lock_pro"
Expand Down Expand Up @@ -108,6 +109,7 @@ class SupportedModels(StrEnum):
SwitchbotModel.METER_PRO_C: SupportedModels.HYGROMETER_CO2,
SwitchbotModel.CONTACT_SENSOR: SupportedModels.CONTACT,
SwitchbotModel.MOTION_SENSOR: SupportedModels.MOTION,
SwitchbotModel.PRESENCE_SENSOR: SupportedModels.PRESENCE_SENSOR,
SwitchbotModel.LEAK: SupportedModels.LEAK,
SwitchbotModel.REMOTE: SupportedModels.REMOTE,
SwitchbotModel.HUBMINI_MATTER: SupportedModels.HUBMINI_MATTER,
Expand Down
25 changes: 25 additions & 0 deletions tests/components/switchbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,3 +1248,28 @@ def make_advertisement(
connectable=True,
tx_power=-127,
)


PRESENCE_SENSOR_SERVICE_INFO = BluetoothServiceInfoBleak(
name="Presence Sensor",
manufacturer_data={2409: b"\xb0\xe9\xfe\xb8r\x9c\xbe\xcc\x00\x1a\x00\x82"},
service_data={
"0000fd3d-0000-1000-8000-00805f9b34fb": b"\x00 d\x00\x10\xcc\xc8",
},
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
address="AA:BB:CC:DD:EE:FF",
rssi=-60,
source="local",
advertisement=generate_advertisement_data(
local_name="Presence Sensor",
manufacturer_data={2409: b"\xb0\xe9\xfe\xb8r\x9c\xbe\xcc\x00\x1a\x00\x82"},
service_data={
"0000fd3d-0000-1000-8000-00805f9b34fb": b"\x00 d\x00\x10\xcc\xc8"
},
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
),
device=generate_ble_device("AA:BB:CC:DD:EE:FF", "Presence Sensor"),
time=0,
connectable=False,
tx_power=-127,
)
55 changes: 55 additions & 0 deletions tests/components/switchbot/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
HUBMINI_MATTER_SERVICE_INFO,
LEAK_SERVICE_INFO,
PLUG_MINI_EU_SERVICE_INFO,
PRESENCE_SENSOR_SERVICE_INFO,
RELAY_SWITCH_2PM_SERVICE_INFO,
REMOTE_SERVICE_INFO,
WOHAND_SERVICE_INFO,
Expand Down Expand Up @@ -793,3 +794,57 @@ async def test_climate_panel_sensor(hass: HomeAssistant) -> None:

assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_presence_sensor(hass: HomeAssistant) -> None:
"""Test setting up creates the sensors for Presence Sensor."""
await async_setup_component(hass, DOMAIN, {})
inject_bluetooth_service_info(hass, PRESENCE_SENSOR_SERVICE_INFO)

entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_ADDRESS: "AA:BB:CC:DD:EE:FF",
CONF_NAME: "test-name",
CONF_SENSOR_TYPE: "presence_sensor",
},
unique_id="aabbccddeeff",
)
entry.add_to_hass(hass)

assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert len(hass.states.async_all("sensor")) == 3
assert len(hass.states.async_all("binary_sensor")) == 2

battery_sensor = hass.states.get("sensor.test_name_battery")
battery_sensor_attrs = battery_sensor.attributes
assert battery_sensor
assert battery_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Battery"
assert battery_sensor_attrs[ATTR_STATE_CLASS] == "measurement"

light_level_sensor = hass.states.get("sensor.test_name_light_level")
light_level_sensor_attrs = light_level_sensor.attributes
assert light_level_sensor
assert light_level_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Light level"

rssi_sensor = hass.states.get("sensor.test_name_bluetooth_signal")
rssi_sensor_attrs = rssi_sensor.attributes
assert rssi_sensor
assert rssi_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Bluetooth signal"
assert rssi_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "dBm"

light_sensor = hass.states.get("binary_sensor.test_name_light")
light_sensor_attrs = light_sensor.attributes
assert light_sensor
assert light_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Light"

motion_sensor = hass.states.get("binary_sensor.test_name_motion")
motion_sensor_attrs = motion_sensor.attributes
assert motion_sensor
assert motion_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Motion"

assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()