home-assistant/core · warning · ValueError
You need to specify a device
Error message
You need to specify a device
What it means
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.
Source
Thrown at homeassistant/components/broadlink/remote.py:149
def _extract_codes(self, commands, device=None):
"""Extract a list of codes.
If the command starts with `b64:`, extract the code from it.
Otherwise, extract the code from storage, using the command and
device as keys.
The codes are returned in sublists. For toggle commands, the
sublist contains two codes that must be sent alternately with
each call.
"""
code_list = []
for cmd in commands:
if cmd.startswith("b64:"):
codes = [cmd[4:]]
else:
if device is None:
raise ValueError("You need to specify a device")
try:
codes = self._codes[device][cmd]
except KeyError as err:
raise ValueError(f"Command not found: {cmd!r}") from err
if isinstance(codes, list):
codes = codes[:]
else:
codes = [codes]
for idx, code in enumerate(codes):
try:
codes[idx] = data_packet(code)
except ValueError as err:
raise ValueError(f"Invalid code: {code!r}") from err
code_list.append(codes)View on GitHub (pinned to 58a3fdb3ea)
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.
Example fix
# before service: remote.send_command target: entity_id: remote.broadlink_rm data: command: Power # after service: remote.send_command target: entity_id: remote.broadlink_rm data: device: tv command: Power
Defensive patterns
Strategy: validation
Validate before calling
def validate_service_data(data: dict) -> None:
"""Require a subdevice for any command not in raw b64: form."""
commands = data.get("command") or []
commands = [commands] if isinstance(commands, str) else commands
if any(not c.startswith("b64:") for c in commands) and not data.get("device"):
raise ValueError("device is required for named commands") Type guard
def is_raw_b64_command(command: object) -> bool:
"""Narrow to pre-encoded packets that need no device lookup."""
return isinstance(command, str) and command.startswith("b64:") Try / catch
try:
await hass.services.async_call("remote", "send_command", data, blocking=True)
except ValueError as err:
if "specify a device" in str(err):
data = {**data, "device": default_subdevice}
await hass.services.async_call("remote", "send_command", data, blocking=True)
else:
raise Prevention
- 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.
When it happens
Trigger: Calling remote.send_command with a named command (not 'b64:<base64>') while omitting the optional device field in the service call data.
Common situations: 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.
Related errors
- Command not found: {cmd!r}
- Invalid MAC address
- Invalid code: {code!r}
- {self.entity_id} doesn't support sending RF commands
- {self.entity_id} doesn't support learning RF commands
AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14).
Data as JSON: /api/errors/29df8209df90151d.
Report an issue: GitHub.