Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Some example lovelace cards #2

Closed
seb5594 opened this issue Nov 10, 2022 · 6 comments
Closed

[Feature Request]: Some example lovelace cards #2

seb5594 opened this issue Nov 10, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@seb5594
Copy link

seb5594 commented Nov 10, 2022

The request

Nice HA integration here!
Could you give out more examples like a markdown card where all "Knaller" sales will be listed or something similar? Would be a good addition

Is your feature request related to a problem?

No response

Additional information

No response

@seb5594 seb5594 added the enhancement New feature or request label Nov 10, 2022
@seb5594 seb5594 changed the title [Feature Request]: Some example cards [Feature Request]: Some example lovelace cards Nov 10, 2022
@FaserF
Copy link
Owner

FaserF commented Nov 11, 2022

Thanks for your feature request and your interest in the integration. I will have a look into it.

@Maxi531
Copy link

Maxi531 commented Nov 15, 2022

I would second his request. If there is a way to create a lovelace template, so we don't have to do it on our own every single time, that would be great!

@KrizzeOne
Copy link

This is how my markdown card looks like:

# **Süßes und Salziges**
|            |        |       |
| :------------: |:------------- | -----:|
 {%- set product_list_loop =  state_attr('sensor.rewe_440421', 'discounts') -%}

{%- for product in product_list_loop -%} {% if 'Süßes & Salziges' in product.category and product.product != '' %}
| <img src="{{product.picture_link[0] }}" width="50" height="50"/> | {{product.product }} 
| ![badge](https://badgen.net/badge/{{ product.price.price }}€/{{ product.price.regularPrice }}/red)  
|  {%- endif -%} 
{%- endfor -%}

Bildschirmfoto 2022-12-20 um 21 07 39

Downside:

  • It takes up to 4sec to load the content if you choose multiple product categories
  • Price tags are build via https://badgen.net and most of the time you have to reload your lovelace page to get all badges
  • Product images aren't square all the time. Sometimes they look a bit distorted
  • By using table layout as I do, Lovelace cards looks different if you have short/long product names. This drives me crazy and I hope I will have a more robust solution in the future.

@FaserF
Copy link
Owner

FaserF commented Jan 9, 2023

Done with #5

@FaserF FaserF closed this as completed Jan 9, 2023
@derliebemarcus
Copy link

derliebemarcus commented Apr 5, 2023

Hi there, since my market has 389 offers, I had to reduce that number to something I could handle. Therefore, I came up with this mushroom template card. Since it's text-only, it loads pretty fast. Hope it helps:

type: custom:mushroom-template-card
primary: Aktuelle Angebote im Rewe Prospekt
icon: ''
multiline_secondary: true
secondary: |+
  {# This selects the sensor containing the Rewe market ID. 
     Note: Check the very last line of this card configuration. 
           The link shown there should refer to your respective market in order to make sense. 
           In case you're wondering: on double tap because it's more user-friendly.  #}
  {%- set product_list_loop = state_attr('sensor.rewe_4040274', 'discounts') -%}

  {# This defines a list of things we don't want to see in our result list. #}
  {%- set unwanted_products = (
  'Homann',
  'Kühlmann',
  'Nadler',
  ) -%}

  {# This defines the list of offers we want to see. #}
  {%- set wanted_products = (
  'Sekt','Crémant','Brut','Champagner'
  'Äpfel','äpfel'
  'Bacon',
  'Beere','beere',
  'Bio',
  'Birne','birne',
  'Butter',
  'Emmis',
  'Forelle',
  'Gurke',
  'Hummus','hummus',
  'Joghurt',
  'Lachs',
  'Kartoffeln','kartoffeln',
  'Lamm',
  'Öl','öl',
  'Parma',
  'Rind',
  'Salat','salat',
  'Schnitzel'
  'Skyr',
  'Spargel',
  'Traube','traube',
  ) -%}

  {# Here, we define all variables we are going to use later on. #}
  {%- set ns = namespace() -%}
  {%- set ns.found_wanted=false -%}
  {%- set ns.product_list={0:0} -%}
  {%- set ns.product_list_current={0:0} -%}

  {# Now, let the magic happen. For each of the products available as discount items do: #}
  {%- for product in product_list_loop -%}
    {%- if product.price  %} {# This filters out entries without pricing details. #}
      {%- set ns.found_wanted=false  -%}
      {# If the product is on our positive list, we set a marker to have it added.  #}
      {%- for wanted_product in wanted_products %}
        {%- if product.product|contains(wanted_product) -%}
          {%- set ns.found_wanted=true  %}
        {%- endif -%}
      {%- endfor -%}
      {# Except when it also contains a string from things we don't want to see. 
         Then we have to remove that marker.
         (e.g.: we want to see Salat but not Homanns Fleischsalat as it is gross.) #}
      {%- for unwanted_product in unwanted_products %}
        {%- if product.product|contains(unwanted_product) -%}
          {%- set ns.found_wanted=false  %}
        {%- endif -%}
      {%- endfor -%}
      {# This is when we finally figured out whether we want to have 
         the current product on our result list or not. #}
      {%- if ns.found_wanted == true %}
        {# This is to add the first item to the empty list. #}
        {%- if ns.product_list_current == ns.product_list-%}
          {%- set ns.product_list = {product.product: product.price.price} -%}
        {%- else -%}
          {# This is for everything else. Looks a bit weird as 
          Home Assistant does not seem to suppport the comfy way. #}
          {%- set ns.product_list_current = {product.product: product.price.price} -%}
          {%- set ns.product_list = dict(ns.product_list.items(), **ns.product_list_current) -%}
        {%- endif -%}
        {%- set ns.found_wanted=false  -%}
      {%- endif -%}
    {%- endif -%}
  {%- endfor -%}

  {# Finally, we print out the whole thing in alphabetic order. #}
  {% for key,value in ns.product_list|dictsort %}
  {{ key }}: {{ value }} €
  {%- endfor -%}

fill_container: true
tap_action:
  action: none
hold_action:
  action: more-info
double_tap_action:
  action: url
  url_path: >-
    https://www.rewe.de/angebote/berlin-neukoelln/4040274/rewe-markt-rollbergstr-59/?market-flyer=active

For completion, here's a screenshot:
Bildschirm­foto 2023-04-05 um 22 58 02

@Maxklos
Copy link
Contributor

Maxklos commented Mar 27, 2024

the cool card from @KrizzeOne doens't work anymore. We only get the current "price", not the old "regularPrice" . here is an updated card:

# **Obst und Gemüse**
|            |        |       |
| :------------: |:------------- | -----:|
 {%- set product_list_loop =  state_attr('sensor.rewe_4040708', 'discounts') -%}

{%- for product in product_list_loop -%} {% if 'obst-und-gemuese' in product.category and product.product != '' %}
| <img src="{{product.picture_link[0] }}" width="50" height="50"/> | {{product.product }}
| ![badge](https://badgen.net/badge/{{ product.price | urlencode }}/€)
|  {%- endif -%}
{%- endfor -%}

For updating the readme file, I opend a pull request: #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants