From fd78d0c0e4bec3fbbbf8bfa449ed9b623bc3899c Mon Sep 17 00:00:00 2001 From: Jorim Tielemans Date: Thu, 14 Sep 2023 21:51:04 +0200 Subject: [PATCH] Add example dashboard card https://github.com/Chouffy/home_assistant_tgtg/issues/73 --- README.md | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7c9ced4..080d562 100644 --- a/README.md +++ b/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 @@ -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 @@ -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/) @@ -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)