home-assistant/core · error · HomeAssistantError
No entity_id provided and no preferred entity set
Error message
No entity_id provided and no preferred entity set
What it means
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.
Source
Thrown at homeassistant/components/ai_task/task.py:128
return resolved_attachments
async def async_generate_data(
hass: HomeAssistant,
*,
task_name: str,
entity_id: str | None = None,
instructions: str,
structure: vol.Schema | None = None,
attachments: list[dict] | None = None,
llm_api: llm.API | None = None,
) -> GenDataTaskResult:
"""Run a data generation task in the AI Task integration."""
if entity_id is None:
entity_id = hass.data[DATA_PREFERENCES].gen_data_entity_id
if entity_id is None:
raise HomeAssistantError("No entity_id provided and no preferred entity set")
entity = hass.data[DATA_COMPONENT].get_entity(entity_id)
if entity is None:
raise HomeAssistantError(f"AI Task entity {entity_id} not found")
if AITaskEntityFeature.GENERATE_DATA not in entity.supported_features:
raise HomeAssistantError(
f"AI Task entity {entity_id} does not support generating data"
)
if (
attachments
and AITaskEntityFeature.SUPPORT_ATTACHMENTS not in entity.supported_features
):
raise HomeAssistantError(
f"AI Task entity {entity_id} does not support attachments"
)
View on GitHub (pinned to 58a3fdb3ea)
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.
Example fix
# before
action:
- action: ai_task.generate_data
data:
task_name: summarize
instructions: "..."
# after
action:
- action: ai_task.generate_data
data:
entity_id: conversation.openai_conversation
task_name: summarize
instructions: "..." Defensive patterns
Strategy: validation
Validate before calling
def gen_data_target_ready(hass) -> bool:
"""Explicit id or stored preference must exist before generate_data."""
prefs = hass.data.get(DATA_PREFERENCES)
return prefs is not None and prefs.gen_data_entity_id is not None Try / catch
from homeassistant.exceptions import HomeAssistantError
try:
result = await async_generate_data(hass, task_name="t", instructions="...")
except HomeAssistantError as err:
if "No entity_id provided" in str(err):
raise ValueError("Pass entity_id or set a preferred entity first") from err
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AI Task entity {entity_id} not found
- AI Task entity {entity_id} does not support generating data
- Heat/Cool is not supported in this mode
- AI Task media source requires at least one media directory c
- Only local attachments are currently supported
AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14).
Data as JSON: /api/errors/b92a1f145e6c6081.
Report an issue: GitHub.