Error rendering data template: TemplateError

Hi everyone, I’m creating a blueprint. I’m contacting you because I can’t write this code properly. I always get the following error:

Errore: Error rendering data template: TemplateError: Invalid domain name ‘{{ !input trigger_state_entity }}’

{{ (as_timestamp(now()) - as_timestamp(states["{{ !input trigger_state_entity }}"].last_changed | default(0)) | int ) | timestamp_custom("%H:%M:%S", false) }}
variables:
  trigger_state_entity: !input trigger_state_entity

How could I do that?
Thanks

There are multiple issues…

  1. Don’t nest templates, just use the variable directly.
  2. Don’t use !input inside templates. Define a variable and use that variable.
{{ (as_timestamp(now()) - as_timestamp(states[trigger_state_entity].last_changed | default(0)) | int ) | timestamp_custom("%H:%M:%S", false) }}
2 Likes

Thank you so much, it works.

1 Like

Hi,
I’m having the same problem again. I’ve tried several things, but I can’t find a solution. How can I fix it?

variables:
  holiday_calendar_entity: !input holiday_calendar_entity
{% if is_state('[holiday_calendar_entity]'), 'off') %}
{% else %}
{{ state_attr('[holiday_calendar_entity]'), 'message') }}
{% endif %}

I wrote it this way too, but no result comes out

{% if is_state[holiday_calendar_entity], 'off' %}
{% else %}
{{ state_attr[holiday_calendar_entity], 'message' }}
{% endif %}

it only works this way

{% if is_state('calendar.example', 'off') %}
{% else %}
{{ state_attr('calendar.example','message') }}
{% endif %}

It’s is_state() and state_attr() so you use parentheses like this:

{% if is_state(holiday_calendar_entity, 'off') %}
{% else %}
{{ state_attr(holiday_calendar_entity, 'message') }}
{% endif %}

holiday_calendar_entity is a variable’s name, representing an entity_id, so it is entered as-is (without wrapping it in square brackets and/or quotes, like you did in your examples).

1 Like

Thank you so much, it works.