Picnic.app integration

I saw that there was some interest in a custom component for Picnic.app. I am not an avid user of Home Assistant myself (yet), but I wanted to contribute to this amazing project. Therefore I reverse engineered the android app.

You can follow the instructions here for installation and usage:

Also, these are my first projects, so feedback is welcome!
The integration hasn’t been tested fully yet!

I would like to thank @ptnijssen and his jumbo integration for allowing me to use parts of his code.

8 Likes

Thanks!
I’ve installed it, so far so good anyway, will need to do some groceries :wink:

Works great! Thank you.
Exaclty what I needed and good sensors.

Thanks for making an effort!
If I understand correctly, it is not possible to add items to basket from the integration. Is this something you plan to add in the future? Would it be possible?

That would be possible for sure!
I was’t planning on doing this in the short term, since I don’t know in what way this would be implemented (interface wise). Would this be done through an automation or lovelace card?

First I want to finish the notification system (since there are still some problems with it :wink:) and my development cycle is somewhat limited due to me only being able to preform real tests once a week when I order from picnic :sweat_smile:

1 Like

The way I would see it, would be setting up several sensors around the house that measure when something is out of stock. Then via HA automation it could be added to the basket. Perhaps via a service with as data the item that needs to be added. Just an idea.

I’ll be following this project with interest.

1 Like

Has somebody examples of how they are using this integration on their lovelace?
maybe maps can be used to see picnic driving :stuck_out_tongue:

1 Like

Hey guys,

Sorry for the radio silence of the last months. I’ve been busy with wrapping up my masters degree + was moving.

I didn’t have the time yet to setup HA and hence can’t really test or use my integration atm + picnic has put me on the waiting list for my current area! So testing from my part will be limited.

I have 2 questions:

  • Could someone provide me some automation examples for the github readme (and maybe help out Ferrymug
  • Provide me some info on how to make the feature that @repjas sugested above

Thanks in advance!

Thanks for the picnic integration! I’m just learning to deal with it …
I solved that with this template:

  • platform: template
    sensors:
    picnic_liefer_zeit_anfang:
    friendly_name: “Picnic Lieferzeitfenster Start”
    icon_template: mdi:clock-outline
    value_template: ‘{{as_timestamp(states.sensor.picnic_delivery.attributes[“delivery”][“window_start”]) | timestamp_custom ("%d-%m-%Y %H:%M") }}’

I use this sensor to get informed one hour before the time window closes to order goods:

  • platform: template
    sensors:
    picnic_order_last_chance:
    friendly_name: “Picnic letzte Chance "
    value_template: '{{as_timestamp(states.sensor.picnic_delivery.attributes[“delivery”][“cut_off_time”]) | timestamp_custom (”%d-%m-%Y %H:%M") }}’

This is my automation:

  • id: ‘XXXXXXXX’
    alias: Picnic letzte Chance
    description: Das Zeitfenster zum Befüllen des Warenkorbs endet in 1 Stunde
    trigger:
    • platform: template
      value_template: “’{{ (((states.sensor.picnic_order_last_chance.state)| int) -
      \ as_timestamp(states.sensor.date.state\n + ‘’ ‘’ + states.sensor.time.state)
      \ |int ) - 3690 < 0 }}’”
      condition: []
      action:
    • service: input_boolean.toggle
      data: {}
      entity_id: input_boolean.shopping_list_message
    • service: notify.ha_nachricht
      data:
      message: XXXXXXXX

Hi Mike and Schreg,

I have also implemented this succefully. However i had to modify the automation a little bit (maybe due to regional settings?).

Here is what I added in the configuration.yaml:

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
  - platform: picnic
    username: !secret picnic_usr
    password: !secret picnic_pw
    country_code: "NL" 
  - platform: template
    sensors:
        picnic_delivery_start:
          friendly_name: Picnic Delivery timslot Start
          icon_template: mdi:clock-outline
          value_template: "{{ as_timestamp(states.sensor.picnic_delivery.attributes['delivery']['window_start']) | timestamp_custom ('%d-%m-%Y %H:%M') }}"

and here is the automation I use:

alias: Picnic in 30 mins
description: ''
trigger:
  - platform: template
    value_template: >-
      {{as_timestamp(states.sensor.picnic_delivery.attributes['delivery']['window_start'])
      - as_timestamp(states.sensor.date.state + " " + states.sensor.time.state)
      - 1800 < 0}}
condition: []
action:
  - service: notify.persistent_notification
    data:
      message: Picnic in 30 minutes
      title: Notification
mode: single

Great integration. Works perfectly.

Just to get some people up and running below you can find some template examples:

// Show all upcoming (available timeslots)
{% for timeslot in state_attr('sensor.picnic_delivery_time_slots', 'time_slots') -%}
{% if timeslot.is_available == true -%}    
  {{
    as_timestamp(timeslot.window_start) | timestamp_custom('%a %b %d, %H:%M') 
    + ' - ' 
    + as_timestamp(timeslot.window_end) | timestamp_custom('%H:%M') 
  }}     
{% endif -%}
{% endfor %}

// Results
Thu Feb 11, 21:00 - 22:00     
Fri Feb 12, 18:15 - 19:15     
Sat Feb 13, 21:00 - 22:00     
Sun Feb 14, 15:30 - 16:30     
Mon Feb 15, 11:30 - 12:30     
Mon Feb 15, 21:00 - 22:00

// Setup integration (Use secrets)
- platform: picnic
  username: !secret picnic_username
  password: !secret picnic_password
  country_code: "NL"

// Create a friendly template sensor
- platform: template
  sensors:
    picnic_next_delivery_formatted:
      friendly_name: "Picnic Next Delivery"
      value_template: "{{ 
        as_timestamp(state_attr('sensor.picnic_delivery', 'delivery').window_start) 
        | timestamp_custom('%a %b %d, %H:%M') 
        + ' - ' 
        + as_timestamp(state_attr('sensor.picnic_delivery', 'delivery').window_end) 
        | timestamp_custom('%H:%M') 
      }}"
      icon_template: mdi:truck-delivery
    picnic_first_available_timeslot_formatted:
      friendly_name: "Picnic First Available Timeslot"
      value_template: "{% set ns = namespace(found=false) %}
        {% for timeslot in state_attr('sensor.picnic_delivery_time_slots', 'time_slots') -%}
        {% if timeslot.is_available == true and ns.found == false -%}    
          {{
            as_timestamp(timeslot.window_start) | timestamp_custom('%a %b %d, %H:%M') 
            + ' - ' 
            + as_timestamp(timeslot.window_end) | timestamp_custom('%H:%M') 
          }}  
          {% set ns.found = true %}
        {% endif -%}
        {% endfor %}"
      icon_template: mdi:calendar-clock
1 Like

Hi,

Is this the same as the picnic integration that can be installed via home assistant directly?

I installed this default picnic integration, ran this “$ pip install python-picnic-api” via the terminal, but I get this error message:
image

Does anybody know what I should do to fix this?
And are the sensors from the integration added by default (once it works) or should I configure this manually in my configuration file?

Thank a lot!
Job

Great integration, keen to hear if we can further develop this integration (e.g. adding shopping etc).

1 Like

This would be awesome

Toilet paper is the only one that i could think of that would make this actually usefull with a sensor
not sure how i would do this for other items

i think that replaced this one

I love the integration and I am trying to use it to make it easier to order particular batches (e.g. basics or specific recipes). However, here the matching with product names is not reliable enough.

To get Picnic product ids I have been using python-picnic-api and searched for items. This yields output like the following:

[{'type': 'CATEGORY',
  'id': 'avocado',
  'links': [{'type': 'SEARCH',
    'href': 'https://storefront-prod.nl.picnicinternational.com/api/15/search?search_term=avocado'}],
  'name': 'avocado',
  'items': [{'type': 'SINGLE_ARTICLE',
    'id': 's1007465',
    'decorators': [{'type': 'FRESH_LABEL', 'period': 'P7D'},
     {'type': 'UNIT_QUANTITY', 'unit_quantity_text': '4 stuks'}],
    'name': "Baby avocado's eetrijp",
    'display_price': 279,
    'price': 279,
    'image_id': '56fab15b05ba086961addea64229ef66cf2cad38008379f29b7ef6de232b0863',
    'max_count': 50,
    'unit_quantity': '4 stuks',
    'unit_quantity_sub': '€5.67/kg',
    'tags': []},
   {'type': 'SINGLE_ARTICLE',
    'id': 's1010706',
    'decorators': [{'type': 'PROMO', 'text': 'nu €2.69'},
     {'type': 'FRESH_LABEL', 'period': 'P3D'},
     {'type': 'PRICE', 'display_price': 269},
     {'type': 'PRICE_STYLE', 'price_color': 'RED1'},
     {'type': 'UNIT_QUANTITY', 'unit_quantity_text': '2 stuks'},
     {'type': 'VALIDITY_LABEL', 'valid_until': '2024-03-03'}],
    'name': 'Avocado eetrijp',
    'display_price': 299,
    'image_id': '01b712926580ab7ef2365230784488105d0d3cd6ab5a13aabc034c03f1ce43b2',
    'max_count': 50,
    'unit_quantity': '2 stuks',
    'unit_quantity_sub': '€7.69/kg',
    'tags': []},

Unlike the example code shown at https://github.com/MikeBrink/python-picnic-api, the ids offered by the API here are labeled with a preceding ‘s’. And, unlike the aforementioned code, adding these id values within the Picnic app does not lead to a product listing.

I am trying to figure out how to turn these ids into actual product ids that can be used in the integration, but am hitting a wall!