{"record":{"id":"d0ac4be6e1312c7d","repo":"home-assistant/core","slug":"device-not-found-subdevice-r","errorCode":null,"errorMessage":"Device not found: {subdevice!r}","messagePattern":"Device not found: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/broadlink/remote.py","lineNumber":463,"sourceCode":"        service = f\"{RM_DOMAIN}.{SERVICE_DELETE_COMMAND}\"\n\n        if not self._attr_is_on:\n            _LOGGER.warning(\n                \"%s canceled: %s entity is turned off\",\n                service,\n                self.entity_id,\n            )\n            return\n\n        if not self._storage_loaded:\n            await self._async_load_storage()\n\n        try:\n            codes = self._codes[subdevice]\n        except KeyError as err:\n            err_msg = f\"Device not found: {subdevice!r}\"\n            _LOGGER.error(\"Failed to call %s. %s\", service, err_msg)\n            raise ValueError(err_msg) from err\n\n        cmds_not_found = []\n        for command in commands:\n            try:\n                del codes[command]\n            except KeyError:\n                cmds_not_found.append(command)\n\n        if cmds_not_found:\n            if len(cmds_not_found) == 1:\n                err_msg = f\"Command not found: {cmds_not_found[0]!r}\"\n            else:\n                err_msg = f\"Commands not found: {cmds_not_found!r}\"\n\n            if len(cmds_not_found) == len(commands):\n                _LOGGER.error(\"Failed to call %s. %s\", service, err_msg)\n                raise ValueError(err_msg)\n","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/broadlink/remote.py#L445-L481","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nawait hass.services.async_call(\n    'remote', 'delete_command',\n    {'entity_id': 'remote.broadlink', 'device': 'TV_Upstairs', 'command': 'power'},\n)\n\n# after\nsubdevices = await hass.services.async_call(\n    'remote', 'get_stored_codes', {'entity_id': 'remote.broadlink'}, blocking=True, return_response=True,\n)\nif 'TV_Upstairs' in subdevices['remote.broadlink']:\n    await hass.services.async_call(\n        'remote', 'delete_command',\n        {'entity_id': 'remote.broadlink', 'device': 'TV_Upstairs', 'command': 'power'},\n    )","handlingStrategy":"validation","validationCode":"stored = await hass.services.async_call(\n    'remote', 'get_stored_codes',\n    {'entity_id': 'remote.broadlink'}, blocking=True, return_response=True,\n)\nsubdevice_known = subdevice in stored['remote.broadlink']\nif not subdevice_known:\n    # nothing to delete; skip the call","typeGuard":null,"tryCatchPattern":"try:\n    await remote.async_delete_command(device=subdevice, command=cmd)\nexcept ValueError as err:\n    if 'Device not found' in str(err):\n        # subdevice already empty/unknown; treat as success\n        pass\n    else:\n        raise","preventionTips":["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"],"tags":["broadlink","remote","delete-command","subdevice","home-assistant"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}