home-assistant/core · error · ValueError

Command not found: {cmds_not_found[0]!r}

Error message

Command not found: {cmds_not_found[0]!r}

What it means

Constructed when exactly one requested command is missing from the stored codes during async_delete_command. The ValueError is only raised when ALL requested commands are missing; otherwise the message is logged as a partial-failure error and deletion of the found commands proceeds. Indicates the stored code dictionary has drifted from what the caller expects.

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. Inspect the entity's stored codes to confirm the exact command names before deleting
  2. If the command is already gone, drop it from the delete list — nothing remains to delete
  3. Re-learn the command under the correct name if you actually want it stored
  4. When deleting several commands, treat partial failures as logged warnings — only all-missing raises

Example fix

# before
await remote_svc.async_call('remote', 'delete_command', {
    'entity_id': 'remote.broadlink', 'device': 'tv', 'command': 'powr',  # typo
})

# after
stored = await remote_svc.async_call('remote', 'get_stored_codes',
    {'entity_id': 'remote.broadlink'}, blocking=True, return_response=True)
command = 'power' if 'power' in stored['remote.broadlink']['tv'] else None
if command:
    await remote_svc.async_call('remote', 'delete_command', {
        'entity_id': 'remote.broadlink', 'device': 'tv', 'command': command,
    })
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,
)
command_exists = command in stored['remote.broadlink'].get(subdevice, {})
if not command_exists:
    # already deleted or never learned; skip

Try / catch

try:
    await remote.async_delete_command(device=subdevice, command=command)
except ValueError as err:
    if 'Command not found' in str(err):
        # requested command(s) already absent; idempotent no-op
        pass
    else:
        raise

Prevention

When it happens

Trigger: Calling remote.delete_command with a single command name never learned, renamed, or already deleted; code was learned under a different subdevice; typos in the command string.

Common situations: Deleting a command twice in a row (first call removes it, second raises); scripts referencing command names from an older learning session; partial deletions in prior runs that logged but did not raise.

Related errors


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