I use Paprika to manage my grocery lists, recipes, and meal planning. They don’t have an official API but some of it has been… deduced by the community. This is my first Paprika integration attempt, but I’ll post more because I am likely to want to integrate grocery lists at the very least.
I added the following to configuration.yaml
which creates a sensor that reads the dinner meal for the day:
sensor:
- platform: rest
resource: https://www.paprikaapp.com/api/v2/sync/meals/
name: Dinner Tonight
method: GET
value_template: >
{% set ns = namespace(found=false) %} {% for meal in
value_json.result if meal["date"][0:10] == now().isoformat()[0:10]
and meal.type == 2 -%} {{ meal.name }} {% set ns.found = true %}
{%- endfor %} {% if ns.found == false %} No dinner planned yet for
tonight. {% endif %}
headers:
Authorization: >
Bearer MY_AUTH_TOKEN
Explanation
This uses RESTful Sensor to poll a REST API. This is polling the v2 meals
endpoint, which returns your meal plan items.
I’m new to Jinja2 templates so there’s probably a more elegant way but basically what happens in the value_template
is:
- create a temp variable (technically a namespace, this is required due to jinja2 quirks) called
ns
and set itsfound
property tofalse
- go through each meal plan item and compare the first ten characters of the date (so just the
2024-03-21
part, for example) with the first ten characters of the current date. If these match, I know it’s an entry for a meal from today. Ifmeal.type
is2
, then I know it’s dinner. (0 is breakfast, 1 is lunch, 3 is snacks). So if the date matches and it’s dinner, I rendermeal.name
and then also setns.found
to be true. - otherwise (if
ns.found
is false) I render the textNo dinner planned yet for tonight.
MY_AUTH_TOKEN
is the token I receive in response when I send the following curl
command from the command line:
curl -X POST https://paprikaapp.com/api/v2/account/login -d 'email=MY_EMAIL&password=MY_PAPRIKA_PASSWORD'
And that’s it! There’s now a Dinner Tonight
sensor available and I use it in two places.
Markdown card to display dinner on a dashboard
This also uses card_mod
to style it a little nicer.
type: markdown
content: |-
### Dinner tonight
{{ states('sensor.dinner_tonight') }}
card_mod:
style:
ha-markdown:
$: |
h3 {
margin-bottom: 0;
}
p {
margin-top: 8px;
}
.: |
ha-card {
font-size: 1.5em;
line-height: 1.5em;
}
Dinner notifications to household members
This is a script that sends a notification via the Home Assistant app to a person. It includes the dinner info from the sensor above, and also when you click the notification on Android it sends you to a dashboard that has the dinner info as well. (The clicking is handled differently on different platforms, see the docs for more.
alias: dinner_script
sequence:
- service: notify.mobile_app_persons_device
metadata: {}
data:
data:
clickAction: /dashboard-dinner/0
message: "{{ states('sensor.dinner_tonight') }}"
mode: single