Help with a weekly shift card for my partner

Hi All,

I’m looking for some help with something I’m trying to do. My partner works shift in a 4 on and 4 off pattern. I have created a calendar for her work shifts which lasts 4 days and starts at 00:00 on day 1 and ends at 23:59 on day 4. This repeats every 8 days.

What I would like to do is create something like below.

image

I had implemented this already and it was working great until her shift ended yesterday and Tuesday- Friday which was red turned Green. This is because the calendar only returns current or future events.

Here is the code for one day on the card.

          - type: custom:mushroom-template-card
            primary: M
            secondary: ""
            icon: ""
            card_mod:
              style:
                mushroom-state-info$: |
                  .primary {
                    --card-primary-font-weight: 350;
                    --card-primary-color: black;
                    --card-primary-font-size: 15px;
                    text-align: center;
                  }
                .: |
                  ha-card {
                    {% set monday = now().replace(hour=8, minute=15, second=0, microsecond=0) + timedelta(days=(0 - now().weekday())) %}
                    {% set start_time = states.calendar.sarah_work.attributes.start_time | as_datetime | as_local %}
                    {% set end_time = states.calendar.sarah_work.attributes.end_time | as_datetime | as_local %}
                    {% set is_working_monday = start_time <= monday <= end_time %}
                    background-color: {{ 'indianred' if is_working_monday else 'darkseagreen' }};
                    border-radius: 100%;
                    max-width: 35px;
                    max-height: 35px;
                    box-shadow: 3px 2px 8px rgba(0, 0, 0, 0.4);
                  }

Is there a better way to achieve this? I have tried using get.calendar_events and populating it using the current week Mon - Sun but I then couldn’t think of a way to use that on the card.

Any help would be greatly appreciated.