{"record":{"id":"b0aa295c48dec2b3","repo":"home-assistant/core","slug":"missing-required-fields-to-set-start-or-end-date-d","errorCode":null,"errorMessage":"Missing required fields to set start or end date/datetime","messagePattern":"Missing required fields to set start or end date/datetime","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/calendar/__init__.py","lineNumber":1096,"sourceCode":"    `datetime` or `date` as a single `start` argument.\n    It also handles the other service call variations like \"in days\" as well.\n    \"\"\"\n\n    if event_in := values.get(EVENT_IN):\n        days = event_in.get(EVENT_IN_DAYS, 7 * event_in.get(EVENT_IN_WEEKS, 0))\n        today = dt_util.now().date()\n        return (\n            today + datetime.timedelta(days=days),\n            today + datetime.timedelta(days=days + 1),\n        )\n\n    if EVENT_START_DATE in values and EVENT_END_DATE in values:\n        return (values[EVENT_START_DATE], values[EVENT_END_DATE])\n\n    if EVENT_START_DATETIME in values and EVENT_END_DATETIME in values:\n        return (values[EVENT_START_DATETIME], values[EVENT_END_DATETIME])\n\n    raise ValueError(\"Missing required fields to set start or end date/datetime\")\n\n\nasync def async_create_event(entity: CalendarEntity, call: ServiceCall) -> None:\n    \"\"\"Add a new event to calendar.\"\"\"\n    # Convert parameters to format used by async_create_event\n    (start, end) = _validate_timespan(call.data)\n    params = {\n        **{k: v for k, v in call.data.items() if k not in EVENT_TIME_FIELDS},\n        EVENT_START: start,\n        EVENT_END: end,\n    }\n    await entity.async_create_event(**params)\n\n\nasync def async_get_events_service(\n    calendar: CalendarEntity, service_call: ServiceCall\n) -> ServiceResponse:\n    \"\"\"List events on a calendar during a time range.\"\"\"","sourceCodeStart":1078,"sourceCodeEnd":1114,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/calendar/__init__.py#L1078-L1114","documentation":"ValueError raised by _validate_timespan in the calendar component when the create_event service call data has neither both EVENT_START_DATE and EVENT_END_DATE nor both EVENT_START_DATETIME and EVENT_END_DATETIME. The service requires a complete start/end pair in one of the two forms (or a days offset for all-day events).","triggerScenarios":"Calling the calendar.create_event service with only a start (date or datetime), only an end, mixed forms (start_date with end_datetime), or misspelled keys — none of the pairing branches in _validate_timespan match.","commonSituations":"Hand-written service calls in automations/scripts that omit EVENT_END, users assuming end defaults to something, or YAML indentation mistakes dropping a key.","solutions":["Provide both start and end in the same form: start_date + end_date, or start_date_time + end_date_time","Or use the in_X_days form which derives the span automatically","Check for typos (e.g. 'end_datetime' vs 'end_date_time') against the service schema in Developer Tools > Actions"],"exampleFix":"# before\nservice: calendar.create_event\ndata:\n  entity_id: calendar.work\n  start_date_time: \"2026-08-15 09:00:00\"\n  # end missing\n\n# after\nservice: calendar.create_event\ndata:\n  entity_id: calendar.work\n  start_date_time: \"2026-08-15 09:00:00\"\n  end_date_time: \"2026-08-15 10:00:00\"","handlingStrategy":"validation","validationCode":"def has_complete_timespan(data: dict) -> bool:\n    return (\n        (\"start_date\" in data and \"end_date\" in data)\n        or (\"start_date_time\" in data and \"end_date_time\" in data)\n        or \"in_days\" in data\n    )","typeGuard":null,"tryCatchPattern":"try:\n    (start, end) = _validate_timespan(call.data)\nexcept ValueError as err:\n    # surface which pairing rule was violated to the caller\n    raise HomeAssistantError(str(err)) from err","preventionTips":["Always supply start and end in the same form (date pair or datetime pair)","Use in_X_days for quick all-day events instead of hand-computing dates","Validate service payloads in Developer Tools > Actions before saving automations"],"tags":["homeassistant","calendar","service-call","validation"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}