I’ve been looking for a way to integrate our weekly family meal planning into home assistant. I wasn’t keen on trying to get Grocy set up or using some of the custom integrations (i.e. with paprika) as I wanted to avoid a dependency on any 3rd parties.
I also wanted to see if it was possible to achieve this just using core HA features. Although I’ve used a few HACs components, they aren’t doing anything that couldn’t be acheived natively, just with a little less polish.
I’ve previously done stuff with input text fields for each day of the week, that automatically clear at the end of each day, to allow us to then enter meals for the next week.
This had started to become difficult and we’d had more than one occasion where we were planning a meal before the old value had cleared, resulting in missed meals and having to remember to go back at a later date to update the values, which definitely failed the partner test.
So I decided to go back to the drawing board. First things first, I wrote down my high level requirements:
- Enter main meals for each day of the week
- Enter lunches for days we need them
- track if we’re making snacks
- plan our daughters packed lunches for school
- Easily see what is for our evening meal today
- See what meals we’ve got planned (and what day they are)
- Link to recipes if possible
- allow meals to be easily entered on mobile
From this, I identified 3 core components:
- Somewhere to enter the meals and required details
- Somewhere to view the meals today
- Somewhere to view a weekly/monthly view
The more I looked, the more it made sense to try and achieve what I wanted with a local calendar.
Adding Meals to the Plan
Within my dashboard, I’ve created a ‘Food Management’ tab. This is accessed on mine and my partners device via an app shortcut.
The page has a 4 button selector, which changes the value of a dropdown select. Button card styling highlights which option is selected.
There are then input text and input datetime helpers where we can set the name of the meal and the date it’s for. the datetime helper by default includes a fully functioning date picker.
Once we’ve added the meal and date, we can choose to either add the meal, or add it and increment the date to tomorrow.
This is achieved by calling one of two scripts. Each scripts runs the following automation:
alias: create meal
description: "automation to create a new calendar event in 'Meals' based on the values of various input helpers"
trigger: []
condition: []
action:
- service: calendar.create_event
metadata: {}
data:
summary: >-
{{ states('input_select.meal_type') }} - {{
states('input_text.meal_title') }}
start_date_time: >-
{{ as_timestamp(states('input_datetime.meal_date')) |
timestamp_custom('%Y-%m-%d 00:00:00', true) }}
end_date_time: >-
{{ as_timestamp(states('input_datetime.meal_date')) |
timestamp_custom('%Y-%m-%d 23:59:59', true) }}
target:
entity_id: calendar.meals
- service: browser_mod.notification
metadata: {}
data:
message: {{
states('input_text.meal_title') }} added
target:
device_id: c68c8673566e917f37c0cc07cacee54e
mode: single
This sets the event title as the meal type and name, hyphen separated and sets the event to run from midnight to 11:59:59
I also use browser mode to give confirmation that the automation has triggered
Each script additionally clears the value in the input text
If the user has chosen to increment the day, then the datetime set service is called and the vlaue incremented by 86400 seconds (i.e. 1 day)
Viewing Meals
On my main kitchen dashboard, this is then displayed using atomic calendar revive
This calendar is set to only show a single day
Clicking ‘View Meals’ invokes a bubble card pop up which shows all meals entered over the next 7 days
Because that is also an atomic calendar, clicking the calendar title switches into a month view
One thing not shown here is that by adding a link to the event description, I can also create links to the recipe.