TooGoodToGo items stock as sensor in Home Assistant
Too Good To Go integration for Home Assistant
This aims to show the stock of one or multiple Too Good To Go items using the tgtg-python library. Sensor data can be used afterward to generate notifications, history graphs, ... share your best examples in the Discussion tab!
Features
- Easy setup - No tokens, Docker containers, or Python scripts needed! Just enter your email and enter the PIN from the login email.
- Config Flow - Full UI-based configuration
- Automatic favorites - Retrieves all your favorites from the TGTG app (with pagination for accounts with 20+ favorites)
- Smart polling - More frequent updates (every 3 minutes) during sales windows when items are likely to become available
- API rate limiting - Built-in 1 second delays between API calls to prevent rate limiting issues
- Reauth support - Handles token expiration gracefully
- Diagnostics - Built-in diagnostics support for troubleshooting
- Custom item IDs - Optionally add non-favorite items during setup
- Rich attributes for each sensor:
Installation
Via HACS (Recommended)
- Search for TooGoodToGo in the Integration tab of HACS
- Click Install
- Restart Home Assistant
- Go to Settings โ Devices & Services โ Add Integration
- Search for "TooGoodToGo" and follow the setup wizard
- Enter your TGTG email address and submit
- Check your email for a PIN code from Too Good To Go (open it in a new tab) and enter it in the setup wizard
- Optionally add any non-favorite item IDs
- Done!
Configuration
Configuration is performed entirely in the UI. No YAML configuration is needed.
Adding custom item IDs
During setup, you can optionally add item IDs for stores that aren't in your favorites. To find an item ID:
- Open the Too Good To Go app
- Navigate to the store you want to add
- Share the store link - it will look like:
https://share.toogoodtogo.com/item/123456/ - The number at the end (
123456) is the item ID
How polling works
- Default polling: Every 60 minutes
- Sales window polling: Every 3 minutes when any item is within its sales window
- Rate limited: 1 second delay between API calls to prevent being blocked
- Adaptive: If API rate limits are hit, polling is automatically reduced to once per hour
Note: Each time you add/remove a favorite in the TGTG app, reload the integration for changes to take effect.
Automation example
Here's an example automation that sends a notification when a TGTG item becomes available:
automation:
- alias: "TGTG Item Available"
trigger:
- platform: state
entityid: sensor.tgtgyourstorename
condition:
- condition: template
valuetemplate: "{{ trigger.tostate.state | int > 0 }}"
action:
- service: notify.mobileappyour_phone
data:
title: "TGTG Surprise Bag Available!"
message: >
{{ trigger.tostate.attributes.friendlyname }} has {{ trigger.to_state.state }} bag(s) available!
Pickup: {{ trigger.tostate.attributes.pickupstart | asdatetime | aslocal }}
Price: {{ trigger.tostate.attributes.itemprice }}
data:
url: "{{ trigger.tostate.attributes.itemurl }}"
Note: All attributes use snakecase (underscores), e.g.,pickupstart,itemprice,itemurl.
Dashboard card example
Here is an example for a card on your Home Assistant dashboard created by @wallieboy, updated by @Sarnog in https://github.com/Chouffy/homeassistanttgtg/issues/73 and @tjorim. Support for images was later added by @ov3rk1ll in https://github.com/Chouffy/homeassistanttgtg/pull/139. Make sure you install the custom auto-entities and multiple-entity-row cards as well.
type: custom:auto-entities
card:
type: entities
title: TGTG Surprise Bags
filter:
template: |-
{% for state in states.sensor if state.entityid in integrationentities('tgtg') %}
{% set entityid = state.entityid %}
{% set state = states(entity_id) %}
{%- if is_number(state) and state | int > 0 %}
{% set pickupstart = stateattr(entityid, 'pickupstart') %}
{%- if pickup_start is not none -%}
{{
{
'entity': entity_id,
'name': stateattr(entityid, 'friendly_name')[5:],
'type': "custom:multiple-entity-row",
'unit': false,
'secondaryinfo': astimestamp(pickupstart) | timestampcustom('Pickup on %d-%m between %H:%M and ', true) + astimestamp(stateattr(entityid, 'pickupend')) | timestampcustom('%H:%M, โฌ ', true) + stateattr(entityid, 'itemprice')[:-3],
'image': stateattr(entityid, 'logo_url'),
'tap_action': {
'action': 'url',
'urlpath': stateattr(entityid, 'itemurl')
}
}
}},
{%- endif -%}
{%- endif -%}
{%- endfor %}
Troubleshooting
"Additional verification required" during setup
This happens when TGTG's API detects unusual activity (DataDome captcha). Click submit on the error screen to retry โ it usually succeeds on the next attempt.
Integration stops updating
Your tokens may have expired. Go to Settings โ Devices & Services, find the TGTG integration, and use the "Reconfigure" option to reauthenticate.
Not all favorites showing
If you have more than 20 favorites, make sure you're using version 6.0.0 or later which includes pagination support.
Enable debug logging
Add this to your configuration.yaml and restart Home Assistant:
logger:
default: info
logs:
custom_components.tgtg: debug
Breaking changes in v6.0.0
- Config flow only: YAML configuration is deprecated. Existing YAML configs will be automatically migrated to UI-based configuration on first load. You can then remove the YAML config from your configuration.yaml.