{"record":{"id":"29df8209df90151d","repo":"home-assistant/core","slug":"you-need-to-specify-a-device","errorCode":null,"errorMessage":"You need to specify a device","messagePattern":"You need to specify a device","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"homeassistant/components/broadlink/remote.py","lineNumber":149,"sourceCode":"    def _extract_codes(self, commands, device=None):\n        \"\"\"Extract a list of codes.\n\n        If the command starts with `b64:`, extract the code from it.\n        Otherwise, extract the code from storage, using the command and\n        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)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/broadlink/remote.py#L131-L167","documentation":"ValueError('You need to specify a device') from BroadlinkRemote._extract_codes: when a command is not prefixed with 'b64:' it is looked up in the stored per-subdevice code dictionary self._codes[device][cmd], so a device (subdevice) name is mandatory. Without it the lookup cannot be routed and the method raises before any transmission.","triggerScenarios":"Calling remote.send_command with a named command (not 'b64:<base64>') while omitting the optional device field in the service call data.","commonSituations":"Automations copied from other remote platforms (e.g. Harmony) that have no subdevice concept, users who learned commands under a subdevice and then send them device-less, scripts where the device key was dropped in YAML cleanup.","solutions":["Add device: <subdevice_name> to the remote.send_command call matching the name used when learning.","Alternatively send raw data directly with command 'b64:<base64 packet>', which bypasses the lookup.","Check stored codes via Developer Tools > States / the broadlink storage file to confirm the subdevice naming.","Re-learn the command under the intended subdevice if the stored set is empty."],"exampleFix":"# before\nservice: remote.send_command\ntarget:\n  entity_id: remote.broadlink_rm\ndata:\n  command: Power\n\n# after\nservice: remote.send_command\ntarget:\n  entity_id: remote.broadlink_rm\ndata:\n  device: tv\n  command: Power","handlingStrategy":"validation","validationCode":"def validate_service_data(data: dict) -> None:\n    \"\"\"Require a subdevice for any command not in raw b64: form.\"\"\"\n    commands = data.get(\"command\") or []\n    commands = [commands] if isinstance(commands, str) else commands\n    if any(not c.startswith(\"b64:\") for c in commands) and not data.get(\"device\"):\n        raise ValueError(\"device is required for named commands\")","typeGuard":"def is_raw_b64_command(command: object) -> bool:\n    \"\"\"Narrow to pre-encoded packets that need no device lookup.\"\"\"\n    return isinstance(command, str) and command.startswith(\"b64:\")","tryCatchPattern":"try:\n    await hass.services.async_call(\"remote\", \"send_command\", data, blocking=True)\nexcept ValueError as err:\n    if \"specify a device\" in str(err):\n        data = {**data, \"device\": default_subdevice}\n        await hass.services.async_call(\"remote\", \"send_command\", data, blocking=True)\n    else:\n        raise","preventionTips":["Always pair named commands with their learned subdevice name in scripts.","Prefer 'b64:' raw form in generated automations to avoid dictionary lookups entirely.","Document the subdevice names used at learning time in the automation comments."],"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"}