This aim to show the stock of one or multiple Too Good To Go item using the tgtg-python library.\ Sensor data can be used afterward to generate notifications, history graphs, ... share your best examples in the Discussion tab!
item:
are definedTwo steps are required:
First you'll need to get access tokens for this integration to work.\ This is to be executed outside of Home Assistant, i.e. on your local machine.
pip install tgtg>=0.11.0
or pip install --upgrade tgtg
if you already have it.This is work in progress.
You only need Docker installed. There is no need to clone the repo because Docker can build from an external URL.
docker build https://github.com/Chouffy/home_assistant_tgtg.git#main --tag "homeassistant_tgtg_tokens:latest"
docker run --rm -it homeassistant_tgtg_tokens
/config/configuration.yaml
retrieved in 1.sensor:
- platform: tgtg
# Optional: email so you know which account is used
email: "Your TGTG mail"
# Mandatory: tokens for authentication - see the tgtg_get_tokens.py script
access_token: "abc123"
refresh_token: "abc123"
user_id: "123456"
cookie: "datadome=..."
# Optional: Refresh the stock every 15 minutes
scan_interval: 900
# Optional, use defined items ID instead to get your favorites
item:
# item_id 1
- 1234
# item_id 2
- 5678
# Optional: user agent - by default, the latest one is retrieved from the Google Play store
#user_agent: "TGTG/22.2.1 Dalvik/2.1.0 (Linux; U; Android 9; SM-G955F Build/PPR1.180610.011)"
access_token
, refresh_token
, user_id
and cookie
can be retrieved using the tgtg_get_tokens script!
Check the tgtg_get_favorites_item_id script!
configuration.yaml
for the item
sectionHere is an example for a card on your Home Assistant dashboard created by @wallieboy, updated by @Sarnog in https://github.com/Chouffy/home_assistant_tgtg/issues/73 and @tjorim. \
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 'sensor.tgtg_' in state.entity_id %}
{% set entity_id = state.entity_id %}
{% set state = states(entity_id) %}
{%- if is_number(state) and state | int > 0 %}
{% set pickup_start = state_attr(entity_id, 'pickup_start') %}
{%- if pickup_start is not none -%}
{{
{
'entity': entity_id,
'name': state_attr(entity_id, 'friendly_name')[5:],
'type': "custom:multiple-entity-row",
'unit': false,
'secondary_info': as_timestamp(pickup_start) | timestamp_custom('Pickup on %d-%m between %H:%M and ', true) + as_timestamp(state_attr(entity_id, 'pickup_end')) | timestamp_custom('%H:%M, € ', true) + state_attr(entity_id, 'item_price')[:-3],
'tap_action': {
'action': 'url',
'url_path': state_attr(entity_id, 'item_url')
}
}
}},
{%- endif -%}
{%- endif -%}
{%- endfor %}
tgtg
integration won't start, all my sensors are unavailable and I have a list of manually defined items ID