đŸ”č template-entity-row - Put templates in an entities row

I think the result file must be js.
You are supposed to compile your changed project into one js file.

Hi all

how is it possible to show last-updated as secondary: in a template-entity-row card ?

I’ve tried like this, but it doesn’t work

type: custom:template-entity-row
icon: mdi:car
name: "Waze route is {{state_attr('sensor.work','route')}}"
state: "{{states('sensor.work')}} min"
secondary: "{{ relative_time( states[config.entity].last_updated) }}"

Any suggestion?

Thanks

Hi all,
I’m just trying to populate image: with an attribute value, but it fails:

type: entities
entities:
  - type: custom:template-entity-row
    entity: sensor.billigste_stasjon
    image: {{ state_attr('sensor.billigste_stasjon', 'pictureurl') }}

title: Drivstoffpriser

If I type the pictureurl manually, it works just fine:

image

I have tried all possible combinations of single and double quotes without any luck.
Is it possible to customize the card image using template-entity-row at all??

Try your template in Dev tools → Template first. Your template is wrong.

Thanks @Ildar_Gabdullin for your reply.
It was just a typo. I’ve tried so many things - I got somewhat carried away.
I’ve corrected the typo now, but it still doesn’t work. However, in Dev tools Template, it works ok:

Try this:

image: “{{ ... }}”

instead

image: {{ ... }}
1 Like

Indeed - that works. Thank you so much :+1:

1 Like

I am trying to use the ‘active’ option to have the icon color change. But the icon color never changes. Even if I add “active: true” or “active: false”, makes no difference in icon color. Any ideas?

  - entity: number.pool_flow_sensor
    type: custom:template-entity-row
    state: |
      {% if states.number.pool_flow_sensor.state == '1' %}
        On
      {% elif states.number.pool_flow_sensor.state == '0' %}
        Off
      {% endif %}    
    active: "{{ is_state('number.pool_flow_sensor', '1') }}"
    name: Flow Sensor
    icon: mdi:waves-arrow-right

you have 2 quotes at the end of the active: line- should only be 1.

Thanks, 35e, for looking it over. That was just a typo of mine when copying it here.

But I did find the issue! I had to remove the “entity: number.pool_flow_sensor” line. Having the number entity listed caused the icon color not to change. Once I deleted that line, it is working fine!

  - type: custom:template-entity-row
    state: |
      {% if states.number.pool_flow_sensor.state == '1' %}
        On
      {% elif states.number.pool_flow_sensor.state == '0' %}
        Off
      {% endif %}    
    active: '{{ states.number.pool_flow_sensor.state == ''1'' }}'
    name: Flow Sensor
    icon: mdi:waves-arrow-right

EDIT: after more testing, I have found that number entities are all impacted by this issue. Sensor entities work just fine. The downside of not being able to include the entity definition is that history cannot be access by clicking on the icon.

@thomasloven, is this by design? Is there a way that number entities can be allowed?

Have you done it? I have a similar problem.

No, I haven’t found a solution yet

                  secondary: >
                    {% if states[config.entity] is not none %}
                    {{relative_time(states[config.entity].last_changed)}} ago
                    {% else %} Not yet detected
                    {% endif %}

last_updated works the same, should work.
If not, check your logs

When using this card without a “state”, the value displayed does not carry the display unit or observe the specified precision. See image attached.

Is there a way to format how the value is displayed? An option is to template the value to access the sensor state and format it inside the template, but it would require a lot of copy/paste to each row of the card, so I think I’m missing a trick.

This is why the card is called “TEMPLATE-entity-row”.
You need to define a template for a state - which may include unit and desired accuracy.

Got it.
Is there any variable accessible to the template (on the state field) that holds the value of the entity, so to avoid explicitily typing out the name of the entity again on each row ?

Described in docs.
Check about “config.entity”.

In my use case, I am using it to override the name, but would like to inherit the value, so as not to have to reinvent how to format it. (Formatting time-related stuff is a little bit more painful than just adding a ÂșC unit or something like that.)

Any way to access what the ‘default’ display format would have been?

Either do not use “template-entity-row” or perform a proper rounding in a template (+ add a unit).

Also, you may consider another custom card - secondaryinfo-entity-row - which allows to define secondary-info in a template.
Or you may use a standard entity row + card-mod (go to card-mod thread → 1st post → link a the bottom → using “after” & “before”)

is something like this possible with this integration?

type: custom:template-entity-row
icon: mdi:calendar
name: Schulferien
state: >
{% set x = state_attr('sensor.ics_1', 'start') %}
{% set days = state_attr('sensor.ics_1', 'days') %}
{% set day_long_g = ("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag") %}
{% set day_short_g = ("Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa.", "So.") %}
{% set month_g = ("Januar","Februar","MĂ€rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember") %}
{{ day_long_g[x.weekday()]}}, {{ x.day }}.{{ x.month }}.{{x.year}} - {{ days | map(attribute='start') | list | join(', ') }} ({{ state_attr('sensor.ics_1', 'remaining' ) }})