home-assistant/core · error · ValueError
Device not found: {subdevice!r}
Error message
Device not found: {subdevice!r} What it means
Raised as ValueError when async_delete_command is called with a subdevice key that does not exist in the internally stored codes dictionary (self._codes). The integration only stores codes keyed by subdevice name, so deleting commands for an unknown subdevice is rejected. Logged via _LOGGER.error before the raise.
Source
Thrown at homeassistant/components/broadlink/remote.py:463
service = f"{RM_DOMAIN}.{SERVICE_DELETE_COMMAND}"
if not self._attr_is_on:
_LOGGER.warning(
"%s canceled: %s entity is turned off",
service,
self.entity_id,
)
return
if not self._storage_loaded:
await self._async_load_storage()
try:
codes = self._codes[subdevice]
except KeyError as err:
err_msg = f"Device not found: {subdevice!r}"
_LOGGER.error("Failed to call %s. %s", service, err_msg)
raise ValueError(err_msg) from err
cmds_not_found = []
for command in commands:
try:
del codes[command]
except KeyError:
cmds_not_found.append(command)
if cmds_not_found:
if len(cmds_not_found) == 1:
err_msg = f"Command not found: {cmds_not_found[0]!r}"
else:
err_msg = f"Commands not found: {cmds_not_found!r}"
if len(cmds_not_found) == len(commands):
_LOGGER.error("Failed to call %s. %s", service, err_msg)
raise ValueError(err_msg)
View on GitHub (pinned to 58a3fdb3ea)
Solutions
- List the stored commands first (call the integration's stored codes view or check the entity's learned commands) and use the exact subdevice name
- If the subdevice was already emptied, no delete is needed — remove that step from the automation
- Fix typos in the 'device' parameter of the remote.delete_command service call
- Re-learn the commands under the intended subdevice name, then delete
Example fix
# before
await hass.services.async_call(
'remote', 'delete_command',
{'entity_id': 'remote.broadlink', 'device': 'TV_Upstairs', 'command': 'power'},
)
# after
subdevices = await hass.services.async_call(
'remote', 'get_stored_codes', {'entity_id': 'remote.broadlink'}, blocking=True, return_response=True,
)
if 'TV_Upstairs' in subdevices['remote.broadlink']:
await hass.services.async_call(
'remote', 'delete_command',
{'entity_id': 'remote.broadlink', 'device': 'TV_Upstairs', 'command': 'power'},
) Defensive patterns
Strategy: validation
Validate before calling
stored = await hass.services.async_call(
'remote', 'get_stored_codes',
{'entity_id': 'remote.broadlink'}, blocking=True, return_response=True,
)
subdevice_known = subdevice in stored['remote.broadlink']
if not subdevice_known:
# nothing to delete; skip the call Try / catch
try:
await remote.async_delete_command(device=subdevice, command=cmd)
except ValueError as err:
if 'Device not found' in str(err):
# subdevice already empty/unknown; treat as success
pass
else:
raise Prevention
- Remember that deleting the last command also removes the subdevice entry — subsequent deletes raise
- Always read stored codes before issuing delete_command in scripts
- Keep subdevice naming consistent between learn and delete calls
When it happens
Trigger: Calling delete_command with a 'device' kwarg whose name was never learned or was already fully deleted (the code removes empty subdevice entries after the last command is deleted); typo in the subdevice name; deleting the same subdevice twice.
Common situations: Automation or script references a subdevice renamed or removed earlier; user re-runs a delete_command call after all commands were deleted, since the cleanup block does 'del self._codes[subdevice]' when codes becomes empty; stale YAML scripts with old subdevice identifiers.
Related errors
- Command not found: {cmds_not_found[0]!r}
- Commands not found: {cmds_not_found!r}
- You need to specify a device
- Command not found: {cmd!r}
- Invalid code: {code!r}
AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14).
Data as JSON: /api/errors/d0ac4be6e1312c7d.
Report an issue: GitHub.