home-assistant/core · error · ValueError

Commands not found: {cmds_not_found!r}

Error message

Commands not found: {cmds_not_found!r}

What it means

Variant of the delete-command failure listing multiple missing commands (cmds_not_found has more than one entry). As with the single-command case, the ValueError is raised only when every requested command is missing; a partial miss is logged as 'Error during %s' and the delete continues for the commands that were found.

Source

Thrown at homeassistant/components/broadlink/remote.py:480

            _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)

            _LOGGER.error("Error during %s. %s", service, err_msg)

        # Clean up
        if not codes:
            del self._codes[subdevice]
            if self._flags.pop(subdevice, None) is not None:
                self._flag_storage.async_delay_save(self._get_flags, FLAG_SAVE_DELAY)

        self._code_storage.async_delay_save(self._get_codes, CODE_SAVE_DELAY)

View on GitHub (pinned to 58a3fdb3ea)

Solutions

  1. Fetch stored codes and diff the requested list against actual command names before calling delete
  2. Normalize command names (case, separators) between learning and deletion scripts
  3. If all commands are already gone, remove the delete step entirely
  4. For mixed lists, split into found/not-found and only delete the found subset to avoid the all-missing raise

Example fix

# before
await remote_svc.async_call('remote', 'delete_command', {
    'entity_id': 'remote.broadlink', 'device': 'tv',
    'command': ['power', 'vol_up', 'hdmi1'],  # none exist
})

# after
stored = await remote_svc.async_call('remote', 'get_stored_codes',
    {'entity_id': 'remote.broadlink'}, blocking=True, return_response=True)
known = set(stored['remote.broadlink'].get('tv', {}))
to_delete = [c for c in ['power', 'vol_up', 'hdmi1'] if c in known]
if to_delete:
    await remote_svc.async_call('remote', 'delete_command', {
        'entity_id': 'remote.broadlink', 'device': 'tv', 'command': to_delete,
    })
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,
)
known = set(stored['remote.broadlink'].get(subdevice, {}))
to_delete = [c for c in requested_commands if c in known]
# only delete the intersection; skip when empty

Try / catch

try:
    await remote.async_delete_command(device=subdevice, command=command_list)
except ValueError as err:
    if 'Commands not found' in str(err):
        # entire batch already absent; safe to ignore for idempotent cleanup
        pass
    else:
        raise

Prevention

When it happens

Trigger: Calling remote.delete_command with a list where none of the command names exist under the given subdevice; bulk-deleting commands from a script written against an older stored-codes layout.

Common situations: Re-running a bulk cleanup script after it already ran successfully; commands learned with different casing or naming (e.g. 'Power' vs 'power'); subdevice switched so the whole command set lives under another key.

Related errors


AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14). Data as JSON: /api/errors/f5446c02a0f6a152. Report an issue: GitHub.