{"record":{"id":"41bb67e9ddb6bf19","repo":"home-assistant/core","slug":"bthome-trigger-event-class-is-not-valid-for-devi","errorCode":null,"errorMessage":"BTHome trigger {event_class} is not valid for device_id '{device_id}'","messagePattern":"BTHome trigger (.+?) is not valid for device_id '(.+?)'","errorType":"exception","errorClass":"InvalidDeviceAutomationConfig","httpStatus":null,"severity":"warning","filePath":"homeassistant/components/bthome/device_trigger.py","lineNumber":98,"sourceCode":"    event classes like button_1 button_2, button_3, etc\n    but if there is only one button then it will be\n    button without a number postfix.\n    \"\"\"\n    return EVENT_TYPES_BY_EVENT_CLASS.get(event_class.split(\"_\", maxsplit=1)[0], set())\n\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        {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/bthome/device_trigger.py#L80-L116","documentation":"InvalidDeviceAutomationConfig raised by BTHome device-trigger validation when the configured event class (CONF_TYPE, e.g. 'button_1', 'dimmer', 'command') is not in the device's discovered event classes. Event classes are learned dynamically: BTHome events are recorded in the config entry's CONF_DISCOVERED_EVENT_CLASSES data the first time the BLE device emits them. This error aborts automation/UI validation, not runtime event handling.","triggerScenarios":"Validating a trigger whose type references a control the device has never emitted — e.g. 'button_2' on a one-button device, or any class on a sensor-only device — because `get_event_classes_by_device_id` returns the entry's (possibly empty) discovered list. Stale automations after re-pairing also hit this.","commonSituations":"Hand-written YAML automations using guessed types; automations created before a device firmware change altered its BTHome advertisement; devices whose buttons were never pressed since being added, so discovery hasn't recorded the class; device re-paired producing a new config entry without history.","solutions":["Press/actuate the physical control once so the BLE event fires and discovery records its class, then re-validate.","Use the automation UI's trigger picker, which lists only discovered event classes for that device.","Re-pair the device if the config entry's discovered list is stale after firmware changes.","For sensor-only devices, remove the trigger — they emit no events."],"exampleFix":"# before (invalid until the device has emitted the event)\ntrigger:\n  - platform: device\n    domain: bthome\n    device_id: \"...\"\n    type: button_2\n    subtype: press\n# after — first press button_2 on the device, then re-add via UI picker, or use a type already in the device's discovered classes\ntrigger:\n  - platform: device\n    domain: bthome\n    device_id: \"...\"\n    type: button_1\n    subtype: press","handlingStrategy":"validation","validationCode":"# check discovered event classes before writing YAML\n# Developer Tools > Template:\n{{ config_entry_attr(device_attr(device_id, 'config_entries')[0], 'data').discovered_event_classes }}","typeGuard":"def trigger_type_is_discovered(hass: HomeAssistant, device_id: str, event_class: str) -> bool:\n    dr_entry = dr.async_get(hass).async_get(device_id)\n    if dr_entry is None:\n        return False\n    entry = next(\n        (hass.config_entries.async_get_entry(e) for e in dr_entry.config_entries\n         if hass.config_entries.async_get_entry(e) and hass.config_entries.async_get_entry(e).domain == \"bthome\"),\n        None,\n    )\n    return entry is not None and event_class in entry.data.get(\"discovered_event_classes\", [])","tryCatchPattern":null,"preventionTips":["Actuate each physical control once after pairing so discovery records its event class.","Build triggers through the UI picker, which only lists discovered classes.","Re-pair the device after firmware changes that alter its BTHome device type."],"tags":["home-assistant","bthome","ble","device-trigger","validation","discovery"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}