🔹 Lovelace_gen - Add abilities to ui_lovelace.yaml

I managed to figure out a working solution for converting the OrderedDict back into YAML Lovelace configuration. I kept bumping into some sort of quirk where it wouldn’t allow me to apply the tojson filter directly to the OrderedDict object. But…it allowed me to apply the list filter to retrieve the keys in the OrderedDict…and for some reason it also allowed me to to apply tojson to their corresponding values.

So this approach works…

{% for key in options|list %}
{{ key }}: {{ options[key]|tojson }}
{% endfor %}

Technically, this doesn’t produce 100% ‘pure’ YAML format…the generated Lovelace config has YAML keys, and the corresponding values are Javascript objects. But that is totally valid from a YAML perspective, and it is generating the hold_action config that I was looking for.

@petro, thank you for your assistance and your sample code - it pushed me in the right direction!

Is there a way to reload the _global variables without a home assistant restart?

1 Like

so I have never used lovelace-gen really, and now am exploring if it can set the view icon. I added

# lovelace_gen

{% set my_icon = 'mdi:alert' %}

title: Presence
path: presence
icon: {{ my_icon }}

to a view, and yes, I did notice it change! however, reloading the page trying to use another icon renders the ‘Unknown Error’. A HA restart too btw, so there must be something wrong.

Schermafbeelding 2022-02-08 om 16.27.16

the reason I am trying to do this, is I want templates to take over control over the tab/view icon, and would love to do

{%- set my_icon = states('sensor.presence_icon') -%}

which all renders the same result, and string with the correct mdi: icon.

but now I can no even manage to get the most basic example in the repo to work, returning the same Unknown Error.

{% set my_lamp = "light.bed_light" %}

type: entities
entities:
 - {{ my_lamp }}

please help me get going?
fyi, I use my views as include, so have now only added # lovelace_gen to this view. Must it be added elsewhere too, maybe the main dashboard file which holds this view?
thanks!

update

Wait, I believe it had to do with the fact I also had commented bits and pieces in that view… deleted that, and now see the icon change upon refresh, and even the light in the example… :wink:

But, what I started out pursuing is still not working. the icon template. Cant this be done?

Inspector:

Update2:

guess this 🔹 Lovelace_gen - Add abilities to ui_lovelace.yaml - #53 by thomasloven means it cant be done. using states is not possible

Does this integration still works?
I would love to use it in my floorplan dashboard

Yes.

Does this card work with the “config-template-card”? I am trying to change the entity source and other parameters of a graph based on the value of an entity using an if statement in lovelace_gen.

The lovelace_gen acts differently if I replace the template with a raw string equivalent of what the template should resolve to.

- type: custom:config-template-card
  entities:
    - input_select.outside_temp_duration
  card:
    !include
      - "../template/outside_temp_graph.yaml"
      - entity: input_select.outside_temp_duration
        name: ${states["input_select.outside_temp_duration"].state}         

In the lovelace_gen file I try to do an if statement on the “name” (see below). It always equates to false using the template above, even if I know that the state of the input_select is 550d. However if I swap the template for a raw string with “550d” the if statement resolves true.

{% if name == '550d' %}

I have a floorplan completely written using lovelace_gen abilities.

The main view file is lovelace_new_data.yaml and is called by the main dashboard file lovelace_new.yaml

The file has become very long and a bit difficult to maintain. I would like to split it up into smaller files according to the sections. I have tried a few ways but couldn’t get it to see all the variables/definitions/macros.

Is there a way I can split it up into smaller files and keep the functionality?

Does it work with the latest 2022.7 HA version?
Anyone tried?

Doesn’t work for me. I get “Unknown error” until I remove it on the latest version.

1 Like

@thomasloven
Any chance of looking at this issue?

Same for me. Anyone found a workaround other than downgrading HA until the permanent fix ?

Hi Petro, do you know anyone who can advise me on installing lovelace_gen ?
I've been trying here for a few days now, but no chance of getting it to work
The problem is {% comma error

Hi all,

A question about this beautiful compoments.
I would like to replicate this piece of code:

{% set my_lights = ["light.bed_light", "light.kitchen_lights", "light.ceiling_lights"] %}
title: My view
cards:
  - type: entities
    entities:
{% for light in my_lights %}
      - {{ light }}
{% endfor %}

but instead of setting up manually the list “my_litghts” i would like to create it dinamycally.
Is it possible to for loop maybe using a group or create a list based on domain like “Light”?

something like this

title: My view
cards:
  - type: entities
    entities:
{% for light in domain.light %}
      - {{ light.entity_id }}
{% endfor %}

(that’s just an example I would like to achive)

Thanks to all

Nik

Is this still true because whenever I add it to an included ‘view’ file I get an error?

# lovelace_gen

title: Logging Settings
path: logging_settings
icon: mdi:notebook-edit

cards:

image

Still true, you most likely have an error below

I have asked this last year and still need a solution? Is there a way to split the lovelace_gen configuration ?

Yes there is, it’s covered in the documentation for lovelace_gen

This whole section is about breaking up:

I saw it but don’t think it is relevant for my configurations.

My UI is a single picture-elements with tens if not hundreds of elements on it. It is a single file (2105 lines and counting) all heavily using lovelace_gen and jinja.

The file is broken up into sections: Variables, Macros and then the elements’ implementation that is split into seperate sections for each of the element types and visual areas of the UI

Is there a simple way of splitting it into files each of these sections? Variable, Macros, Lights, Covers, Settings, Irrigations, etc…?

You can still split that way… It does not need to be a card. Just a collection of fields.

Assuming I took my lovelace_new_data.yaml file and cut it in 2 creating the following:

  • lovelace_new_data_variables.yaml
  • lovelace_new_data_rest.yaml

Each of the files has the # lovelace_gen at the beginning of course.

How should my new main lovelace file lovelace_new.yaml be?

current file is:

# lovelace_gen

kiosk_mode:
  hide_header: true

title: Home

views:
  - !include lovelace_new_data.yaml