diff --git a/homeassistant/components/shelly/binary_sensor.py b/homeassistant/components/shelly/binary_sensor.py index 1474906cacb..a5889cd11a7 100644 --- a/homeassistant/components/shelly/binary_sensor.py +++ b/homeassistant/components/shelly/binary_sensor.py @@ -164,6 +164,14 @@ RPC_SENSORS: Final = { entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, ), + "external_power": RpcBinarySensorDescription( + key="devicepower:0", + sub_key="external", + name="External power", + value=lambda status, _: status["present"], + device_class=BinarySensorDeviceClass.POWER, + entity_category=EntityCategory.DIAGNOSTIC, + ), "overtemp": RpcBinarySensorDescription( key="switch", sub_key="errors", diff --git a/tests/components/shelly/conftest.py b/tests/components/shelly/conftest.py index 2a80233aeb9..96e888d7509 100644 --- a/tests/components/shelly/conftest.py +++ b/tests/components/shelly/conftest.py @@ -189,6 +189,7 @@ MOCK_STATUS_RPC = { "current_pos": 50, "apower": 85.3, }, + "devicepower:0": {"external": {"present": True}}, "temperature:0": {"tC": 22.9}, "illuminance:0": {"lux": 345}, "sys": { diff --git a/tests/components/shelly/test_binary_sensor.py b/tests/components/shelly/test_binary_sensor.py index 207b73bf44b..c067f5dffc9 100644 --- a/tests/components/shelly/test_binary_sensor.py +++ b/tests/components/shelly/test_binary_sensor.py @@ -218,6 +218,11 @@ async def test_rpc_sleeping_binary_sensor( assert hass.states.get(entity_id).state == STATE_ON + # test external power sensor + state = hass.states.get("binary_sensor.test_name_external_power") + assert state + assert state.state == STATE_ON + async def test_rpc_restored_sleeping_binary_sensor( hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch