TooGoodToGo MQTT Bridge

When you get the info is there also a value with “today” and “Tomorrow” ?
Sometimes you can pick it up today or you bye for next day?

there is a pickup window available:

image

Will have a look at how to add it as useful data.
It is only available when there is stock.

I could either parse it into some human-readable like in 3 hours or just parse around the window. this would lead to some ugly situations when there is now a window available but some automation relies on it…

I guess I will give the humanize version a go, looks the most useful to me.

1 Like

Would this be useful?

Locale nl

Locale en_us

That look nice! I will also try something.
Maybe something with a new sensor and check the dates of it is today or tmorrow

EDIT: I see that the times now are not in the sensors. When you can add them I can try my solution what I write above…

New version v1.1.0 is out :slight_smile:

To have some timestamp magic inside templates this could help:


{{
  as_timestamp(
    strptime(
      state_attr('sensor.toogoodtogo_vitamininsel', 'pickup_start')[0],
      '%Y-%m-%d %H:%M:%S')
    )
}} 
1 Like

Let me play with it :slight_smile:

Is it correct I see 2 docker images of TooGoodTogo? I checked my Portainer:

maxwinterstein/homeassistant-addon-toogoodtogo-ha-mqtt-bridge:1.1.0

f1c878cb/armv7-addon-tgtg-ha-mqtt-bridge:1.1.0

Yeah, I guess this should be okay.

The image f1c878cb... is based on the maxwinterstein... image, but does not really add a lot onto it. They share nearly all layers together.

Are there more ununsed images shown?

e.g.:

It was nothing. I did docker image prune -a to clean everything thats not in use.
Now I have just 1 docker :wink:

I was wondering what the reason is that you build it around MQTT?
Would it not be nicer to update sensors etc. directly without MQTT between add-on and HA?

p.s. with your add-on I bought more nice portions :smiley:

Probably, yes. But as most of the code is recycled from my own little bot, it was the easiest way to do it. Populating sensors via MQTT is a piece of cake.

I guess the cleanest version would be to rebuild it as an integration that can be acquired using HACS and use the Home Assistant API to communicate. But honestly, I am not sure if I want to invest the time.

i looked at Amsterdam, this is crazy! So many shops that work with toogoodtogo! I am a little bit jealous :wink:

Understandable… Its ok. Im more then happy to use your add-on.
Yes there are lot of shops here… Every day its Xmas day haha

Hello guys,

thanks for this component!

Here is my automation, maybe it’s useful for somebody :slight_smile:

alias: notify_tgtg
description: ''
trigger:
  - platform: state
    entity_id: sensor.toogoodtogo_biobackerei_schomaker_biostrot_ii
    from: '0'
  - platform: state
    entity_id: sensor.toogoodtogo_cafe_backerei_berns
    from: '0'
  - platform: state
    entity_id: sensor.toogoodtogo_pro_biomarkt_innenhafen_obst_gemuse
    from: '0'
  - platform: state
    entity_id: sensor.toogoodtogo_pro_biomarkt_innenhafen_uberraschungstute
    from: '0'
  - platform: state
    entity_id: sensor.toogoodtogo_sushi_sohne
    from: '0'
  - platform: state
    entity_id: sensor.toogoodtogo_one_million_fruits
    from: '0'
  - platform: state
    entity_id: sensor.toogoodtogo_blumen_hermes_schnittblumen
    from: '0'
  - platform: state
    entity_id: sensor.toogoodtogo_blumen_hermes_zimmerpflanzen
    from: '0'
condition: []
action:
  - service: notify.alexa_media
    data:
      data:
        method: all
        type: announce
      target:
        - media_player.Kuche
      message: |
        {% set entityID = trigger.to_state.entity_id %}
        {% set items = states(entityID) | int %}
        {% set names = state_attr(entityID,'friendly_name').split('-') %} 
        {% set namesLength = names | length %}

        {% if namesLength > 2 %}
          {% set outName = names[1] + '-' + names[2].replace("&","und") %}
        {% else %}
          {% set outName = names[1].replace("&","und") %}
        {% endif %}

        {% if items > 1 %}
          Es gibt {{ items }} neue Tüten bei ToGoodToGo von {{ outName }} zum Preis von 
          {{ state_attr(entityID,'price') }}€.
          {% else %}
            Es gibt {{ items }} neue Tüte bei ToGoodToGo von {{ outName }} zum Preis von 
            {{ state_attr(entityID,'price') }}€.
        {% endif %}
  - service: notify.mobile_app_ac2003
    data:
      title: ToGoodToGo Ware verfügbar!
      message: >
        {% set entityID = trigger.to_state.entity_id %} {% set names =
        state_attr(entityID,'friendly_name').split('-') %}  {% set namesLength =
        names | length %}

        {% if namesLength > 2 %}
          {% set outName = names[1] + '-' + names[2] %}
        {% else %}
          {% set outName = names[1] %}
        {% endif %}

        Von {{ outName }}, Stückzahl {{ states(entityID) }}, Preis {{
        state_attr(entityID,'price') }}€
  - service: notify.mobile_app_redmi_note_8
    data:
      title: ToGoodToGo Ware verfügbar!
      message: >
        {% set entityID = trigger.to_state.entity_id %} {% set names =
        state_attr(entityID,'friendly_name').split('-') %}  {% set namesLength =
        names | length %}

        {% if namesLength > 2 %}
          {% set outName = names[1] + '-' + names[2] %}
        {% else %}
          {% set outName = names[1] %}
        {% endif %}

        Von {{ outName }}, Stückzahl {{ states(entityID) }}, Preis {{
        state_attr(entityID,'price') }}€
mode: single
3 Likes

Thx for sharing :slight_smile:

Nice code. Will try your notify part… See what it do :slight_smile:

Great Work Max, thanks for this nice addon

thx :slight_smile:

I am just fighting with myself if I want to make it more popular and provide some notification blueprint or keep it flying under the radar just like it is currently.

The chances that somebody steals the good sushi portions from my favorite shop would increase maybe too much :wink:

1 Like

I’ve been using this for a while and it seems to have stopped working. I can see the start and end of the loop but nothing happens for me during the check() function. I’ve got a handful of stores set as a favourite.

Is there something I can check to figure out why I’m not seeing any store updates?

Many thanks,

Andy

Hi Andy,

I just pushed a new version. Please have a try.

Just the every_n_minutes to 1 and show me the log ouput. Maybe there is something usefull.

1 Like

Thanks Max,

Here’s the output from the log for a few minutes after restarting the add on using version1.4.0.

Many thanks,

Andy

[s6-init] making user provided files available at /var/run/s6/etc…exited 0.
[s6-init] ensuring user provided files have correct perms…exited 0.
[fix-attrs.d] applying ownership & permissions fixes…
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts…
[cont-init.d] 00-banner.sh: executing…

Add-on: TooGoodToGo Home Assistant MQTT Bridge
Publish TooGoodToGo stock as MQTT messages

Add-on version: 1.4.0
You are running the latest version of this add-on.
System: Ubuntu 20.04.2 LTS (amd64 / qemux86-64)
Home Assistant Core: 2021.3.1
Home Assistant Supervisor: 2021.03.4

Please, share the above information when looking for help
or support in, e.g., GitHub, forums or the Discord chat.

[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing…
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[14:18:11] INFO: Copy setings file
[14:18:11] INFO: Strating Bridge
2021-03-07 14:18:16 f1c878cb-tgtg-ha-mqtt-bridge main[309] INFO Connecting mqtt
2021-03-07 14:18:16 f1c878cb-tgtg-ha-mqtt-bridge main[309] INFO Starting loop
2021-03-07 14:18:16 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run started
2021-03-07 14:18:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run finished
2021-03-07 14:19:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run started
2021-03-07 14:19:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run finished
2021-03-07 14:20:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run started
2021-03-07 14:20:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run finished
2021-03-07 14:21:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run started
2021-03-07 14:21:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run finished
2021-03-07 14:22:17 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run started
2021-03-07 14:22:18 f1c878cb-tgtg-ha-mqtt-bridge main[309] DEBUG Loop run finished