Iâm still playing around with things, but hereâs where things currently stand:
1.) Created (5) sensors - one for each day of the week - and added them to my configuration.yaml file using File Editor.
Youâll want to edit the URL details to match your specific school but the format shouldnât change much.
While I canât speak to every scenario, the weekly calendar starts on Sunday with day â0â and runs through Saturday with day â6â so I called out only Monday through Friday (i.e., Days 1 - 5).
Also, I didnât want to ping the site incessantly, so I set the refresh to every 8 hours (i.e., 28800 seconds) but you can certainly toggle that as you see fit.
#FCPS School Lunch
- platform: rest
name: lunch Monday
scan_interval: 28800
resource_template: https://fcps.api.nutrislice.com/menu/api/weeks/school/woodson-high-school/menu-type/hs-lunch/{{now().strftime('%Y/%m/%d')}}?format=json
value_template: 'OK'
json_attributes_path: $.days.1
json_attributes:
- menu_items
- platform: rest
name: lunch Tuesday
scan_interval: 28800
resource_template: https://fcps.api.nutrislice.com/menu/api/weeks/school/woodson-high-school/menu-type/hs-lunch/{{now().strftime('%Y/%m/%d')}}?format=json
value_template: 'OK'
json_attributes_path: $.days.2
json_attributes:
- menu_items
- platform: rest
name: lunch Wednesday
scan_interval: 28800
resource_template: https://fcps.api.nutrislice.com/menu/api/weeks/school/woodson-high-school/menu-type/hs-lunch/{{now().strftime('%Y/%m/%d')}}?format=json
value_template: 'OK'
json_attributes_path: $.days.3
json_attributes:
- menu_items
- platform: rest
name: lunch Thursday
scan_interval: 28800
resource_template: https://fcps.api.nutrislice.com/menu/api/weeks/school/woodson-high-school/menu-type/hs-lunch/{{now().strftime('%Y/%m/%d')}}?format=json
value_template: 'OK'
json_attributes_path: $.days.4
json_attributes:
- menu_items
- platform: rest
name: lunch Friday
scan_interval: 28800
resource_template: https://fcps.api.nutrislice.com/menu/api/weeks/school/woodson-high-school/menu-type/hs-lunch/{{now().strftime('%Y/%m/%d')}}?format=json
value_template: 'OK'
json_attributes_path: $.days.5
json_attributes:
- menu_items
2.) Created a markup card that displays the menu items for the current day.
Youâll see that I âremovedâ milk from the results with a replace function, itâs on the menu every day and not really of interest to me personally. You could copy-and-paste that same code to filter out other items if you needed, or remove it altogether and see everything for a given day.
- type: markdown
title: Lunch
content: >-
{% set lunch = state_attr('sensor.lunch_' +
now().strftime('%A')|lower,'menu_items') %}
{% for x in range(0,lunch| count) %}
{% if lunch[x].food != None %}
{{ lunch[x].food.name | replace('Milk, Fat Free Unflavored','')|
replace('Milk, Fat Free Chocolate','')| replace('Milk, 1%
Unflavored','')}}
{% endif %}
{% endfor %}
This has been a big hit - and thank you to @vingerha and @mekaneck for chiming in!
Two questions.
1.) I built five similar sensors for breakfast - is there a way to add those breakfast items to the same markup card? Iâm thinking itâs something to do with the âcontentâ code but I donât really understanding templating well.
2.) Is there a way to make a card that only displays when thereâs a given item - conditional formating or somethingâŚFor example, if they have âpancakesâ for breakfast, it would pop-up but would otherwise stay hidden.