From f0af1eacfa8f8ad7b29c7224d2923464f63621e0 Mon Sep 17 00:00:00 2001 From: Joshua King Date: Sun, 9 Aug 2026 14:47:55 -0400 Subject: [PATCH] =?UTF-8?q?Show=20Mon=E2=80=93Fri=20school=20lunch=20menus?= =?UTF-8?q?=20in=20a=20full-width=20panel=20layout.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- dashboards/views/lunch-menus-dashboard.yaml | 225 ++++++++++++++------ packages/lunch_menus.yaml | 62 ++++++ 2 files changed, 227 insertions(+), 60 deletions(-) create mode 100644 packages/lunch_menus.yaml diff --git a/dashboards/views/lunch-menus-dashboard.yaml b/dashboards/views/lunch-menus-dashboard.yaml index 71073ca..f57b6c9 100644 --- a/dashboards/views/lunch-menus-dashboard.yaml +++ b/dashboards/views/lunch-menus-dashboard.yaml @@ -1,7 +1,8 @@ -# Lunch Menus — school cafeteria calendars (one week each) +# Lunch Menus — school cafeteria calendars (Mon–Fri each) # -# Three Google Calendar entities, each shown in listWeek so the wall/panel -# view stays focused on the current week instead of a full month grid. +# Panel layout so the title spans the full width and the three school cards +# sit in one row. Menus come from packages/lunch_menus.yaml (stock calendar +# cards cannot limit to a school-week window). title: Lunch Menus theme: cubecraft views: @@ -9,64 +10,168 @@ views: path: lunch-menus icon: mdi:food-apple theme: cubecraft - type: masonry + type: panel cards: - - type: markdown - content: | - # School Lunch Menus - ## Week of {{ now().strftime("%B %d, %Y") }} - card_mod: - style: | - ha-card { - background: var(--cc-gradient); - color: #fff; - border: none; - border-radius: var(--cc-radius-brand); - box-shadow: var(--cc-shadow-brand); - padding: 6px 12px; - text-align: center; - } - ha-card h1 { - margin: 0; - font-size: 1rem; - font-weight: 600; - letter-spacing: 0.02em; - opacity: 0.85; - color: #fff; - } - ha-card h2 { - margin: 2px 0 0 0; - font-size: 1.5rem; - font-weight: 800; - letter-spacing: -0.01em; - color: #fff; - } + - type: vertical-stack + cards: + - type: markdown + content: | + {% set wd = now().weekday() %} + {% if wd >= 5 %} + {% set monday = today_at() + timedelta(days=(7 - wd)) %} + {% else %} + {% set monday = today_at() - timedelta(days=wd) %} + {% endif %} + {% set friday = monday + timedelta(days=4) %} + # School Lunch Menus + ## {{ monday.strftime("%b %-d") }} – {{ friday.strftime("%b %-d, %Y") }} + card_mod: + style: | + ha-card { + background: var(--cc-gradient); + color: #fff; + border: none; + border-radius: var(--cc-radius-brand); + box-shadow: var(--cc-shadow-brand); + padding: 6px 12px; + text-align: center; + } + ha-card h1 { + margin: 0; + font-size: 1rem; + font-weight: 600; + letter-spacing: 0.02em; + opacity: 0.85; + color: #fff; + } + ha-card h2 { + margin: 2px 0 0 0; + font-size: 1.5rem; + font-weight: 800; + letter-spacing: -0.01em; + color: #fff; + } - - type: calendar - title: BHS Lunch Menu - initial_view: listWeek - entities: - - calendar.bhs_lunch_menu - card_mod: &cc_calendar - style: | - ha-card { - --calendar-day-color: var(--cc-text, var(--primary-text-color)); - --calendar-day-weekday-color: var(--cc-text-muted, var(--secondary-text-color)); - --fc-today-bg-color: var(--cc-accent-soft); - --fc-event-bg-color: var(--cc-accent); - --fc-event-border-color: var(--cc-accent); - } + - type: grid + columns: 3 + square: false + cards: + - type: markdown + title: BHS Lunch Menu + entity_id: sensor.bhs_lunch_menu_week + content: | + {% set events = state_attr('sensor.bhs_lunch_menu_week', 'events') or [] %} + {% if events is string %}{% set events = [] %}{% endif %} + {% set wd = now().weekday() %} + {% if wd >= 5 %} + {% set monday = today_at() + timedelta(days=(7 - wd)) %} + {% else %} + {% set monday = today_at() - timedelta(days=wd) %} + {% endif %} + {% for offset in range(5) %} + {% set d = (monday + timedelta(days=offset)).date() %} + {% set d_str = d.isoformat() %} + {% set ns = namespace(found=false) %} + ### {{ d.strftime("%A") }} + {{ d.strftime("%b %-d") }} + {% for e in events if e.start is defined and e.start[:10] == d_str %} + {% set ns.found = true %} + - {{ e.summary }} + {% endfor %} + {% if not ns.found %} + _No menu listed_ + {% endif %} - - type: calendar - title: BIS School Lunches - initial_view: listWeek - entities: - - calendar.bis_school_lunches - card_mod: *cc_calendar + {% endfor %} + card_mod: &cc_menu + style: | + ha-card .card-header { + color: var(--cc-text, var(--primary-text-color)); + font-weight: 700; + } + ha-markdown { + padding-top: 0 !important; + } + ha-markdown h3 { + margin: 0.85rem 0 0.15rem 0; + font-size: 1rem; + font-weight: 700; + color: var(--cc-accent, var(--primary-color)); + } + ha-markdown h3:first-child { + margin-top: 0; + } + ha-markdown p { + margin: 0 0 0.35rem 0; + color: var(--cc-text-muted, var(--secondary-text-color)); + font-size: 0.85rem; + } + ha-markdown ul { + margin: 0 0 0.5rem 0; + padding-left: 1.1rem; + } + ha-markdown li { + margin: 0.15rem 0; + color: var(--cc-text, var(--primary-text-color)); + } + ha-markdown em { + color: var(--cc-text-muted, var(--secondary-text-color)); + } - - type: calendar - title: HMS Lunch Menu - initial_view: listWeek - entities: - - calendar.hms_lunch_menu - card_mod: *cc_calendar + - type: markdown + title: BIS School Lunches + entity_id: sensor.bis_lunch_menu_week + content: | + {% set events = state_attr('sensor.bis_lunch_menu_week', 'events') or [] %} + {% if events is string %}{% set events = [] %}{% endif %} + {% set wd = now().weekday() %} + {% if wd >= 5 %} + {% set monday = today_at() + timedelta(days=(7 - wd)) %} + {% else %} + {% set monday = today_at() - timedelta(days=wd) %} + {% endif %} + {% for offset in range(5) %} + {% set d = (monday + timedelta(days=offset)).date() %} + {% set d_str = d.isoformat() %} + {% set ns = namespace(found=false) %} + ### {{ d.strftime("%A") }} + {{ d.strftime("%b %-d") }} + {% for e in events if e.start is defined and e.start[:10] == d_str %} + {% set ns.found = true %} + - {{ e.summary }} + {% endfor %} + {% if not ns.found %} + _No menu listed_ + {% endif %} + + {% endfor %} + card_mod: *cc_menu + + - type: markdown + title: HMS Lunch Menu + entity_id: sensor.hms_lunch_menu_week + content: | + {% set events = state_attr('sensor.hms_lunch_menu_week', 'events') or [] %} + {% if events is string %}{% set events = [] %}{% endif %} + {% set wd = now().weekday() %} + {% if wd >= 5 %} + {% set monday = today_at() + timedelta(days=(7 - wd)) %} + {% else %} + {% set monday = today_at() - timedelta(days=wd) %} + {% endif %} + {% for offset in range(5) %} + {% set d = (monday + timedelta(days=offset)).date() %} + {% set d_str = d.isoformat() %} + {% set ns = namespace(found=false) %} + ### {{ d.strftime("%A") }} + {{ d.strftime("%b %-d") }} + {% for e in events if e.start is defined and e.start[:10] == d_str %} + {% set ns.found = true %} + - {{ e.summary }} + {% endfor %} + {% if not ns.found %} + _No menu listed_ + {% endif %} + + {% endfor %} + card_mod: *cc_menu diff --git a/packages/lunch_menus.yaml b/packages/lunch_menus.yaml new file mode 100644 index 0000000..eda6e37 --- /dev/null +++ b/packages/lunch_menus.yaml @@ -0,0 +1,62 @@ +################################################################################ +# lunch_menus.yaml +# +# Pulls Mon–Fri of the current school week from each lunch Google Calendar into +# template sensors. On Sat/Sun, advances to next week's Monday. The Lunch Menus +# dashboard renders those attributes — the stock calendar card has no school- +# week view. +################################################################################ + +template: + - trigger: + - platform: time_pattern + minutes: "/15" + - platform: homeassistant + event: start + - platform: event + event_type: event_template_reloaded + action: + - variables: + # weekday(): Mon=0 … Sun=6. Weekend → next Monday. + school_monday: >- + {% set wd = now().weekday() %} + {% if wd >= 5 %} + {{ (today_at() + timedelta(days=(7 - wd))).isoformat() }} + {% else %} + {{ (today_at() - timedelta(days=wd)).isoformat() }} + {% endif %} + - action: calendar.get_events + target: + entity_id: + - calendar.bhs_lunch_menu + - calendar.bis_school_lunches + - calendar.hms_lunch_menu + data: + start_date_time: "{{ school_monday }}" + duration: + days: 5 + response_variable: agenda + sensor: + - name: "BHS Lunch Menu Week" + unique_id: bhs_lunch_menu_week + icon: mdi:food-apple + state: "{{ agenda['calendar.bhs_lunch_menu'].events | count }}" + attributes: + events: "{{ agenda['calendar.bhs_lunch_menu'].events }}" + week_start: "{{ school_monday }}" + + - name: "BIS Lunch Menu Week" + unique_id: bis_lunch_menu_week + icon: mdi:food-apple + state: "{{ agenda['calendar.bis_school_lunches'].events | count }}" + attributes: + events: "{{ agenda['calendar.bis_school_lunches'].events }}" + week_start: "{{ school_monday }}" + + - name: "HMS Lunch Menu Week" + unique_id: hms_lunch_menu_week + icon: mdi:food-apple + state: "{{ agenda['calendar.hms_lunch_menu'].events | count }}" + attributes: + events: "{{ agenda['calendar.hms_lunch_menu'].events }}" + week_start: "{{ school_monday }}"