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

Using a variable in a raw section #55

Open
rjgrandy opened this issue Nov 11, 2023 · 1 comment
Open

Using a variable in a raw section #55

rjgrandy opened this issue Nov 11, 2023 · 1 comment

Comments

@rjgrandy
Copy link

I want to populate a template card (mushroom template) using lovelace_gen. So I need to escape the parts that I want jinja to pass through with {% raw %}, however I want to use a variable from lovelace_gen (in the below case {{entity}}. Is below an acceptable syntax? I doesn't seem to like it.

{% raw %}
icon: >-
  {% if is_state({% endraw %}{{entity}}{% raw %},'on') %}
    mdi:lightbulb-on
  {% raw %}{% elif is_state({% endraw %}{{entity}}{% raw %},'off') %}
    mdi:lightbulb-off
  {% else %}
    mdi:lightbulb-alert
  {% endif%}
{% endraw %}
@steefzz
Copy link

steefzz commented Nov 14, 2023

Hi there,

Not sure if this is what you mean but i think i'm kinda doing the same

This is my room_card.yaml function

# lovelace_gen
type: custom:mushroom-template-card
entity: {{ room_state_group }}
primary: {{ room|capitalize }}
secondary: |-
  {%raw%}
  {% if is_state('{%endraw%}{{ room_state_group }}{%raw%}', 'on') %}
    Aan
  {% else -%}
    Uit
  {%- endif -%}
  {%endraw%}
icon: {{ icon }}
icon_color: |-
  {%raw%}
  {% if is_state('{%endraw%}{{ room_state_group }}{%raw%}', 'on') %}
    yellow
  {%- endif -%}
  {%endraw%}
tap_action:
  action: navigate
  navigation_path: {{ room }}
layout: horizontal
hold_action:
  action: toggle
double_tap_action:
  action: none
fill_container: true

In my view i'm using this to "call the function":

  - type: horizontal-stack
    cards:
      - !include 
        - ../../functions/room_card.yaml
        - room: achtertuin
          room_state_group: light.achtertuin_light_group
          icon: mdi:palm-tree
      - !include 
        - ../../functions/room_card.yaml
        - room: schuur
          room_state_group: light.schuur_licht
          icon: mdi:barn

Which is resulting in (the bottom two buttons):
image

For the entity i'm using a different name than "Entity". Don't know or it might be an issue but in my case I often use groups to show the state.

Hope this helps you?

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