Paprika recipe app integration: What's for dinner tonight?

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 its found property to false
  • 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. If meal.type is 2, 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 render meal.name and then also set ns.found to be true.
  • otherwise (if ns.found is false) I render the text No 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.

image

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
2 Likes

I’m a Paprika user too, so thanks for this!

1 Like

Interesting project. I also rely on Paprika Recipe Manager 3. However, the “curl” command;
curl -X POST https://paprikaapp.com/api/v2/account/login -d 'email=MY_EMAIL&password=MY_PAPRIKA_PASSWORD
does not give the MY_AUTH_TOKEN. Any ideas why?

@hawkplace, I was missing a quotation mark which I’ve since edited the post to add. Try this instead:

And forgive me if you already know this but I have to be thorough when giving help to strangers online: MY_EMAIL should be the full email address for your Paprika account, and MY_PAPRIKA_PASSWORD needs to be the full password. Seems obvious but I have to mention it!

Thank you for this, now I’ve got it set up as well, and pushed to a Dakboard

1 Like

Hi,

Awesome idea.
I’m looking into using paprika too,
Any update on how to integrate the shopping list from paprika into home assistant?

Thanks

For those who have special characters in their passwords. the following will work:

curl -X POST https://paprikaapp.com/api/v2/account/login --data-urlencode 'email=MY_EMAIL' --data-urlencode 'password=MY_PAPRIKA_PASSWORD'

Thanks Darius

1 Like

Hi, trying to get this to work. I’m getting a {“error”:{“code”:0,“message”:“Invalid email address.”}} when I try the curl command. I double checked I had the correct email address so not sure what would cause this.

Anything I could try here?