đŸ”č Lovelace_gen - Add abilities to ui_lovelace.yaml

I had an idea to use the rooms as keys in the global config and then using your lovelace_gen I can loop through rooms then using auto entities include any lights from said room.

lovelace_gen:
  rooms:
    - living_room
    - master_bedroom
    - spare_bedroom

Then my lovelace_gen

cards:
  - type: entities
    entities:
      {% for room in _global.rooms %}
      - type: custom:auto-entities
        card:
          type: custom:fold-entity-row
          head:
            type: section
            label: {{ room }}
        filter:
          include:
            - entity_id: "light.{{ room }}*"
      {% endfor %}

My question and problem I am trying to solve is I want to use the room names as headers also but I want to remove the underscore from the name. It does not look like there is a jinja2 filter for regex. Is that something you could add like you did the tojson and fromjson? Or perhaps do you have another suggestion?

Either way thanks for this!

{{ room | replace("_", " ") }}

1 Like

I swear I Googled and came to the conclusion I couldn’t do that but I mostly tried regex examples. Thanks!

For anyone else looking for the built in filter list: https://jinja.palletsprojects.com/en/2.10.x/templates/#list-of-builtin-filters

Very good example. Thank you for that !
I’m trying to deal with the new from_json filter (thank you @thomasloven for it ! ), but I’m facing an issue that I don’t understand. I have the same initial behavior as you: displaying the tojson in my template returns an OrderedDict like string.
But, when I use the fromjson filter (exactly like the example in the lovelace_gen doc) I have an error :

TypeError: the JSON object must be str, bytes or bytearray, not Undefined

Here is an extract of my code.
The calling part :

{% set mydict = {"a": 1, "b": 2} %}
- !include
  - '../templates/_button_configurable.yaml'
  - test: {{ mydict | tojson }}

and the _button_configurable.yaml extract

# lovelace_gen

type: custom:button-card
name: {{ (test|fromjson)['a'] }}

I already checked my lovelace_gen version etc.
The error is raised when lovelace_gen execute the json.loads(value). It seems to beleive that my string is undefined but it is not, because I can display it


Any clue for this ?

Thank you !

[EDIT 5 minutes later ^^]
Found my mistakes. Another call to my test template were done above in my code. Just silly. excuse me for this mistake.
Lovelace_gen is awesome !

1 Like

@thomasloven would it be possible to reload global config without a restart of HA?

Btw, lovelace_gen is indeed very cool. I wish I knew this a long time ago (as I have used decluttering card in the past) this is so much more. You actually made the vision I had for my project possible!!

I saw a new card, something with “teleporting” the card to another view. You say: only one at the time. As in? It can only show that card on a single view at the same time? Or do you mean, it will only work for a single card?

It’s not possible to reload the global config without a reboot at this time.

The new card - which is rather experimental still - works a bit like decluttering card in some ways, like yaml node anchors in some ways and entirely unlike both in others.

The main point is that you define a card once, and then use it in several places.
This can be done with decluttering card, node anchors and lovelace_gen, but in that case you get copies of the same card.

If you use e.g. state-switch to display different cards at different times, all the cards that are not shown are still loaded into memory and are eating browse resources. with q-card, they instead go off and do something useful somewhere else - hopefully where you’re currently looking at them.
A secondary effect of this is with cards that have an internal state - like how a fold-entity-row can be open or closed. If it’s a q-card, and it’s shown in two views, if you open the fold and switch to the other view, it will be open there too.

The reason there’s no forum topic, no blue diamond and it’s not in HACS is that I haven’t quite evaluated the impact of this on the performance of lovelace yet.

Ah I personally don’t care if it is in HACS or not :rofl::joy:, but I figured as much as you said it is experimental. It might have some useful cases, like the fold-entity-row you talked about. Though I wonder what will happen if my wife would open a view with that card, and I open another view that has the exact same card?

Anyways as always, great work on the updates, you made me happy and prepared for 105 (which runs absolutely fine now!)

Btw, I don’t even know what that blue diamond means :joy:

This is brilliant - do you post your config online somewhere?

Nothing. The not-quantum effect is contained within the current browser window/tab.

Ah alright, that sounds cool. I might play around with it and find some usefulness with it. Thanks for the reply.

My repo is currently a mess, and I realized I haven’t moved all sensitive details to secrets.yaml.

What are you looking for ? The examples I posted above are still the ones I use. If you have specific questions, feel free to ask !

I was interested in where your colNum variable was set, but also the structure of your room card

Is it possible to pass templated variables to a lovelace_gen include?

For example (this doesn’t work but is it possible somehow?).

view.yaml

# lovelace_gen
  - !include
    - includes/titles.yaml
    - title: {{ states('input_text.cycle1_name') }}

titles.yaml

# lovelace_gen
type: markdown
style: |
  ha-card {
    font-size: 20px;
    font-family: Oswald;
    height: 30px;
    background: none;
    margin-top: -0.5em;
    margin-left: -10px;
    margin-bottom: 0.9em;
  }
content: {{ title }}

And another question

Can you pass variables into the style?

For example (and again this doesn’t work but is iot possible somehow?).

# lovelace_gen
type: custom:hui-markdown-card
style: |
  ha-card {
    font-size: {{ font_size | default('20px') }};
    font-family: Oswald;
    height: 30px;
    background: none;
    margin-top: -0.5em;
    margin-left: -10px;
    margin-bottom: 0.9em;
  }
content: {{ title }}

“Doesn’t work” is not very descriptive.
Please remember that by extension of the second law of thermodynamics, things can generally work in one way and not work in infinite ways.

Both your example should do something (assuming you actually define font_size somewhere too), but it won’t ever update dynamically when cycle_name changes, because lovelace_gen is only run when the lovelace config is rebuilt.

Ok, so yes I do define font_size but it seems to ignore it and apply the default.

      - !include
        - includes/titles.yaml
        - title: MORNING CYCLE SCHEDULE
        - font_size: 10px

Example1.

# lovelace_gen
type: custom:hui-markdown-card
style: |
  ha-card {
    font-size: {{ font_size | default('20px') }};
    font-family: Oswald;
    height: 30px;
    background: none;
    margin-top: -0.5em;
    margin-left: -10px;
    margin-bottom: 0.9em;
  }
content: {{ title }}

image

Example 2.

# lovelace_gen
type: custom:hui-markdown-card
style: |
  ha-card {
    font-size: {{ font_size | default('10px') }};
    font-family: Oswald;
    height: 30px;
    background: none;
    margin-top: -0.5em;
    margin-left: -10px;
    margin-bottom: 0.9em;
  }
content: {{ title }}

image

You’re passing three arguments to !include, but it only takes two - a file name and a dict of variables:

!include
  - includes/titles.yaml
  - title: MORNING CYCLE SCHEDULE
    font_size: 10px
1 Like

I’m doing something stupid but can’t for the life of me see what. I have the following code:

# lovelace_gen

{% set colors = ['cyan', 'magenta', 'yellow', 'black'] %}

in a file that’s included from ui_lovelace.yaml. I’m happily using lovelace_gen elsewhere in my config, so it’s installed correctly. I get the following error:

while scanning for the next token found character '%' that cannot start any token in "/config/views/adminView.yaml", line 4, column 2

can anyone see what I’m doing wrong?

It looks right to me. I’ve encountered that error before due to erroneous whitespace (accidentally hit [tab] first when trying to [alt]+[tab]).

1 Like

Thanks, you set me on the right track.

Although that was the first text in the file, there was a blank line above it. Now it’s the first line and working.

1 Like