{"record":{"id":"7c4d1ba1cf610417","repo":"home-assistant/core","slug":"command-not-found-cmd-r","errorCode":null,"errorMessage":"Command not found: {cmd!r}","messagePattern":"Command not found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"homeassistant/components/broadlink/remote.py","lineNumber":154,"sourceCode":"        device as keys.\n\n        The codes are returned in sublists. For toggle commands, the\n        sublist contains two codes that must be sent alternately with\n        each call.\n        \"\"\"\n        code_list = []\n        for cmd in commands:\n            if cmd.startswith(\"b64:\"):\n                codes = [cmd[4:]]\n\n            else:\n                if device is None:\n                    raise ValueError(\"You need to specify a device\")\n\n                try:\n                    codes = self._codes[device][cmd]\n                except KeyError as err:\n                    raise ValueError(f\"Command not found: {cmd!r}\") from err\n\n                if isinstance(codes, list):\n                    codes = codes[:]\n                else:\n                    codes = [codes]\n\n            for idx, code in enumerate(codes):\n                try:\n                    codes[idx] = data_packet(code)\n                except ValueError as err:\n                    raise ValueError(f\"Invalid code: {code!r}\") from err\n\n            code_list.append(codes)\n        return code_list\n\n    @callback\n    def _get_codes(self):\n        \"\"\"Return a dictionary of codes.\"\"\"","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/broadlink/remote.py#L136-L172","documentation":"ValueError(f\"Command not found: {cmd!r}\") from _extract_codes: the command name was not present in self._codes[device], the learned-code dictionary for the specified subdevice. A device was supplied and the dict lookup raised KeyError, which is converted to this explicit error. Nothing is transmitted.","triggerScenarios":"Sending remote.send_command with device set correctly but a command name never learned (or learned under a different subdevice, or with different capitalization/spelling).","commonSituations":"Typo in the command name in an automation, command learned under a different subdevice name, storage file lost/reset (HA database or .storage wipe), case mismatch ('power' vs 'Power').","solutions":["Run remote.learn_command to (re)learn the exact command name for that subdevice.","Check spelling and case — lookup is an exact dict key match.","Confirm the command was learned under the same device/subdevice name you pass in the call.","If codes vanished, restore HA .storage or re-learn all commands for that subdevice."],"exampleFix":"# before\ndata:\n  device: tv\n  command: powr   # typo\n\n# after\ndata:\n  device: tv\n  command: Power   # exact learned name","handlingStrategy":"validation","validationCode":"def known_commands(remote_entity) -> set[str]:\n    \"\"\"Return learned command names for exact-match checking before sending.\"\"\"\n    codes = remote_entity.broadlink_codes  # or read the integration's stored codes\n    return set(codes.get(subdevice, {}))\n\nif command not in known_commands(remote):\n    raise ValueError(f\"Command not learned: {command!r} — run remote.learn_command first\")","typeGuard":"def is_known_command(command: object, codes: dict) -> bool:\n    \"\"\"Narrow to commands present in the subdevice's learned set.\"\"\"\n    return isinstance(command, str) and command in codes","tryCatchPattern":"try:\n    await hass.services.async_call(\"remote\", \"send_command\", data, blocking=True)\nexcept ValueError as err:\n    if \"Command not found\" in str(err):\n        await hass.services.async_call(\n            \"remote\", \"learn_command\",\n            {**data, \"command\": [missing_cmd]}, blocking=True,\n        )\n    else:\n        raise","preventionTips":["Use exact learned command names (case-sensitive) in automations.","Keep a canonical list of learned subdevice/command pairs in the automation config comments.","Back up HA .storage so learned codes survive reinstalls."],"tags":["home-assistant","broadlink","remote","user-input"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}