Is there any way to use Jinja2 templates in Lovelace? I would like to be able to do filtering with either the entity-filter or conditional card based on comparing the states of two different entities and, although I can create template sensors to do this, it would be great if I could use the Jinja2 directly in Lovelace but it doesn’t seem to work.
4 Likes
letherwin
(Marco Crocellà)
April 15, 2019, 6:04pm
2
just to revive this topic, because it is my question too…
nickma
(Nick)
April 27, 2019, 6:52pm
3
Hi,
I’m just starting with this too, but here’s what I found so far:
Lovelace Templates
I’ve gone and made a crazy card that allows you to pretty much template anything in Lovelace for your card configurations using any information available on the frontend; states, attributes, user, etc.
Want state/attribute-based icons? DONE!
Want dynamic stacks; vertical vs horizontal based on user? DONE!
Want OR conditionals? DONE!
The list is pretty much endless and I’m sure you all will come up with some crazy stuff. Be sure to share.
Go nuts! Enjoy!
that links to the installation instructions:
And here’s an example
vars[1] < -0.5 ? 'rgb(248, 147, 29)' :
vars[1] < 0 ? 'rgb(255, 194, 15)' :
vars[1] = 0 ? 'rgb(20, 142, 153)' :
vars[1] < 0.5 ? 'rgb(202, 219, 43)' :
vars[1] < 1.0 ? 'rgb(142, 198, 65)' :
vars[1] < 1.5 ? 'rgb(106, 158, 47)' :
vars[1] < 2 ? 'rgb(37, 145, 60)' : 'rgb(0, 111, 58)'}"
card:
type: "custom:secondaryinfo-entity-row"
entity: sensor.dow_futures
secondary_info: "${'Change: ' + states['sensor.dow_futures_change'].state + ' (' + vars[1] + '%)'}"
icon: "${vars[1] > 0 ? 'mdi:arrow-up-bold-circle' : 'mdi:arrow-down-bold-circle' }"
- type: custom:card-modder
entity: sensor.s_p_futures
style:
--paper-item-icon-color: "${
vars[2] < -2.5 ? 'rgb(151, 26, 30)' :
vars[2] < -2.0 ? 'rgb(194, 39, 45)' :
vars[2] < -1.5 ? 'rgb(236, 27, 33)' :
vars[2] < -1.0 ? 'rgb(244, 101, 35)' :
vars[2] < -0.5 ? 'rgb(248, 147, 29)' :
1 Like
3_14
(Piotr Machowski)
August 30, 2019, 12:05am
4
You can check out my latest card:
poudenes
(Poudenes)
February 26, 2021, 1:41pm
5
it is not possible to use if then else llalala… with your card?
petro
(Petro)
February 27, 2021, 11:56am
6
Everything in that custom card can be done in the markdown card. Markdown card can use all jinja logic. I would assume that custom card do it as well.
1 Like