PiotrMachowski / Home-Assistant-Lovelace-HTML-Jinja2-Template-card

This card displays provided Jinja2 template as an HTML content of a card. It uses exactly the same engine as Home Assistant in Developer tools.
MIT License
68 stars 10 forks source link

Card loading error: No card type found #12

Closed Boogaard53 closed 2 years ago

Boogaard53 commented 2 years ago

Overview - Home  (1)

PiotrMachowski commented 2 years ago

This is a config for whole view. Here you have one than can be used in card editor:

type: custom:html-template-card
title: 'HTML Template card'
ignore_line_breaks: true
content: |
  Sun state: <b>{{ states('sun.sun') }}</b>, elevation: {{ state_attr('sun.sun','elevation') }}</br>
  <b>Hello</b> there!<p>General <u>Kenobi!</u></p>
  <img src="https://i.redd.it/ltxppihy4cyy.jpg" width="70%"/></br>
  <ha-icon icon="mdi:speaker"></ha-icon> Volume: {{ states('input_number.system_volume') }}%</br>
  <center><img src="https://vignette.wikia.nocookie.net/starwars/images/f/fa/Modal_Nodes_02.jpg" width="{{ states('input_number.system_volume') }}%"/></center>
Boogaard53 commented 2 years ago

Ahh yes sorry my bad, this one does work. However it doesn't work with some other code. This code to be exact: (from this repo: https://github.com/ben8p/home-assistant-bunq-balance-sensors)


type: 'custom:html-template-card'
title: Transactions
ignore_line_breaks: true
content: >
  <style>.bunq_table { width:100% } .bunq_table tr:nth-child(even) {background:
  var(--material-secondary-background-color)}</style> <table class="bunq_table">
  <tr> <th >Amount</th> <th>Description</th> <th>Time</th> </tr> {% for
  transaction in state_attr('sensor.bunq_groceries', 'transactions') %}

  <tr>

  <td style="width: 20%;text-align:right">

  {{ transaction.amount }}&nbsp;{{ transaction.currency }}

  </td>

  <td style="padding:0 0.5em">

  {{ transaction.description }}

  </td>

  <td style="width: 20%;">

  {% set created = as_timestamp(now()) - (strptime(transaction.created,
  '%Y-%m-%d %H:%M:%S.%f') + now().utcoffset()).timestamp() %}

  {% set days = (created // (60 * 60 * 24)) | int %}

  {% set weeks = (days // 7) | int %}

  {% set hours = (created // (60 * 60)) | int %}

  {% set hours =  hours - days * 24 %}

  {% set minutes = (created // 60) | int %}

  {% set minutes = minutes - (days * 24 * 60) - (hours * 60) %}

  {% set days = (days | int) - (weeks * 7) %}

  {% macro phrase(value, name) %}

  {%- set value = value | int %}

  {{- '{}{}'.format(value, name) if value | int > 0 else '' }}

  {%- endmacro %}

  {% set text = [ phrase(weeks, 'w'), phrase(days, 'd'), phrase(hours, 'h'),
  phrase(minutes, 'm') ] | select('!=','') | list | join(', ') %}

  {% set last_comma = text.rfind(',') %}

  {% set text = text[:last_comma] + text[last_comma + 1:] %} {{text}} </td>

  </tr>

  {% endfor %}

  </table>
PiotrMachowski commented 2 years ago

"doesn't work" can mean a lot, can you specify a little bit more?

Boogaard53 commented 2 years ago

Yes sorry i forgot to add a photo. i cant get an screenshot right now but bassicly the card does show up in my dashboard (so it doesnt give a red error box) but it has no content so it is blank

PiotrMachowski commented 2 years ago

It means that your template is invalid (probably invalid entity id: sensor.bunq_groceries). You can paste this config in dev tools and it should work

Boogaard53 commented 2 years ago

That sensor doesnt even exist in my HA. I know for sure you didn't mean this but I'm not sure that you do mean: Screenshot (4)

Boogaard53 commented 2 years ago

Or do i need this maybe:

home-assistant-b

PiotrMachowski commented 2 years ago

Or do i need this maybe:

No, you don't need this.

Template is not rendered, because it is invalid: it refers to entity that doesn't exist.

You can check if used template is correct by pasting it in dev tools.

You can contact the creator of the integration/template to help you

Boogaard53 commented 2 years ago

Okay I'll contact the creator, thank you for your help, cheers