Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help to pass input_select helper to decluttering template #54

Open
fergalish opened this issue Oct 20, 2022 · 5 comments
Open

Help to pass input_select helper to decluttering template #54

fergalish opened this issue Oct 20, 2022 · 5 comments

Comments

@fergalish
Copy link

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 by input_select.room_selector with the various room names listed.
So I have this:

decluttering_templates:
  test_decluttering_template:
    card:
      type: entities
      title: '[[title]]'
      entities:
        - type: custom:template-entity-row
          state: '[[roomname]]'
          name: roomname_variable
        - type: custom:template-entity-row
          state: '{{ states("binary_sensor.[[roomname]]_window") }}'
          name: Window state

And the cards:

    cards:
      - type: custom:decluttering-card
        template: test_decluttering_template
        variables:
          - title: Passing the value of the input_select
          - roomname: '{{ states.input_select.room_selector.state }}'
      - type: custom:decluttering-card
        template: test_decluttering_template
        variables:
          - title: passing_direct_string (\"kitchen\")
          - roomname: kitchen


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 of states.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?

@ghost
Copy link

ghost commented Dec 10, 2022

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.

@ildar170975
Copy link

ildar170975 commented Jan 11, 2023

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

image

But templates cannot be used "inside templates"...

@RedNo7
Copy link

RedNo7 commented Sep 26, 2023

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 ]]]

@ildar170975
Copy link

ildar170975 commented Sep 29, 2023

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.

@RedNo7
Copy link

RedNo7 commented Sep 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants