thomasloven / hass-lovelace_gen

🔹 Improve the lovelace yaml parser for Home Assistant
MIT License
209 stars 22 forks source link

Help with defining variables in Lovelace Gen #9

Closed soloam closed 4 years ago

soloam commented 4 years ago

Hello @thomasloven I'm sitting up a tab in my lovelace, that should work as a simple way to my kids to play movies on the TV. I'm using the button-card custum card to make the layout, and now using Lovelace Gen to display one card for movie. This is working to some point:

# lovelace_gen
title: Filmes
icon: mdi:filmstrip
panel: true
path: movies_{{ library }}
cards:
 # - !include ../cards/header.yaml
  - type: vertical-stack
    cards:
    - type: custom:layout-card
      layout: horizontal
      min_columns: 2
      cards:
      {% for i in range(1, 100, 1) %}
        - type: custom:button-card
          template: recent_movie
          entity: sensor.kodi_movies
          variables:
            index: {{i}}
            library: {{ library }}
      {% endfor %}

The problem is that I have set "100" to display the cards, but I would like this value to be dynamic, I have a sensor with the json values that I use in button-card to get the images and descriptions of the movie, that sensor is a JSON Array with several objects.

The question is, can I replace that hard coded 100 with the array length of the JSON attribute of that sensor?

Thank You

soloam commented 4 years ago

Ok I found a post by you

https://community.home-assistant.io/t/lovelace-gen-add-abilities-to-ui-lovelace-yaml/130328/21?u=soloam

lovelace_gen does not know anything about the state of your entities. It’s meant to be run and generate the static lovelace config once and then never again until you manually change something.

So its not possible?

thomasloven commented 4 years ago

Correct. Perhaps you can use https://github.com/thomasloven/lovelace-state-switch to reach your goal in a different way?