{"record":{"id":"9e9c72b1255dbbfd","repo":"home-assistant/core","slug":"bthome-trigger-event-type-is-not-valid-for-devic","errorCode":null,"errorMessage":"BTHome trigger {event_type} is not valid for device_id '{device_id}'","messagePattern":"BTHome trigger (.+?) is not valid for device_id '(.+?)'","errorType":"exception","errorClass":"InvalidDeviceAutomationConfig","httpStatus":null,"severity":"error","filePath":"homeassistant/components/bthome/device_trigger.py","lineNumber":103,"sourceCode":"\n\nasync def async_validate_trigger_config(\n    hass: HomeAssistant, config: ConfigType\n) -> ConfigType:\n    \"\"\"Validate trigger config.\"\"\"\n    config = TRIGGER_SCHEMA(config)\n    event_class = config[CONF_TYPE]\n    event_type = config[CONF_SUBTYPE]\n    device_id = config[CONF_DEVICE_ID]\n    event_classes = get_event_classes_by_device_id(hass, device_id)\n\n    if event_class not in event_classes:\n        raise InvalidDeviceAutomationConfig(\n            f\"BTHome trigger {event_class} is not valid for device_id '{device_id}'\"\n        )\n\n    if event_type not in get_event_types_by_event_class(event_class):\n        raise InvalidDeviceAutomationConfig(\n            f\"BTHome trigger {event_type} is not valid for device_id '{device_id}'\"\n        )\n\n    return config\n\n\nasync def async_get_triggers(\n    hass: HomeAssistant, device_id: str\n) -> list[dict[str, Any]]:\n    \"\"\"Return a list of triggers for BTHome BLE devices.\"\"\"\n    event_classes = get_event_classes_by_device_id(hass, device_id)\n    return [\n        {\n            # Required fields of TRIGGER_BASE_SCHEMA\n            CONF_PLATFORM: \"device\",\n            CONF_DEVICE_ID: device_id,\n            CONF_DOMAIN: DOMAIN,\n            # Required fields of TRIGGER_SCHEMA","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/bthome/device_trigger.py#L85-L121","documentation":"Raised as InvalidDeviceAutomationConfig when a BTHome device automation trigger references an event subtype that the device does not actually advertise. During async_validate_trigger_config, the config is schema-validated, then the event subtype (CONF_SUBTYPE) is checked against get_event_types_by_event_class(event_class). A mismatch means the stored device no longer supports that button/switch event.","triggerScenarios":"Calling async_validate_trigger_config (e.g. when an automation using a device trigger is loaded or validated) with a trigger whose type/subtype pair is not in the event types advertised by the BTHome device's parser for that event class. Happens when a device firmware changes its advertised data or the automation YAML was hand-edited or copied from another device.","commonSituations":"Copying automation YAML between different BTHome devices, a device firmware update that changes exposed buttons, or a stale device registry entry after a device was replaced/re-paired.","solutions":["Re-create the trigger via the UI (Settings > Automations) so the trigger is built from the device's currently advertised events","Delete and re-pair the BTHome device so the coordinator re-discovers its event classes and subtypes","Manually correct the subtype in the automation YAML to one reported by the device (check the BTHome advertisement data or the integration's event schema)"],"exampleFix":"# before (automation.yaml)\n- triggers:\n  - trigger: device\n    domain: bthome\n    type: button\n    subtype: unknown_button  # not advertised by this device\n\n# after\n- triggers:\n  - trigger: device\n    domain: bthome\n    type: button\n    subtype: button_1  # a subtype the device actually advertises","handlingStrategy":"validation","validationCode":"from homeassistant.helpers import config_validation as cv\nfrom homeassistant.components.bthome.device_trigger import async_get_triggers\n\n# Before installing an automation trigger, confirm the subtype is offered\ntriggers = await async_get_triggers(hass, device_id)\nsubtypes = {\n    t[\"subtype\"] for t in triggers if t.get(\"type\") == wanted_type\n}\nif wanted_subtype not in subtypes:\n    # skip or re-select instead of raising InvalidDeviceAutomationConfig\n    ...","typeGuard":"def is_valid_bthome_trigger(trigger: dict, available: list[dict]) -> bool:\n    return any(\n        t.get(\"type\") == trigger.get(\"type\")\n        and t.get(\"subtype\") == trigger.get(\"subtype\")\n        for t in available\n    )","tryCatchPattern":"from homeassistant.helpers.device_automation import InvalidDeviceAutomationConfig\n\ntry:\n    await async_validate_trigger_config(hass, config)\nexcept InvalidDeviceAutomationConfig as err:\n    # rebuild the trigger list for this device and prompt re-selection\n    logger.warning(\"Stale BTHome trigger: %s\", err)","preventionTips":["Always create device triggers through the UI so subtypes come from the live device advertisement","Re-pair the BTHome device after firmware changes and re-generate dependent automations","Validate stored automation YAML against async_get_triggers output after device replacement"],"tags":["homeassistant","bthome","ble","device-automation","validation"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}