Well done!
nice work, congrats
nice work, awsome cards
do you have any tracker.json url for this card to show in custom updater cards also?
If you have a recent version of custom_updater you shouldn’t need to add a JSON URL to your config, since it uses the “super custom cards” method of tracking. Just add the following to the resources:
resources:
- url: /customcards/github/gadgetchnnel/lovelace-card-templater.js?track=true
type: js
You may need to trigger an update in custom_updater after doing this, but it should then automatically download the files.
I’m considering possible improvements to the card to improve the efficiency (it currently submits a request to the /api/template endpoint for each template when refreshing) and to allow it to automatically identify the entities to monitor (for simple templates) as happens with the template sensors.
However, this would most likely require a custom component which would expose its own API endpoints (to identify entities and process all templates for a card) so I’d like to get feedback on this:
Poll: Would you be happy to require a custom component in order to use the card-templater card?
- Yes
- No
0 voters
If anybody has had any issues accessing this today, it appears that my GitHub profile has been flagged (possibly due to an edit I made to the Wiki on another repository). I’ve contacted GitHub support, so hopefully this will be available again soon.
I’ve now published a new version of this, with an experimental new feature allowing whole lists to be templated. This currently only works with the entities and state_filter properties. You simply need to create a template which returns valid JSON or YAML, like this example which will show all device_tracker entities with a state of “home”:
type: 'custom:card-templater'
card:
type: entities
title: Who's at Home
entities_template: >-
{{ states.device_tracker | selectattr("state", "equalto",
"home") | map(attribute="entity_id") | list | tojson }}
entities:
- sensor.time
I’ve just started implementing releases in the lovelace-card-templater repo so, if you’ve installed this using HACS, you may want to reinstall it selecting the latest version from the available versions. This will make updating easier in future and also allow me to release beta versions.
I’m trying to template the state for an entity in a glance card inside an entity-filter card.
The filter state is ‘on’.
I’m trying to change the displayed state of a binary sensor to the state of a numerical sensor.
I’ve tried this:
- type: 'custom:card-templater'
card:
type: entity-filter
show_empty: false
card:
type: glance
state_filter:
- "on"
entities:
- binary_sensor.ha_update_avail_template
- binary_sensor.potential_breaking_changes
- binary_sensor.nuc_memory_usage_high
- binary_sensor.haapi_mqtt_test
- input_boolean.low_batteries
entities:
- entity: binary_sensor.nuc_memory_usage_high
state_template: "{{ states.sensor.memory_use_percent.state }}%"
It’s almost working…
Right now the problem is that it actually changes the state of the binary sensor in the state machine itself to the state of the other sensor. So then the when the filter checks for the “on” state it doesn’t pick up the binary sensor because now the binary sensor state is no longer ‘on’, it’s ‘70.2%’.
Is that the expected behavior of this card or am I doing something very wrong here?
If this is expected behavior is there another way that you know of that I can change only the way the state is displayed on the frontend without affecting the backend. I looked at secondary info entity row but it doesn’t work for anything other than an entities card.
This is a limitation of how it currently templates the state. It does this by updating the state in the hass.states collection which, although it doesn’t actually change it in the actual state machine (the States page under Developer Tools will still show the actual state), will affect the state seen by the card (and sometimes other cards on the same page).
I’ll see if I can prevent this from happening. I may be able to do this by using a clone of the hass object rather than updating the original (I implemented something similar recently in the Home Feed card for the more-info popup for history entities).
Actually…that’s not correct.
I tried it yesterday and I saw in the dev tools states page that it changed the actual state there.
here it is without the entity being templated (it’s the “binary_sensor.nuc_memory_usage_high” entity):
and here it is after the templated config using the code from above You can see that it’s the same as the memory percent used sensor:
You won’t see the state change in the dev-tools states page until you have the templating code active in lovelace and then you need to restart HA. Then it shows the updated state.
But you can see the result of the template on the actual state because the entity-filter card (which is filtering for the “on” state) isn’t displaying the entity because the actual state is no longer “on”; it’s now “73.9%”.
I’ve done some testing using a copy of the hass object, rather than the original and, unfortunately, I don’t think this will actually be possible. The most I’ve been able to do is make it so templating the state of an entity doesn’t interfere with other cards on the page and doesn’t affect the Developer Tools/States page (and I’ll release a filx for this shortly). However, the issue with cards such as entity-filter is that it isn’t possible for the card-templater card to pass the templated states to the card without it also affecting the filtering (as everything is using the hass object passed to it).
Ok, thanks for trying.
I’ll have to see if I can figure out another way to do it. Or not… It’s not really something necessary. Just something I thought would be nice to have so I can see the actual number on that sensor instead of navigating to another page to see it.
Do you know of another custom component that allows us to template the displayed state of an entity?
I’m not aware of another component that would allow that, but as a workaround you could use name_template, something like this:
- type: 'custom:card-templater'
card:
type: entity-filter
show_empty: false
card:
type: glance
state_filter:
- "on"
entities:
- binary_sensor.ha_update_avail_template
- binary_sensor.potential_breaking_changes
- entity: binary_sensor.nuc_memory_usage_high
name_template: "NUC High Memory Usage - {{ states.sensor.memory_use_percent.state }}%"
- binary_sensor.haapi_mqtt_test
- input_boolean.low_batteries
entities:
- entity: binary_sensor.nuc_memory_usage_high
That would override the display name of the entity to have the percentage memory usage concanenated to the end.
Good idea! Thanks!
It’s not perfect but it works great for what I needed.
I think you’ve posted this in the wrong thread, this is for the card-templater card which allows you to use Jinja2 templates. I think you need to post this here:
Apologies. Yes I did post it in the wrong topic.
Having said that I’m not getting anywhere with debugging it so I might try it with this card instead as I’m slightly less incompetent with jinja.
Would it be possible to use this card to make weblink?
In my example below i want a card with 2 collumns:
First the state of my sensor “sensor.spel_game_01” then the state of “sensor.spel_titel_01” that should be an clickable url from the state of the sensor “sensor.spel_url_01”
- type: 'custom:card-templater'
card:
type: weblink
show_header_toggle: false
columns: 2
title: Spel 01
entities:
- entity: sensor.spel_titel_01
name_template: >-
{{ states.sensor.spel_game_01.state }}
url: >-
{{ states.sensor.spel_url_01.state }}
entities:
- sensor.spel_titel_01
This card only allows the configuration of the card or the states of the entities to be templated. Unless the card you are templating allows the state to be displayed as a link (I’m not sure what card you are trying to use there, since weblink doesn’t actually seem to be a valid card) you won’t be able to use this card to do what you want.
Weblink is part of standard lovelace enities card.