šŸ”¹ template-entity-row - Put templates in an entities row

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

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

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:
Feb-07-2020 10-35-04

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

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

on my post above, this is solved with the latest update of your custom card, so thank you very much.

I do have another question (next to the open request for tap/hold-action ) which has revealed itself just now. As you can see the auto-entities config makes the sensors appear with the templated state and secondary info, but also with their given name, and default GitHub icon, belonging to the GitHub sensor.

I needed to add a single GitHub sensor to the card config, and without explicitly setting a name and icon this shows as:

adding the name and icon as follows:

 - type: custom:auto-entities
    card:
      type: entities
#      title: Github repos
      show_header_toggle: false
      header:
        type: picture
        image: /local/images/github_owler.png
    entities:
      - entity: automation.github_repo_update
        secondary_info: last-triggered
      - type: custom:template-entity-row
        name: >
          {{state_attr('sensor.home_assistant','name')}}
        icon: >
          {{state_attr('sensor.home_assistant','icon')}}
        state: >
          {% if state_attr('sensor.home_assistant','latest_release_url') %}
          {{ state_attr('sensor.home_assistant','latest_release_url').split('tag/')[1]}}
          {% else %} Not set
          {% endif %}
        secondary: >
          {{ state_attr('sensor.home_assistant','latest_commit_message')}}
    filter:
      include:
        - entity_id: sensor.github*
          options:
#            tap_action:
#              action: more-info
            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')}}
          sort:
            method: name

makes it show like the other sensors:

how can this be? does the auto-entities card also automatically add the name and icon?

Iā€™ve just started using this card and itā€™s awesome, thanks @thomasloven!

I need some help from more experienced people with the following card.
It displays my motion sensors with their statuses (Clear/Detected instead of ā€˜offā€™/on), secondary info as a value of another (related to entity) sensor and changing its iconā€™s colour dependig on the entity's state.

This is working the version (secondary code shortened for clarity):

entities:
  - type: custom:template-entity-row
    entity: binary_sensor.pir_ground_floor_hall
    secondary: >
      {% set dt_obj = states.input_datetime.pir_ground_floor_hall %}
    state: >
      {{ 'Clear' if is_state('binary_sensor.pir_ground_floor_hall', 'off') else 'Detected' }}
    active: "{{ is_state('binary_sensor.pir_ground_floor_hall', 'on') }}"

  - type: custom:template-entity-row
    entity: binary_sensor.pir_ground_floor_reception
    secondary: >
      {% set dt_obj = states.input_datetime.pir_ground_floor_reception %}
    state: >
      {{ 'Clear' if is_state('binary_sensor.pir_ground_floor_reception', 'off') else 'Detected' }}
    active: "{{ is_state('binary_sensor.pir_ground_floor_reception', 'on') }}"
    
show_header_toggle: false
state_color: true
title: Motion detectors
type: entities

As you can see, there is little difference so I wanted to avoid repeating entities. After looking at this and this advice I tried to change my card to:

entities:
  - type: custom:template-entity-row
    entity: binary_sensor.pir_ground_floor_hall
    secondary: >
      {% set dt_obj = states.input_datetime.pir_ground_floor_hall %}
    state: >
      {{ 'Clear' if is_state(config.entity, 'off') else 'Detected' }}
    active: "{{ is_state(config.entity, 'on') }}"

  - type: custom:template-entity-row
    entity: binary_sensor.pir_ground_floor_reception
    secondary: >
      {% set dt_obj = states.input_datetime.pir_ground_floor_reception %}
    state: >
      {{ 'Clear' if is_state(config.entity, 'off') else 'Detected' }}
    active: "{{ is_state(config.entity, 'on') }}"

Entities do change icons when motion detected but states do not change (always Clear) and colour is always blue.
Do I miss anything here or it wonā€™t work in my case? (I kind of understand how HA detects what entitiesā€™ changes to listen to when rendering templates but people reported success with their config.entity templatesā€¦)

It also does not look like I can use any YAML anchors here, does it?

p.s as far as I understand from reading this topic, this card does not support tap_action so if I need such functionality I need to look elsewhere?

Does the color change if you refresh the page while the sensor is on?

