dooz127
(Duy Nguyen)
January 9, 2020, 10:04pm
6
I want to give a shout-out to Thomas for this excellent custom integration. There are a number of systems which break up a single system into multiple entities (e.g., ring, zwave, etc.). It’s very painful to present the desired information for such systems in hass. You can do it via templates but this has the drawback of having to restart hass if you have to make changes. Another alternative was to use multiple custom integrations, which has the drawback of being very difficult to read and understand. For example, I have a Family card that displays the location of my family members, and proximity from home as secondary information:
To generate this card, my previous yaml was:
cards:
- card:
entities:
- entity: person.john_smith
secondary_info: >-
{% if states('person.john_smith') != 'home' and
states('sensor.john_smith_proximity') != 'unknown' %}
{{ states('sensor.john_smith_proximity') }} minutes from home
{% else %}
{% endif %}
type: 'custom:secondaryinfo-entity-row'
- entity: person.jane_smith
secondary_info: >-
{% if states('person.jane_smith') != 'home' and
states('sensor.jane_smith_proximity') != 'unknown' %}
{{ states('sensor.jane_smith_proximity') }} minutes from home
{% else %}
{% endif %}
type: 'custom:secondaryinfo-entity-row'
- entity: person.jenny_smith
- entity: person.joe_smith
show_header_toggle: false
title: Family
type: 'custom:hui-entities-card'
entities:
- device_tracker.john_smith_iphone
- sensor.john_smith_proximity
- device_tracker.jane_smith_iphone
- sensor.jane_smith_proximity
- device_tracker.jenny_smith_ipad
- device_tracker.joe_smith_ipad
type: 'custom:config-template-card'
variables:
- 'states[''device_tracker.john_smith_iphone''].state'
- 'states[''sensor.john_smith_proximity''].state'
- 'states[''device_tracker.jane_smith_iphone''].state'
- 'states[''sensor.jane_smith_proximity''].state'
This was a nightmare to debug. Now, with template-entity-row, my yaml is:
entities:
- entity: person.john_smith
secondary: >-
{% if states('person.john_smith') != 'home' and
states('sensor.john_smith_proximity') != 'unknown' %}
{{ states('sensor.john_smith_proximity') }} minutes from home
{% else %}
{% endif %}
type: 'custom:template-entity-row'
- entity: person.jane_smith
secondary: >-
{% if states('person.jane_smith') != 'home' and
states('sensor.jane_smith_proximity') != 'unknown' %}
{{ states('sensor.jane_smith_proximity') }} minutes from home
{% else %}
{% endif %}
type: 'custom:template-entity-row'
- entity: person.jenny_smith
- entity: person.joe_smith
show_header_toggle: false
title: Family
type: entities
2 Likes
basnijholt
(Bas Nijholt)
January 12, 2020, 3:44pm
7
This is really great!
I have used it for displaying the following
Where it tells me how long a utility has been on (or off) and how much money has been spend on it today (whenever it’s more than €0.01, otherwise it’s hidden).
If anyone cares, I share my config here .
2 Likes
sti0
(Sti0)
January 12, 2020, 8:13pm
8
Great card, thank you. Exactly what I need. How can I use this.entity
from a auto-entities-card to display an attribute as state value?
I tried it like this:
- type: custom:auto-entities
card:
type: entities
title: Last seen
filter:
include:
- attributes:
last_seen: ">0"
options:
type: custom:template-entity-row
state: "{{states['this.entity'].attributes.last_seen }}"
sti0
(Sti0)
January 12, 2020, 8:18pm
10
I even tried
"{{state_attr('this.entity','last_seen') }}"
but this displays only None
thomasloven
(Thomas Lovén)
January 12, 2020, 8:23pm
11
auto-entities sets the entity:
property of each row.
Templates lets you access the rows configuration in the config
variable.
Try "{{state_attr(config.entity, 'last_seen')}}
1 Like
sti0
(Sti0)
January 12, 2020, 8:25pm
12
thomasloven:
config
That works. Thank you very much!
dooz127
(Duy Nguyen)
January 12, 2020, 9:58pm
13
I may be misconfiguring something but the underscore function _(<key>)
doesn’t seem to be working for me:
entities:
- entity: binary_sensor.master_bedroom_occupancy
- entity: binary_sensor.master_bedroom_occupancy
type: 'custom:template-entity-row'
- entity: binary_sensor.master_bedroom_occupancy
state: '{{ _(state.binary_sensor.default.off) }}'
type: 'custom:template-entity-row'
title: Template-entity-row-test
show_header_toggle: false
type: entities
thomasloven
(Thomas Lovén)
January 13, 2020, 6:52am
14
The result of the template must be _(state.binary_sensor.default.off)
.
The template {{ _(state.binary_sensor.default.off) }}
will evaluate to an error because _
is undefined.
{{ '_(state.binary_sensor.default.off)' }}
will work, though.
1 Like
dooz127
(Duy Nguyen)
January 13, 2020, 10:29pm
15
I am still having some confusion about how to take advantage of the localization feature in template-entity-row. The below configuration works:
entities:
- entity: binary_sensor.master_bedroom_occupancy
state: |-
{% if is_state('binary_sensor.master_bedroom_occupancy','on') %}
{{ '_(state.binary_sensor.occupancy.on)' }}
{% else %}
{{ '_(state.binary_sensor.occupancy.off)' }}
{% endif %}
type: 'custom:template-entity-row'
type: entities
But is there a more efficient way of doing this, something like, e.g.:
state: {{ '_(eval('state.binary_sensor.occupancy.'+states('binary_sensor.master_bedroom_occupancy'))) }}
thomasloven
(Thomas Lovén)
January 13, 2020, 10:46pm
16
state: "_(state.binary_sensor.occupancy.{{states('binary_sensor.master_bedroom_occupancy')}})"
Make sure you understand why before you copy it.
1 Like
HI,
this is new to me, where is the underscore function described or mentioned? (or is it simply the concatenation Underscore between single words used in regular code everywhere)
secondly, is this binary_sensor.default a true binary_sensor in your config, or is ‘default’ also some reserved name in the template? What do you want the template to show in the card?
dooz127
(Duy Nguyen)
January 14, 2020, 7:31am
18
Thomas added it as a new feature in the latest release of template-entity-row to support localized strings:
My understanding is shaky, but I believe the underscore function _(<key>)
is a JavaScript
function that maps a key to localized string:
javascript
a yes, I had missed the completely, thanks for pointing it out on https://github.com/thomasloven/lovelace-template-entity-row#options
Have always been thinking the system takes care of localization anyway, so don’t really understand when this would be necessary?
@thomasloven there’s a small but important typo there:
document.querySelector("home-assistant").hass.resouces
should be:
document.querySelector("home-assistant").hass.resources
thomasloven
(Thomas Lovén)
January 14, 2020, 6:42pm
20
It’s not a javascript function in this case. It’s an identifier which I search for in the processed template and replace.
The name _
is commonly used for localization in several programming languges, though. That’s why I chose it.
trying to display all GitHub sensors with their respective versions and last_changed on secondary, I can’t find the correct syntax to realize that. Could someone please help me find the template (or maybe direct config setting, tried last_changed obviously, or secondary_info: last-changed
but didn’t work) I need?
- type: custom:auto-entities
card:
type: entities
title: Github repos
show_header_toggle: false
filter:
include:
- entity_id: sensor.github*
options:
type: custom:template-entity-row
state: >
{% if state_attr(config.entity,'latest_release_url') %}
{{ state_attr(config.entity,'latest_release_url').split('tag/')[1]}}
{% else %} Not set
{% endif %}
secondary: "{{ config.entity.last_changed}}"
sort:
method: name
gives me:
secondly, Id like to be able to click the entities and reveal more-info. Can’t we tap these template-entity-row 's at all? No handle appears, and clicking does nothing…
thanks for having a look
thomasloven
(Thomas Lovén)
February 4, 2020, 10:29pm
23
last_changed
and last_updated
are a bit odd ones…
{{ states[config.entity].last_changed }}
1 Like
better!
bit of formatting makes it more readable:
secondary: "{{ as_timestamp(states[config.entity].last_changed)| timestamp_custom('%X - %D') }}"
Thomas, how can we reveal the more-info on these entities?
HI Thomas,
Since updating to 105.1/2 the above card using your auto-entities and template-entity-row is in a state of turmoil… it shows like this now:
every few seconds flickers to its ‘supposed to be state’ like posted above for a split second and then back to the full templates again…
Could it be either of these cards is having issues with HA 105?
this is the config for the cards:
- type: custom:auto-entities
card:
type: entities
title: Github repos
show_header_toggle: false
filter:
include:
- entity_id: sensor.github*
options:
type: custom:template-entity-row
state: >
{% if state_attr(config.entity,'latest_release_url') %}
{{ state_attr(config.entity,'latest_release_url').split('tag/')[1]}}
{% else %} Not set
{% endif %}
secondary: >
{{ state_attr(config.entity,'latest_commit_message')}}
which has been showing just fine up to now like posted here
h4nc
February 12, 2020, 9:44pm
26
This is great, thanks. It would be even better if it behaves like a normal card. So when I click it, it would be nice when it opens the entity. Is this possible too?
Something like tap_action in the glance card.
1 Like