diff --git a/homeassistant/components/logbook/helpers.py b/homeassistant/components/logbook/helpers.py index cc9ea238f8b..de021994b8d 100644 --- a/homeassistant/components/logbook/helpers.py +++ b/homeassistant/components/logbook/helpers.py @@ -132,6 +132,12 @@ def async_subscribe_events( if not _is_state_filtered(ent_reg, state): target(event) + if device_ids and not entity_ids: + # No entities to subscribe to but we are filtering + # on device ids so we do not want to get any state + # changed events + return + if entity_ids: subscriptions.append( async_track_state_change_event( diff --git a/tests/components/logbook/test_websocket_api.py b/tests/components/logbook/test_websocket_api.py index 1d35d6d897d..291c487b35b 100644 --- a/tests/components/logbook/test_websocket_api.py +++ b/tests/components/logbook/test_websocket_api.py @@ -1743,6 +1743,8 @@ async def test_subscribe_unsubscribe_logbook_stream_device( assert msg["type"] == "event" assert msg["event"]["events"] == [] + hass.states.async_set("binary_sensor.should_not_appear", STATE_ON) + hass.states.async_set("binary_sensor.should_not_appear", STATE_OFF) hass.bus.async_fire("mock_event", {"device_id": device.id}) await hass.async_block_till_done()