How to create event in Local Calendar

For others in the same boat as @mattat - here’s some yaml for a create calendar form. You’ll need to create the input fields. I use the o365 plugin (i know it’s recently been split apart, I must update) but this is what i’m doing with button-card & browser_mod. Note - I had this in a popup but it caused issue with the date pickers.

type: vertical-stack
cards:
  - type: entities
    title: New Event
    entities:
      - entity: input_text.newevent_name
        name: Name
      - entity: input_text.newevent_description
        name: Description
      - entity: input_datetime.newevent_startdate
        name: Start Date
      - entity: input_datetime.newevent_enddate
        name: End Date
      - entity: input_boolean.newevent_allday
        name: All Day Event?
      - entity: input_text.newevent_location
        name: Location
    show_header_toggle: false
    state_color: false
  - type: custom:button-card
    icon: mdi:calendar-alert-outline
    show_icon: false
    name: Create Event
    styles:
      card:
        - margin: 0
        - padding: 0
      grid:
        - grid-template-areas: "\"i n\""
        - grid-template-columns: min-content 1fr
        - grid-template-rows: min-content min-content
      name:
        - align-self: center
        - font-weight: normal
        - margin: 10px
        - justify-self: center
      icon:
        - align-self: center
        - margin: 10px
        - width: 25px
        - height: 25px
    tap_action:
      action: fire-dom-event
      browser_mod:
        service: browser_mod.popup
        data:
          title: Confirm adding event
          content: Are you sure you wish to add this new event to the family calendar.
          right_button: "Yes"
          left_button: "No"
          right_button_action:
            service: script.create_calendar_event
          left_button_action:
            service: browser_mod.popup
            data:
              title: Operation cancelled.
              dismissable: false
              timeout: 500

and the script

alias: Create Calendar Event
fields:
  subject:
    name: Event Subject
    description: The summary or title for the calendar event
  body:
    name: Event Body
    description: The description for the calendar event
  location:
    name: Event Location
    description: The location for the calendar event
  start:
    name: Start Date
    description: The date & time the calendar event should start
  end:
    name: End Date
    description: The end time of the calendar event
sequence:
  - target:
      entity_id: calendar.your_calendar
    data:
      is_all_day: "{{ is_state('input_boolean.newevent_allday', 'on') }}"
      start: >
        {% set _start = states('input_datetime.newevent_startdate')|as_datetime
        %}   {% set x = _start.strftime("%Y-%m-%dT%H:%M:%S") %}   {{ x }}
      end: >
        {% set _start = states('input_datetime.newevent_startdate')|as_datetime
        %} {% set _end = states('input_datetime.newevent_enddate')|as_datetime
        %}  {% if (_end > _start) %}
          {% set x = _end.strftime("%Y-%m-%dT%H:%M:%S") %} 
          {{ x }}      
        {% else %}
          {% set _end = _start+timedelta(minutes=30) %}
          {% set x = _end.strftime("%Y-%m-%dT%H:%M:%S") %} 
          {{ x }}      
        {% endif %}
      subject: "{{ states('input_text.newevent_name') }}"
      body: "{{ states('input_text.newevent_description') }}"
      location: "{{ states('input_text.newevent_location') }}"
    action: o365.create_calendar_event
  - target:
      entity_id: input_boolean.newevent_allday
    data: {}
    action: input_boolean.turn_off
  - target:
      entity_id: input_text.newevent_name
    data:
      value: ""
    action: input_text.set_value
  - target:
      entity_id: input_text.newevent_description
    data:
      value: ""
    action: input_text.set_value
  - target:
      entity_id: input_text.newevent_location
    data:
      value: ""
    action: input_text.set_value
  - target:
      entity_id: input_datetime.newevent_startdate
    data:
      datetime: "{{ now() }}"
    action: input_datetime.set_datetime
  - target:
      entity_id: input_datetime.newevent_enddate
    data:
      datetime: "{{ now()+timedelta(minutes=30) }}"
    action: input_datetime.set_datetime
mode: queued
icon: mdi:calendar-edit
2 Likes