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

ct_eval(): whitespaces cause an error #2

Closed
ildar170975 opened this issue Feb 20, 2023 · 4 comments
Closed

ct_eval(): whitespaces cause an error #2

ildar170975 opened this issue Feb 20, 2023 · 4 comments

Comments

@ildar170975
Copy link

Consider this example:

{% set TEMPLATE = "
  {% if true -%}
    {{states('zone.home')}}
  {%- else -%}
    {{states('sun.sun')}}
  {%- endif %}
" %}
currently is {{ct_eval(TEMPLATE)}}

which works fine:

image

image

Now let's try to use it with a custom:declutering-card:

  decl_test_var_template_into_template:
    default:
      - VALUE: '{{states(''sun.sun'')}}'
    card:
      type: markdown
      content: |-
        {% set STATE = ct_eval("[[VALUE]]") -%}
        Current state is {{STATE}}
        Zone state is {{states('zone.home')}}
  - type: custom:decluttering-card
    template: decl_test_var_template_into_template
    variables:
      - VALUE: '{{states(''person.ildar'')}}'
  - type: custom:decluttering-card
    template: decl_test_var_template_into_template
    variables:
      - VALUE: >-
          {% if true -%}
          {{states('zone.home')}}
          {%- else -%}
          {{states('sun.sun')}}
          {%- endif %}
  - type: custom:decluttering-card
    template: decl_test_var_template_into_template
    variables:
      - VALUE: "{% if true -%}
            {{states('zone.home')}}
          {%- else -%}
            {{states('sun.sun')}}
          {%- endif %}"
  - type: custom:decluttering-card
    template: decl_test_var_template_into_template
    variables:
      - VALUE: >-
          {% if true -%}
            {{states('zone.home')}}
          {%- else -%}
            {{states('sun.sun')}}
          {%- endif %}

where the last call gives an error:

image

i.e. this is accepted:

      - VALUE: >-
          {% if true -%}
          {{states('zone.home')}}
          {%- else -%}
          {{states('sun.sun')}}
          {%- endif %}

and this is NOT (although it works in Dev tools -> Template):

      - VALUE: >-
          {% if true -%}
            {{states('zone.home')}}
          {%- else -%}
            {{states('sun.sun')}}
          {%- endif %}

Could it be an issue for this integration or to the decluttering-card ?

@PiotrMachowski
Copy link
Owner

I would assume the problem is not in this integration (because it works in dev tools), but it needs to be more deeply investigated

@ildar170975
Copy link
Author

ildar170975 commented Feb 20, 2023

Seems to be in issue with decluttering-card.
Consider this template:

  decl_test_var_template:
    default:
      - VALUE: xxx
    card:
      type: markdown
      content: '[[VALUE]]'

and a card:

type: vertical-stack
cards:
  - type: custom:decluttering-card
    template: decl_test_var_template
    variables:
      - VALUE: '{{ states(''sun.sun'') }}'
  - type: custom:decluttering-card
    template: decl_test_var_template
    variables:
      - VALUE: >-
          {{ states('sun.sun') }}
  - type: custom:decluttering-card
    template: decl_test_var_template
    variables:
      - VALUE: >-
          {% if false -%}
          {{states('zone.home')}}
          {%- else -%}
          {{states('sun.sun')}}
          {%- endif %}
  - type: custom:decluttering-card
    template: decl_test_var_template
    variables:
      - VALUE: >-
          {% if false -%}
            {{states('zone.home')}}
          {%- else -%}
            {{states('sun.sun')}}
          {%- endif %}

image

Here again indented template does NOT work.

So, imho I found a reason.
Unfortunately, there is a small probability this will be fixed - the repo seems to be abandoned.
Created an issue anyway w/o any hope - custom-cards/decluttering-card#60.

Please feel free to close this issue.

@PiotrMachowski
Copy link
Owner

Great, thank you for your investigation!

Personally I use lovelace_gen, maybe it will be better for you as well 🙂

@ildar170975
Copy link
Author

Found a workaround:
instead of:

      - VALUE: >-
          {% if false -%}
            {{states('zone.home')}}
          {%- else -%}
            {{states('sun.sun')}}
          {%- endif %}

use this:

          - VALUE: "
              {% if false -%}
                {{states('zone.home')}}
              {%- else -%}
                {{states('sun.sun')}}
              {%- endif %}
              "

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

2 participants