Skip to content

Commit

Permalink
Add example dashboard card
Browse files Browse the repository at this point in the history
  • Loading branch information
tjorim committed Sep 14, 2023
1 parent 0ab4980 commit fd78d0c
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions README.md
@@ -1,6 +1,6 @@
# TooGoodToGo items stock as a sensor in Home Assistant
# Too Good To Go items stock as a sensor in Home Assistant

This aim to show the stock of one or multiple [TooGoodToGo](https://toogoodtogo.com/) item using the [tgtg-python](https://github.com/ahivert/tgtg-python) library.
This aim to show the stock of one or multiple [Too Good To Go](https://toogoodtogo.com/) item using the [tgtg-python](https://github.com/ahivert/tgtg-python) library.\
Sensor data can be used afterward to generate notifications, history graphs, ... share your best examples in the [Discussion tab](https://github.com/Chouffy/home_assistant_tgtg/discussions)!

## Features
Expand All @@ -10,9 +10,10 @@ Sensor data can be used afterward to generate notifications, history graphs, ...
- Retrieve all favorites instead of a manual list of item_id if no `item:` are defined
- Retrieve additional information as attributes, if available:
- Item ID
- TooGoodToGo price and original value
- Price and original value
- Pick-up start and end
- Sold-out date
- Dashboard card example

## Installation

Expand All @@ -23,11 +24,10 @@ Two steps are required:

### 1. Get access tokens

First you'll need to get access tokens for this integration to work.

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.

#### 1a. Manually
#### 1a. Python

1. Install required packages.
- [Python >=3.8](https://www.python.org/downloads/)
Expand Down Expand Up @@ -92,9 +92,41 @@ Check the [tgtg_get_favorites_item_id](./tgtg_get_favorites_item_id.py) script!
1. Run it
1. Copy the full output in the `configuration.yaml` for the `item` section

## Dashboard card example

Here is an example for a card on your Home Assistant dashboard created by @wallieboy and updated by @Sarnog in https://github.com/Chouffy/home_assistant_tgtg/issues/73.\
Make sure you install the custom `auto-enties` and `multiple-entity-row` cards as well.

```yaml
type: custom:auto-entities
card:
type: entities
title: TGTG Surprise Bags
filter:
template: |-
{% for state in states.sensor -%}
{%- if state.state|float(default=0) >= 1 and 'sensor.tgtg_' in state.entity_id %}
{%- if state_attr(state.entity_id, 'pickup_start') is not none -%}
{{
{
'entity': state.entity_id,
'name': state.attributes.friendly_name[5:],
'type': "custom:multiple-entity-row",
'unit': false,
'secondary_info': 'Pickup on ' + state.attributes.pickup_start[8:10] + "-" + state.attributes.pickup_start[5:7] + ' between '+ state.attributes.pickup_start[11:16] + ' and ' + state.attributes.pickup_end[11:16] + ', € '+ state.attributes.item_price[:-3],
'tap_action': {
'action': 'url',
'url_path': state.attributes.item_url}
}
}},
{%- endif -%}
{%- endif -%}
{%- endfor %}
```

## Q&A

- It was working before, but now all TooGoodToGo sensors are "not available"
- It was working before, but now all Too Good To Go sensors are "not available"
- Try to update your tokens using [the script](https://github.com/Chouffy/home_assistant_tgtg/blob/main/tgtg_get_tokens.py) and restart Home Assistant
- I have a sensor that shows now as unavailable when there's no stock
- Try add it manually using Item ID - See [this issue](https://github.com/Chouffy/home_assistant_tgtg/issues/18)
Expand Down

0 comments on commit fd78d0c

Please sign in to comment.