Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/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.
https://github.com/PiotrMachowski/Home-Assistant-Lovelace-HTML-Jinja2-Template-card

home-assistant jinja2 lovelace-card template

Last synced: 5 days ago
JSON representation

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.

Awesome Lists containing this project

README

        

# Lovelace HTML Jinja2 Template card

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)
[![Community Forum](https://img.shields.io/badge/community-forum-brightgreen.svg?style=popout)](https://community.home-assistant.io/t/html-jinja2-template-card/134550)
[![Ko-Fi][ko_fi_shield]][ko_fi]
[![buycoffee.to][buycoffee_to_shield]][buycoffee_to]
[![PayPal.Me][paypal_me_shield]][paypal_me]
[![Revolut.Me][revolut_me_shield]][revolut_me]

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*.

## Configuration options

| Key | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `title` | `string` | `false` | - | Title of a card |
| `content` | `string` | `true` | - | Content of a card |
| `ignore_line_breaks` | `boolean` | `false` | `false` | Disables changing line breaks to `` tags |
| `do_not_parse` | `boolean` | `false` | `false` | Disables template parsing |
| `always_update` | `boolean` | `false` | `false` | Enables refreshing the card with every change of entity |
| `picture_elements_mode` | `boolean` | `false` | `false` | Enables picture-elements mode |
| `entities` | `list` | `false` | `[]` | List of additional entities whose updates should trigger refresh of the card |

### Templates

* Entity state, example: `{{ states('sun.sun') }}`
* Entity attribute, example: `{{ state_attr('sun.sun', 'elevation') }]`
* Detailed documentation: [*Templating*](https://www.home-assistant.io/docs/configuration/templating/)

## Example usage

![Example](https://github.com/PiotrMachowski/Home-Assistant-Lovelace-HTML-Jinja2-Template-card/raw/master/example.gif)

```yaml
views:
- name: Example
cards:
- type: custom:html-template-card
title: 'HTML Template card'
ignore_line_breaks: true
content: |
Sun state: {{ states('sun.sun') }}, elevation: {{ state_attr('sun.sun','elevation') }}
Hello there!

General Kenobi!



Volume: {{ states('input_number.system_volume') }}%

```

## Manual Installation
1. Download [*html-template-card.js*](https://github.com/PiotrMachowski/Home-Assistant-Lovelace-HTML-Jinja2-Template-card/raw/master/dist/html-template-card.js) to `/www/custom_lovelace/html_template_card` directory:
```bash
mkdir -p www/custom_lovelace/html_template_card
cd www/custom_lovelace/html_template_card/
wget https://github.com/PiotrMachowski/Home-Assistant-Lovelace-HTML-Jinja2-Template-card/raw/master/dist/html-template-card.js
```
2. Add card to resources in `ui-lovelace.yaml` or in raw editor if you are using frontend UI editor:
```yaml
resources:
- url: /local/custom_lovelace/html_template_card/html-template-card.js
type: js
```

## Hints
* To use mdi icon follow example: ``.
* If content does not contain any template use flag `do_not_parse: true` to increase performance.
* If content does not contain entity id (e.g. because of loop) you have to provide it manually in `entities` to enable refresh of the card when it will be updated.
* If you want to enable refreshing for every change in HA use flag `always_update: true`. **WARNING:** this may cause heavy load of browser/HA. Best to use with flag `do_not_parse: true`.
* To check if your content is correct without changing configuration use *Developer tools*.
* To use this card as an element of picture-elements card use `picture_elements_mode` parameter.

## Support

If you want to support my work with a donation you can use one of the following platforms:


Platform
Payment methods
Link
Comment


Ko-fi

  • PayPal

  • Credit card



  • Buy Me a Coffee at ko-fi.com


  • No fees

  • Single or monthly payment




  • buycoffee.to

  • BLIK

  • Bank transfer



  • Postaw mi kawę na buycoffee.to




    PayPal

  • PayPal



  • PayPal Logo


  • No fees




  • Revolut

  • Revolut

  • Credit Card



  • Revolut


  • No fees


  • [ko_fi_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Ko-Fi&color=F16061&logo=ko-fi&logoColor=white

    [ko_fi]: https://ko-fi.com/piotrmachowski

    [buycoffee_to_shield]: https://shields.io/badge/buycoffee.to-white?style=flat&label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588cfBMgpPMI9nMFe0BkFzVOYrYqycyQgQJLwTC2cDZCPeF8V5Y7jGb8BUpRicy7OU5MAAAAASUVORK5CYII=

    [buycoffee_to]: https://buycoffee.to/piotrmachowski

    [buy_me_a_coffee_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Buy%20me%20a%20coffee&color=6f4e37&logo=buy%20me%20a%20coffee&logoColor=white

    [buy_me_a_coffee]: https://www.buymeacoffee.com/PiotrMachowski

    [paypal_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=PayPal.Me&logo=paypal

    [paypal_me]: https://paypal.me/PiMachowski

    [revolut_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Revolut&logo=revolut

    [revolut_me]: https://revolut.me/314ma