Hey I just drove through Bettendorf today, small world. You probably have already figured it out by now, but here is the fix you were looking for just in case:
Change:
{{ day.menu_items | selectattr("food.food_category","equalto","entree") | slice(2) | first | join('; ', attribute="food.name") }}<br/>
To:
{{ day.menu_items | selectattr("food.name", 'defined') | slice(1) | first | join('; ', attribute="food.name") }}<br/>
The defined part is important because it will error if the value doesnāt exist. Also changing slice(2) to slice(1) gives all the results. Otherwise it was cutting off some menu items for me. I also went with food.name because at least for our school the food category is never used. I took your code and built on it. Here is what I am using:
List meals for entire week:
{% for day in state_attr('sensor.school_lunch', 'days') |
selectattr("menu_items") | selectattr("date", "greaterthan",
(now()-timedelta(hours=12)).strftime("%Y-%m-%d")) %}
{%- if day.date == now().strftime("%Y-%m-%d") -%}<b><u>TODAY</b></u>:{{" "}}
{%- elif day.date == (now()+timedelta(hours=24)).strftime("%Y-%m-%d")
-%}<b><u>TOMORROW</b></u>:{{" "}}{{"
"}}
{%- else -%}<b><u> {{- strptime(day.date, "%Y-%m-%d").strftime("%A").upper() -}}</b></u>:{{"
"}}
{%- endif -%}
{% for result in day.menu_items | selectattr("position", 'defined') %}
{%- if result.text != "" -%}
<br><b><i>{{ result.text }}</b></i><br>
{%- endif -%}
{%- if result.food is not none -%}
{{ result.food.name }}<br>
{%- endif -%}
{% endfor %}
<br>
{% endfor %}
This method lists each item in order so that I could include the section titles as well (ex: alternate). It ends up looking like this:
I also created a grid card to show the lunch menu with pictures for the next two days. I have the screen real estate so mine is larger than some people may want. I set it to show today and tomorrow if it is before 8AM or to show the next two days if it is after 8AM. I also hide the whole thing on Saturdays:
square: false
type: grid
columns: 2
cards:
- type: markdown
content: |-
<center>
{% for day in state_attr('sensor.school_lunch', 'days') |
selectattr("menu_items") | selectattr("date", "equalto",
now().strftime("%Y-%m-%d")) %}
<b><u>TODAY</b></u>
{% for result in day.menu_items | selectattr("position", 'defined') %}
{%- if result.text != "" -%}
<font color='yellow'><br><b><i>{{ result.text }}</b></i><br><br></font>
{%- endif -%}
{%- if result.food is not none -%}
<img src='{{ result.food.image_url }}' width='150' ><br>
{%- endif -%}
{%- if result.food is not none -%}
{{ result.food.name }}<br><br>
{%- endif -%}
{% endfor %}
<br>
{% endfor %}
</center>
visibility:
- condition: state
entity: binary_sensor.nutrislice_before_8
state: 'on'
- type: markdown
content: |-
<center>
{% for day in state_attr('sensor.school_lunch', 'days') |
selectattr("menu_items") | selectattr("date", "equalto",
(now()+timedelta(hours=24)).strftime("%Y-%m-%d")) %}
<b><u>TOMORROW</b></u>
{% for result in day.menu_items | selectattr("position", 'defined') %}
{%- if result.text != "" -%}
<font color='yellow'><br><b><i>{{ result.text }}</b></i><br><br></font>
{%- endif -%}
{%- if result.food is not none -%}
<img src='{{ result.food.image_url }}' width='150' ><br>
{%- endif -%}
{%- if result.food is not none -%}
{{ result.food.name }}<br><br>
{%- endif -%}
{% endfor %}
<br>
{% endfor %}
</center>
- type: markdown
content: >+
<center>
{% for day in state_attr('sensor.school_lunch', 'days') |
selectattr("menu_items") | selectattr("date", "equalto",
(now()+timedelta(hours=48)).strftime("%Y-%m-%d")) %}
<b><u> {{- strptime(day.date, "%Y-%m-%d").strftime("%A").upper()
-}}</b></u>
{% for result in day.menu_items | selectattr("position", 'defined') %}
{%- if result.text != "" -%}
<font color='yellow'><br><b><i>{{ result.text }}</b></i><br><br></font>
{%- endif -%}
{%- if result.food is not none -%}
<img src='{{ result.food.image_url }}' width='150' ><br>
{%- endif -%}
{%- if result.food is not none -%}
{{ result.food.name }}<br><br>
{%- endif -%}
{% endfor %}
<br>
{% endfor %}
</center>
visibility:
- condition: state
entity: binary_sensor.nutrislice_before_8
state: 'off'
title: School Lunch
visibility:
- condition: state
entity: sensor.day_of_the_week
state_not: '6'
Iām no pro so there may be a better way of doing this, but it worked for me. Thanks for sharing your part!