Open fergalish opened 1 year ago
I had a similar issue and gave up. I don't think decluttering-card can handle templates either being passed as variables or being used in the template itself.
Templates may be passed as variables:
decl_test_input_name_2:
card:
type: entities
title: '[[title]]'
entities:
- type: custom:template-entity-row
state: '[[roomname]]'
name: roomname_variable
- type: custom:template-entity-row
state: '[[room_light_state]]'
name: light state
input_select:
test_area:
options:
- kitchen
- bathroom
- balcony
type: vertical-stack
cards:
- type: entities
entities:
- input_select.test_area
- type: custom:decluttering-card
template: decl_test_input_name_2
variables:
- roomname: >-
{{ states('input_select.test_area') }}
- room_light_state: >-
{% set ROOM = states('input_select.test_area') -%}
{{ states('light.' + ROOM + '_ceiling') }}
- title: some_title_2
- type: entities
entities:
- light.kitchen_ceiling
- light.bathroom_ceiling
- light.balcony_ceiling
But templates cannot be used "inside templates"...
you can do it, but it's javascript, not jinja. So:
variables:
- roomname: >-
{{ states('input_select.test_area') }}
becomes:
variables:
- roomname: "[[[ return states['input_select.test_area'].state ]]]"
...I popped in onto a single line, but you can still do it on multiple lines:
variables:
- roomname: >-
[[[ return states['input_select.test_area'].state ]]]
you can do it, but it's javascript, not jinja. So:
The original question was "how to pass a template as a variable" - and a possible solution was provided here.
BTW, I was not quite right when said
templates cannot be used "inside templates"...
because it IS possible with using a custom ct_eval()
function.
Check here, part "jinjia template which is used INSIDE another jinjia template".
it's javascript, not jinja
The original question was about using template-entity-row
which dies NOT accept JS.
My attempts to pass templates as variables using jinja have failed in the past and someone on this forum showed me that javascript works.
Edit: Ugh, it’s 10 mins, 1 cup-of-coffee and some checking of my yaml later. I now remember why I am using javascript and not jinja; all my decluttering templates use custom:button-card
which only accepts javascript templates.
…sorry for the bum info.
Hi, I have decluttering templates working quite well, including nested ones. However, I've run into a block. I have several rooms, each with a
binary_sensor.[[roomname]]_window
entity. I pass the roomname as text when I call the template entity, and it all works great. However, I'd also like to have a separate page where the[[roomname]]
is set byinput_select.room_selector
with the various room names listed. So I have this:And the cards:
I've tried all sorts of variations, using
custom:template-entity-row
or directly using- entity: 'binary_sensor.[[roomname]]_window'
and so on. I've tried using the'{{states("input_select.room_selector")}}'
function instead ofstates.input_select.room_selector.state
and so on.Nothing is working for me. Some fail with "Unknown" in the UI, others don't render the card with various types of error. Happy to supply those errors if anyone thinks it might help.
Has anyone every seen this before and have an idea on how to fix please?