{"record":{"id":"b92a1f145e6c6081","repo":"home-assistant/core","slug":"no-entity-id-provided-and-no-preferred-entity-set","errorCode":null,"errorMessage":"No entity_id provided and no preferred entity set","messagePattern":"No entity_id provided and no preferred entity set","errorType":"exception","errorClass":"HomeAssistantError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/ai_task/task.py","lineNumber":128,"sourceCode":"    return resolved_attachments\n\n\nasync def async_generate_data(\n    hass: HomeAssistant,\n    *,\n    task_name: str,\n    entity_id: str | None = None,\n    instructions: str,\n    structure: vol.Schema | None = None,\n    attachments: list[dict] | None = None,\n    llm_api: llm.API | None = None,\n) -> GenDataTaskResult:\n    \"\"\"Run a data generation task in the AI Task integration.\"\"\"\n    if entity_id is None:\n        entity_id = hass.data[DATA_PREFERENCES].gen_data_entity_id\n\n    if entity_id is None:\n        raise HomeAssistantError(\"No entity_id provided and no preferred entity set\")\n\n    entity = hass.data[DATA_COMPONENT].get_entity(entity_id)\n    if entity is None:\n        raise HomeAssistantError(f\"AI Task entity {entity_id} not found\")\n\n    if AITaskEntityFeature.GENERATE_DATA not in entity.supported_features:\n        raise HomeAssistantError(\n            f\"AI Task entity {entity_id} does not support generating data\"\n        )\n\n    if (\n        attachments\n        and AITaskEntityFeature.SUPPORT_ATTACHMENTS not in entity.supported_features\n    ):\n        raise HomeAssistantError(\n            f\"AI Task entity {entity_id} does not support attachments\"\n        )\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/ai_task/task.py#L110-L146","documentation":"HomeAssistantError from ai_task.async_generate_data when no entity_id argument was supplied AND hass.data[DATA_PREFERENCES].gen_data_entity_id is None. The data-generation path needs a concrete AI Task entity to delegate to; without an explicit id or a configured preferred entity there is nothing to run the task.","triggerScenarios":"Calling the ai_task.generate_data service (or the helper) without entity_id on an instance where the user never picked a preferred 'generate data' entity in the AI Task integration options/dialog.","commonSituations":"First use of ai_task.generate_data after enabling the integration; the UI preference (gen_data_entity_id) is only set when the user selects a default entity, so scripted/automation-first usage hits this immediately.","solutions":["Pass entity_id explicitly in the service call (e.g. entity_id: conversation.agent_name).","Or open the AI Task defaults once — call generate_data from the UI (Developer Tools > Actions) and set the preferred entity — so the preference is stored for future id-less calls.","Verify the integration is set up (ai_task in hass.data with DATA_COMPONENT/ DATA_PREFERENCES present).","In blueprints/automations, always template entity_id from a input_text/input_select helper instead of relying on the stored preference."],"exampleFix":"# before\naction:\n  - action: ai_task.generate_data\n    data:\n      task_name: summarize\n      instructions: \"...\"\n\n# after\naction:\n  - action: ai_task.generate_data\n    data:\n      entity_id: conversation.openai_conversation\n      task_name: summarize\n      instructions: \"...\"","handlingStrategy":"validation","validationCode":"def gen_data_target_ready(hass) -> bool:\n    \"\"\"Explicit id or stored preference must exist before generate_data.\"\"\"\n    prefs = hass.data.get(DATA_PREFERENCES)\n    return prefs is not None and prefs.gen_data_entity_id is not None","typeGuard":null,"tryCatchPattern":"from homeassistant.exceptions import HomeAssistantError\n\ntry:\n    result = await async_generate_data(hass, task_name=\"t\", instructions=\"...\")\nexcept HomeAssistantError as err:\n    if \"No entity_id provided\" in str(err):\n        raise ValueError(\"Pass entity_id or set a preferred entity first\") from err\n    raise","preventionTips":["Always pass entity_id in automations instead of relying on the stored preference.","Set the preferred entity via one UI invocation before scripting.","Re-set defaults after removing an agent integration."],"tags":["homeassistant","ai-task","validation","entity-selection"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}