yes, both state and active work if I refresh the page.
thatā€™s why I doubted this {{ is_state(config.entity, 'on') }} would ever work properly as itā€™s a template and HA wonā€™t catch whatā€™s inside config.entity so there will be no re-evaluation and therefore no change (until something else causes re-evaluation)

:+1:

By the way, when I move some logic from backend to LL (as I used to have some template sensors just to make them read-only like this one) does it shift processing from backend to a browser?
Iā€™m asking because it seems like my sensors react a bit slower now and Iā€™m trying to figure out whyā€¦

Ok.
Iā€™ll have a fix up later today.

Temporary workaround: add

entity_ids:
  - binary_sensor.pir_...
1 Like

Hi Thomas,

would you add the tap/hold action functionality also? Would be really very nice indeed.

Thatā€™s very kind of you, thanks!
Just a thought:
I only need to re-define state because (I think) standard LL entity row looks at my binary_sensorā€™s device_class and internally does that off ā†’ Clear/on ā†’ Detected substitution so I donā€™t see those off/on if I use standard entity row. Maybe your code could do the same?
That way there will be less template processing and generally room for error :wink:

On a similar note, I have activeā€¦ but itā€™s much trickier considering the recent state of things with dropping colour changes in standard cards.

I just wanted to update my report based on some observation.
Your workaround let me see immediate changes in state but as my secondary info displays time elapsed from the last on state in needs to be updated regularly.
So I ended up having this and it works better as being updated both upon state change and then every minute

entity_ids:
      - binary_sensor.pir_ground_floor_lounge
      - sensor.time

Donā€™t know if there is a better way of doing what I want thoughā€¦

Just wanted to say a big thank you for the fix - I downloaded the latest version and it works for me without entity_ids (even without sensor.time - good stuff).
You donā€™t do releases of it, do you? :wink:

@thomasloven I have an issue similar to the previous one when using condition as I want to hide my input_number when an automation is disabled - my card is updated only if I refresh the page.
Hereā€™s the simple config

type: entities
show_header_toggle: false
title: Ventilation
entities:
  - entity: automation.ventilation_1st_floor_bathroom_extractor_fan_turn_on_by_humdity_threshold

  - type: custom:template-entity-row
    entity: input_number.ventilation_1st_floor_bathroom_shower_humidity_threshold
    condition: >
      {{ is_state('automation.ventilation_1st_floor_bathroom_extractor_fan_turn_on_by_humdity_threshold', 'on') }}

The workaround works, too :wink:

But there is another problem - that input_number (mode: slider, but mode: box makes no difference) behaves like a sensor so I can see no box around it and cannot change its value.
Could you look into it please?

@thomasloven

I recently learned that it is considered normal for template-entity-row to momentarily display its raw templates during a page-refresh (this may be true of other custom cards as well; I donā€™t know because I donā€™t use any others).
Template-Entity-Row momentarily displays its templates

My point of reference is Custom UI and its templates are never displayed in the UI. Can you explain to a novice like me how Custom UI and template-entity-row differ in their approach?

FWIW, Iā€™m trying to replace Custom UI with purely Lovelace cards and techniques. My requirement is fairly simple: I want to change the icon (and its color) of an entities card based on the entityā€™s state. Iā€™m using style: to set the iconā€™s color and template-entity-row to set the icon. It produces the same appearance as Custom UI but has the additional undesirable feature of showing its templates during rendering.

For the benefit of other readers, this issue was resolved here.

1 Like

I chose to display the original template as a fallback. That means that if the template fails to evaluate for any reason, you will be able to at least see it and possibly find out what went wrong.

That also means that on initial load, you will see the template until the backend can evaluate it and send the result back to the frontend.

Thank you for the explanation.

If I understood you correctly, you are saying the template is displayed by design. In other words, it is entirely feasible to not momentarily display the template but it was decided to display it.

I ask that you reconsider this design choice (or provide an option to enable/disable the display of templates). Hereā€™s why:

  1. From the standpoint of aesthetics, itā€™s unattractive. I canā€™t recall seeing any web page that, when refreshed, momentarily reveals portions of its raw code prior to rendering it.
  2. If the template has an error, I doubt seeing it flash on the screen for a half-second allows anyone to analyze it.