diff --git a/homeassistant/components/hue/v2/binary_sensor.py b/homeassistant/components/hue/v2/binary_sensor.py index da28fd1f6a9..7b7717cbf76 100644 --- a/homeassistant/components/hue/v2/binary_sensor.py +++ b/homeassistant/components/hue/v2/binary_sensor.py @@ -145,7 +145,11 @@ class HueMotionSensor(HueBaseEntity, BinarySensorEntity): if not self.resource.enabled: # Force None (unknown) if the sensor is set to disabled in Hue return None - return self.resource.motion.value + if not (motion_feature := self.resource.motion): + return None + if motion_feature.motion_report is not None: + return motion_feature.motion_report.motion + return motion_feature.motion # pylint: disable-next=hass-enforce-class-module diff --git a/tests/components/hue/test_binary_sensor.py b/tests/components/hue/test_binary_sensor.py index 02b4d93acfe..8fc2043d45a 100644 --- a/tests/components/hue/test_binary_sensor.py +++ b/tests/components/hue/test_binary_sensor.py @@ -123,6 +123,29 @@ async def test_binary_sensor_add_update( test_entity = hass.states.get(test_entity_id) assert test_entity is not None assert test_entity.state == "on" + # NEW: prefer motion_report.motion when present (should turn on even if plain motion is False) + updated_sensor = { + **FAKE_BINARY_SENSOR, + "motion": { + "motion": False, + "motion_report": {"changed": "2025-01-01T00:00:00Z", "motion": True}, + }, + } + mock_bridge_v2.api.emit_event("update", updated_sensor) + await hass.async_block_till_done() + assert hass.states.get(test_entity_id).state == "on" + + # NEW: motion_report False should turn it off (even if plain motion is True) + updated_sensor = { + **FAKE_BINARY_SENSOR, + "motion": { + "motion": True, + "motion_report": {"changed": "2025-01-01T00:00:01Z", "motion": False}, + }, + } + mock_bridge_v2.api.emit_event("update", updated_sensor) + await hass.async_block_till_done() + assert hass.states.get(test_entity_id).state == "off" async def test_grouped_motion_sensor(