home-assistant/core · error · ValueError

Missing required fields to set start or end date/datetime

Error message

Missing required fields to set start or end date/datetime

What it means

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).

Source

Thrown at homeassistant/components/calendar/__init__.py:1096

    `datetime` or `date` as a single `start` argument.
    It also handles the other service call variations like "in days" as well.
    """

    if event_in := values.get(EVENT_IN):
        days = event_in.get(EVENT_IN_DAYS, 7 * event_in.get(EVENT_IN_WEEKS, 0))
        today = dt_util.now().date()
        return (
            today + datetime.timedelta(days=days),
            today + datetime.timedelta(days=days + 1),
        )

    if EVENT_START_DATE in values and EVENT_END_DATE in values:
        return (values[EVENT_START_DATE], values[EVENT_END_DATE])

    if EVENT_START_DATETIME in values and EVENT_END_DATETIME in values:
        return (values[EVENT_START_DATETIME], values[EVENT_END_DATETIME])

    raise ValueError("Missing required fields to set start or end date/datetime")


async def async_create_event(entity: CalendarEntity, call: ServiceCall) -> None:
    """Add a new event to calendar."""
    # Convert parameters to format used by async_create_event
    (start, end) = _validate_timespan(call.data)
    params = {
        **{k: v for k, v in call.data.items() if k not in EVENT_TIME_FIELDS},
        EVENT_START: start,
        EVENT_END: end,
    }
    await entity.async_create_event(**params)


async def async_get_events_service(
    calendar: CalendarEntity, service_call: ServiceCall
) -> ServiceResponse:
    """List events on a calendar during a time range."""

View on GitHub (pinned to 58a3fdb3ea)

Solutions

  1. Provide both start and end in the same form: start_date + end_date, or start_date_time + end_date_time
  2. Or use the in_X_days form which derives the span automatically
  3. Check for typos (e.g. 'end_datetime' vs 'end_date_time') against the service schema in Developer Tools > Actions

Example fix

# before
service: calendar.create_event
data:
  entity_id: calendar.work
  start_date_time: "2026-08-15 09:00:00"
  # end missing

# after
service: calendar.create_event
data:
  entity_id: calendar.work
  start_date_time: "2026-08-15 09:00:00"
  end_date_time: "2026-08-15 10:00:00"
Defensive patterns

Strategy: validation

Validate before calling

def has_complete_timespan(data: dict) -> bool:
    return (
        ("start_date" in data and "end_date" in data)
        or ("start_date_time" in data and "end_date_time" in data)
        or "in_days" in data
    )

Try / catch

try:
    (start, end) = _validate_timespan(call.data)
except ValueError as err:
    # surface which pairing rule was violated to the caller
    raise HomeAssistantError(str(err)) from err

Prevention

When it happens

Trigger: 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.

Common situations: Hand-written service calls in automations/scripts that omit EVENT_END, users assuming end defaults to something, or YAML indentation mistakes dropping a key.

Related errors


AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14). Data as JSON: /api/errors/b0aa295c48dec2b3. Report an issue: GitHub.