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

Markdown card for on the dashboard #73

Closed
3 tasks done
Sarnog opened this issue Mar 10, 2023 · 10 comments
Closed
3 tasks done

Markdown card for on the dashboard #73

Sarnog opened this issue Mar 10, 2023 · 10 comments

Comments

@Sarnog
Copy link

Sarnog commented Mar 10, 2023

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

Hello,

Is there any way to create a markdown card or something like that, that fills automaticly with all the tgtg sensors, and displays only the sensors, that are active. Ofcourse i would love to see this with the attributes showen as well.

Example:

(only showen when 'available (status > 0, and not sold-out)', otherwise hidden):

'Happy Snacks (attr friendly_name)'
'10 (attr status)' pcs 'magic snack boxes (attr item_url)'
From: '€20,- (attr original_value)', for: '€5,- (attr item_price)'
Pickup from: '20:00 (attr pickup_start)' - '23:00 (attr pickup_end)'

Describe the solution you'd like

Maybe anybody can do something with auto-entities mod and/or markdown card?
I tried, but can't figure it out. I'm lacking skills for this.

Describe alternatives you've considered

Not have it showen on my dashboard... :-/

Additional context

(only showen when 'available (status > 0, and not sold-out )', otherwise hidden):

'Happy Snacks (attr friendly_name)'
'10 (attr status)' pcs 'magic snack boxes (attr item_url)'
From: '€20,- (attr original_value)', for: '€5,- (attr item_price)'
Pickup from: '20:00 (attr pickup_start)' - '23:00 (attr pickup_end)'
@wallieboy
Copy link

I use two custom cards to see which TGTG boxes are available, the auto-enties card and the multiple-entity row.

type: custom:auto-entities
card:
  type: entities
  title: Beschikbaar
filter:
  template: |-
    {% for state in states.sensor -%}
      {%- if state.state>= '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': 'Ophalen op ' + state.attributes.pickup_start[8:10] + "-" + state.attributes.pickup_start[5:7] + ' tussen '+ state.attributes.pickup_start[11:16] + ' en ' + state.attributes.pickup_end[11:16] + ', € '+  state.attributes.item_price[:-3],
            'tap_action': { 
              'action': 'url',
              'url_path':  state.attributes.item_url}
            }

        }},  
      {%- endif -%}
      {%- endif -%}
    {%- endfor %}

@Sarnog
Copy link
Author

Sarnog commented Mar 20, 2023

Thanks for the card!
Altho they remain empty, even when i receive a notification when there is something available. What i'm i doing wrong?

@wallieboy
Copy link

I don't know... indentation is very important with this card. I had some trouble with it.
If you copy and paste the code in the template editor, does that work?
By the way, there is an error with the pickup time in the card, it's an hour to early in the card

@Sarnog
Copy link
Author

Sarnog commented Mar 20, 2023

I don't know... indentation is very important with this card. I had some trouble with it.
If you copy and paste the code in the template editor, does that work?
By the way, there is an error with the pickup time in the card, it's an hour to early in the card

On the template editor i get this error:

TypeError: '>=' not supported between instances of 'float' and 'str'

@wallieboy
Copy link

That's strange. I copied the code above in my template editor, no problem. Did you copy all the code?
And if you delete the part with >=?

@Sarnog
Copy link
Author

Sarnog commented Mar 20, 2023

That's strange. I copied the code above in my template editor, no problem. Did you copy all the code?
And if you delete the part with >=?

This is what i put in the editor:


{% for state in states.sensor -%}
  {%- if state.state>= '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': 'Ophalen op ' + state.attributes.pickup_start[8:10] + "-" + state.attributes.pickup_start[5:7] + ' tussen '+ state.attributes.pickup_start[11:16] + ' en ' + state.attributes.pickup_end[11:16] + ', € '+  state.attributes.item_price[:-3],
        'tap_action': { 
          'action': 'url',
          'url_path':  state.attributes.item_url}
        }

    }},  
  {%- endif -%}
  {%- endif -%}
{%- endfor %}

@Sarnog
Copy link
Author

Sarnog commented Mar 21, 2023

Ssems like this code is working:

type: custom:auto-entities
card:
  type: entities
  title: Beschikbare boxen TGTG
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': 'Ophalen op ' + state.attributes.pickup_start[8:10] + "-" + state.attributes.pickup_start[5:7] + ' tussen '+ state.attributes.pickup_start[11:16] + ' en ' + state.attributes.pickup_end[11:16] + ', € '+  state.attributes.item_price[:-3],
            'tap_action': { 
              'action': 'url',
              'url_path':  state.attributes.item_url}
            }

        }},  
      {%- endif -%}
      {%- endif -%}
    {%- endfor %}

tjorim added a commit that referenced this issue Sep 14, 2023
@tjorim
Copy link
Collaborator

tjorim commented Sep 14, 2023

Thanks, added it to the readme.
image

@tjorim tjorim closed this as completed Sep 14, 2023
@Dinth
Copy link

Dinth commented Sep 17, 2023

This is amazing. I never used auto_entities, but would it be possible to add a filter of entities for pickup today or pickup tomorrow?

@Joepie007v2
Copy link

I use two custom cards to see which TGTG boxes are available, the auto-enties card and the multiple-entity row.

type: custom:auto-entities
card:
  type: entities
  title: Beschikbaar
filter:
  template: |-
    {% for state in states.sensor -%}
      {%- if state.state>= '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': 'Ophalen op ' + state.attributes.pickup_start[8:10] + "-" + state.attributes.pickup_start[5:7] + ' tussen '+ state.attributes.pickup_start[11:16] + ' en ' + state.attributes.pickup_end[11:16] + ', € '+  state.attributes.item_price[:-3],
            'tap_action': { 
              'action': 'url',
              'url_path':  state.attributes.item_url}
            }

        }},  
      {%- endif -%}
      {%- endif -%}
    {%- endfor %}

Thanks. Works great. I’m just wondering how to adjust the time. The attribute shows e.g. pickup_start 15:10, but it is actually 17:10. So 2 hours difference. I live in the Netherlands.
Can I adjust it in your card example or do I have to do this in another way. Hope you can share how you are handling the time zone.

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

No branches or pull requests

5 participants