Hello everyone,
I am currently trying to change my frontend a littlebit. As I am now working a lot with custom cards where it is not possible to use the ui editor I am trying to switch to the yaml mode.
decluttering_templates: !include ui/test_decluttering.yaml
views: !include ui/test_views.yaml
For some smaller cards it is working. But I have at least one configurations which is crashing the whole ui.
This is the code I am using in my views:
automation_template:
card:
type: custom:mushroom-template-card
entity: "[[entity]]"
primary: "[[primary]]"
secondary: |-
{% if is_state(entity, 'on') %}
An
{% elif is_state(entity, 'off') %}
Aus
{% else %}
Nicht verfügbar
{% endif %}
I am using it this way in my views.yaml:
- type: custom:decluttering-card
template: automation_template
variables:
- entity: automation.licht_abstellraum_aus
- primary: Licht Abstellraum
But this forces my whole Dashboard to crash. In the log I can see the following output:
File "/config/ui/test_decluttering.yaml", line 336, in top-level template code
{% if is_state(entity, 'on') %}
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/jinja2/utils.py", line 83, in from_obj
if hasattr(obj, "jinja_pass_arg"):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I also have a problem without decluttering card. In my views I get the following error:
File "/config/ui/main_views.yaml", line 94, in top-level template code
{% set time = now().hour %} {% if (time >= 18) %}
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/jinja2/utils.py", line 83, in from_obj
if hasattr(obj, "jinja_pass_arg"):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'now' is undefined
Why is this failing and how can I fix this?