Show tomorrows calendar event as secondary info in Mushroom template card

Hey there…

I want to display the workshifts of my wife in my HA dashboard. My primary information tells my which shift she have today (morning-, late-, nightshift). But I can’t figure out how to display tomorrows calendar event.

I probably made it very difficultly because I can’t really code :smiley: so if todays event has a specific word in it (morningshift, Lateshift, and so on), on of four toggle helper switch to on, three of four switch to off. In my mind I wanted to archive the same with tomorrow’s event.

Can someone please help or have a better idea how to do this?

Thanks from Germany!

The basic method you will need to use is to set up a Template sensor to retrieve and store tomorrow’s event. Then you would use the new sensor’s value in your mushroom template card.

Service: calendar.list_events

I have tried to make a template sensor already, but it won’t show anything.

Could you send me an example how this code would look like? So I can “just” change to my credentials :wink:

You will need to provide some details about how the calendar is being used.

For example, does the calendar include other events that are not work shifts that will need to be ignored? If yes, what details exist that would allow us to select work shifts. Is the shift type held in the title or description of the calendar event? Is the type held by itself or is there other data that needs to be removed?

The easiest way to give us all the useful information is to use the Services tool to call the following (make sure to use your calendar’s id):

service: calendar.list_events
target:
  entity_id: calendar.example
data:
  duration:
    hours: 24
response_variable: agenda

Then post the response. Feel free to modify/obfuscate personal information, but be careful not to alter the structure.

The calendar only contains her shifts (Morning-, late, Nightshift and free). I made a dedicated local calendar just for this purpose. The shifts name is only displayed in the Title of the event.

Then post the response. Feel free to modify/obfuscate personal information, but be careful not to alter the structure.

events:
  - start: "2023-11-07"
    end: "2023-11-08"
    summary: Spätschicht
    description: ""
  - start: "2023-11-08"
    end: "2023-11-09"
    summary: Frei
    description: ""

All entries are a full day. I hope that’s the right term for what i want to explain. In german is called “Ganztägig” :smiley:

template:
  - trigger:
      - platform: time
        at: "00:01:00"
      - platform: event
        event_type: event_template_reloaded
    action:
      - service: calendar.list_events
        target:
          entity_id: calendar.EXAMPLE
        data:
          duration:
            hours: 24
        response_variable: agenda
    sensor:
      - name: Tomorrow's Workshift
        state:  "{{ (agenda.events | selectattr('start', 'eq', (now()+timedelta(days=1)).date()|string ) | first).summary }}"
        availability: "{{ (agenda.events | selectattr('start', 'eq', (now()+timedelta(days=1)).date()|string )| first) is defined }}"

Make sure to change the entity_id to your calendar’s ID.

EDIT: Added Availability template

I think im dump…I made the Template sensor and checking it in devtools and it has an unknown state

You can’t test that example in the Template Editor. The agenda variable is defined by the execution of the calendar.list_events service call but the Template Editor cannot execute service calls.

To clarify, did you try to test the template in the Template editor tool (which @123 addressed above) or are you saying the entity’s state is “unknown” in the States tool? If you are talking about the States tool, make sure to load the template by Restarting Home Assistant.

yes, i did restart before i checked the state. here’s what it said:

Did you change the entity id to your calendar?

yes of course :slight_smile:

Go to the YAML tool, scroll down and click “Template Entities” to force a reload then check the entity in the States tool again.

That helped! now it shows me the right State/Titel

THANK YOU!

1 Like