How to create event in Local Calendar

Currently, there’s no service call available for adding a scheduled event.

1 Like

I also wish we could create an event to the calendar using an automation.

Hydro-Québec, our electricity company, notifies us by email about peak periods.

Using IMAP Email Content I can parse the time period from the body but then I can’t create an event automatically in the Local Calendar.

1 Like

It’s in development:

4 Likes

That is great to hear. For me that will solve the problem to create events via a service. It is half solution to my challenge. The second thing which is important is to be able to enumerate existing events via service.
What I would like to achieve is to have a simple way to show for instance when the last time I changed the litterbox of the cat. (Have a button which I press when it got replaced, show the time on the dashboard - 8 days ago).
Also it is a great tool to create an event for every power outage. U could see visually when and how long the blackout lasted (yep I have ups in every critical infra so can create events on those periods too :slight_smile: ), or we where away from the house.
I know I can play with history stats, counters etc but this would be much more straightforward since I can build dashboard information from those and can put it out visually as a calendar.

1 Like

Is there a way to create an event which is repeating for example every 9 days? In the new event pop up I have only repeat yerly, monthly, weekly and daily which is not very flexible :frowning:

1 Like

Yes. Set to Daily and choose 9 for the Repeat interval. It implements nearly all of RFC 5545: Internet Calendaring and Scheduling Core Object Specification (iCalendar) but not secondly and hourly. I disagree with you, it’s quite flexible :slight_smile:

I feel like idiot now. I did not try to set it daily to see there is more setting to it. I just reckoned that daily meant every day :smiley:

Now I agree, it is really flexible, just as I need. thanks

The service calendar.create_event is now available in 2023.2.1 which enables, in my case, an automation to populate events in a local calendar from an external data source.
How can I read the existing events from a local calendar? How can I make my automation can execute multiple times and not duplicate events?

Currently, Home Assistant doesn’t provide a native method for finding all existing events. In other words, nothing is available to tell you all of the events scheduled for today (or tomorrow or any other day in the future).

The Calendar Trigger can report the moment when a scheduled event occurs, or if you use the Calendar Trigger’s offset option, it can report in advance of the scheduled event (example: 4 hours in advance).

There’s a custom integration that finds all scheduled events but I don’t recall its name (and I have no experience with it). Maybe someone who uses it can post its name and explain its features.

As @123 mentioned you can use the Hass Calendar Add-On to access the data of events beyond the next scheduled event.

Can you clarify what you are asking here?

Sure: in a scheduled automation, with an external data source I want to sync the local calendar with, I cannot make the assumption my automation will successfully execute exactly-once for each event: I need to get events from the calendar to verify if I already added the event and, eventually, delete it.

Hello everyone,
I’m so happy that the create_event service is available.
I see a very useful option but I cannot figure how to use it.

The option is “in” and the documentation indicates :

in — days or weeks that you want to create the event in. — “days”: 2 or “weeks”: 2

I try whitout succes :

data: 
  summary: "blabla" 
  in: "days: 2"

or

data: 
  summary: "blabla" 
  in: ""days": 2"

or

data: 
  summary: "blabla" 
  in_days: 2

Does somebody succed in using the “in” yaml option?
Thanks

Here is the link to the create_event documentation

Edit :
I found the solution, it was:

data: 
  summary: "blabla" 
  in:
    days: 2
1 Like

Hey, I can’t seem to find this button?

Neither on my phone, nor on my desktop.

I don’t see any calendars either in the Dev Tools service call:

Even though they do exist, and I see actual entries in the calendar:

Hey Allen,

Thanks for getting the create-event service working a while back!

I was wondering if you knew if there was a way to ‘copy’ the functionality of the button in the sidebar calendar to my dashboard? I assume that button pops up a card with entry fields, then the event is created using the create_event service, but I didn’t really want to take a day or two of trial and error getting something like that working since it already exists, just on a different page…!

Thanks,
Matthew

Hi, not totally sure I understand what you have in mind, but not I don’t think there is any existing code to create events elsewhere in the UI

Ok thanks.
I was hoping the " + Add Event " button (in the calendar sidebar screen) might call a service/script that opens the pop-up, so I could link it to another button on another dashboard. It sounds like the button’s action might not work the same way as a button element though.

Thanks for replying though, I appreciate it.

I still don’t understand the big picture of what you are trying to accomplish, nor the specifics of what you are asking. But if you want to make a custom card to call websocket APIs, that is a thing that exists.

Thanks for persisting with me!
The screenshot is from the calendar page in the sidebar/menu. It is the default HA calendar. I want a button on another page that opens an identical pop-up, but it sounds like I have to build it. I know I can use calendar.create_event to add the event, once I have the details available in the pop-up.
I’ll make a button to open my own form I’ll build to gather the necessary event information, like the default pop-up form does, then call calendar.create_event. I was just looking for shortcuts :slight_smile:

Thanks.

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

@iamdabe, thanks for posting. I’d managed to come up with a form that looks very much like yours, but you saved me some script writing time :slight_smile:, but I also had a dropdown to select the calendar to add it to (which I couldn’t add an entity to so need to hard code the options->entity map.

Is your New Event card simply a card on a dashboard? I had started building mine as a pop-up using browser_mod.popup, but found that the popup was replaced with the date selector, and then didn’t come back [EDIT: oh, just saw your releated comment] (I’ve only tested it in the browser mod menu section, not on a real dashboard, so maybe it will work in productions., but probably not)… so I was thinking of different ways to select the date. Clicking on a calendar day (as the crate event button) was one approach, but I’d be limited to days currently on my view… [EDIT 2: just looked into an expanding section to hide the form until the crete event buttoin is pressed. I haven’t read the details, but if I can expand it programatically it may be what I’m looking for!]

Thanks for your input. It is great to see someone has the essential functions working!