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' ) }})
Any jinjia template resulting a SINGLE-LINE string may be used in the card.
Ofc the template must be correct. But this is not a question related to this card.
As well as common yaml rules like a correct indentation.
did you try it? if yes, what was the result?
yes, itâs working
So you answered your own question
after the tipp from lldar, format was the problem, thanks to him
I am trying to template the hold_action confirmation text before calling a service to toggle the running state of an ESXi VM. Unfortunately, the result I am presented with is:
Do you really want to turn {{ state_attr(config.entity, 'friendly_name') }} {% if is_state(config.entity, 'off') %}on{% else %}off{% endif %}?
- type: custom:template-entity-row
entity: sensor.esxi_vm_toolbox_licenses_virtual_appliance_1_3_2
name: "{{ state_attr(config.entity, 'vm_name') }}"
icon: mdi:server
style: |
:host {
color:
{% if states(config.entity) == "off" %} default;
{% elif state_attr(config.entity, 'tools_status') == "toolsOk" %} green;
{% else %} red;
{% endif %}
}
hold_action:
action: call-service
confirmation:
text: "Do you really want to turn {{ state_attr(config.entity, 'friendly_name') }} {% if is_state(config.entity, 'off') %}on{% else %}off{% endif %}?"
service: script.toggle_vm
service_data:
sensor_entity: "{{ config.entity }}"
Unrelated to your question (which is rather unclear):
check card-mod lines & read release notes to card-mod 3.4.0.
Then let et me rephrase my question. I wish to present a templated action confirmation string before calling the service to toggle a vm state. I was using the example (more or less) that is shown at the end of the README.md for this custom Lovelace element on Github.
When I use it as shown above, it returns the literal:
" Do you really want to turn {{ state_attr(config.entity, âfriendly_nameâ) }} {% if is_state(config.entity, âoffâ) %}on{% else %}off{% endif %}? ", rather than evaluating the template.
I do not think using templates like this is supported:
- type: custom:template-entity-row
entity: sun.sun
hold_action:
action: '{{"more-info"}}'
According to the Docs, we need to use this:
hold_action: |
{
"action": "toggle",
"confirmation": {
"text": "Do you really want to turn {{ state_attr(config.entity,
'friendly_name') }} {% if is_state(config.entity, 'off') %}on{% else
%}off{% endif %}?",
},
}
i.e. kind of (untested):
hold_action: |
{
"action": "service-call",
"confirmation": {
"text": "Do you really want to turn {{ state_attr(config.entity,
'friendly_name') }} {% if is_state(config.entity, 'off') %}on{% else
%}off{% endif %}?",
},
"service": "script.toggle_vm",
"service_data": {
"sensor_entity": "{{ config.entity }}"
}
}
Thanks, @Ildar_Gabdullin ! That helped! Here is my working snippet:
- type: custom:template-entity-row
entity: sensor.esxi_vm_toolbox_licenses_virtual_appliance_1_3_2
name: "{{ state_attr(config.entity, 'vm_name') }}"
icon: mdi:server
card_mod:
style: |
:host {
color:
{% if states(config.entity) == "off" %} default;
{% elif state_attr(config.entity, 'tools_status') == "toolsOk" %} green;
{% else %} red;
{% endif %}
}
hold_action: |
{
"action": "call-service",
"confirmation": {
"text": "Do you really want to turn {{ state_attr(config.entity,
'vm_name') }} {% if is_state(config.entity, 'off') %}on{% else
%}off{% endif %}?",
},
"service": "script.toggle_vm",
"service_data": {
"sensor_entity": "{{ config.entity }}",
}
}