šŸ’” UI eXtension - Add CSS styles to (almost) any part of the Home Assistant UI

your not necessarily a PIA :wink:
just need more time to understand that this

will never happen in HA stock frontend. and this is essentially the same:

so we need custom cards like this to fix it for us.

as for your other questions about the why, just take a bit more time to read it and understand this new integration (that’s new in itself, and offers a lot of functionality) is now in serious active development (which card-mod didnt see in a long time until Darryn came along).
As HA keeps changing Frontend, and does that in an accelerated momentum, it was no longer feasible to update someone else’s code/card and keep up with that.

Lastly, it’s of course up to you, which tool you prefer to use, always good to have choice.

Adding to what @Mariusthvdb shared.

Even if Frontend added a style config item to cards, I doubt it would then support templates. So this is where Uix would always be superior.

As far as what you can styled with Uix, ā€œalmostā€ is part of the description to cover things which may change in Frontend, or are quirky stand alone elements or custom cards, aka inbuilt energy dahsboard date selector which recently was a quirky standalone element as a hui-root sibling which was not touchable by Uix (well not easily until ha-drawer was added in 5.0.0). Thankfully the energy dashboard will be updating to use the new dashboard footer which means it will be loaded by hui-card and thus stylable with Uix.

As for a major difference that Uix has over card_mod, is that ā€œalmostā€ is far wider spreading out of the box given that the Uix Frontend resource is loaded as an extra module without any fuss to the user.

ha-nunjucks is great for custom cards, but I’m not sure if it’s worth switching away from the default engine for this project. It may give it a tiny performance bump, but ha-nunjucks is better when a custom card has custom template variables or functions that change over time like a feature value in my projects. I do think (of course I do I’m biased) it’s a better option than JavaScript templates since it’s 99% the same syntax as the default jinja2 engine, outside of Python vs JavaScript syntax hiccups.

1 Like

I took a quick look at ha-nunjucks. Reviewing in isolation from adaption to any project, I note the following:

  • ha-nunjucks needs performance improvements similar to what was added to auto-entities 2.0.0. Currently ha-nunjucks looks up config entries like labels, integrations, groups etc using find() which is inefficient for large number of objects.
  • ha-nunjucks does not reload labels, config entries etc. when changed in backend, which was also added in auto-entities 2.0.0. So if you add a new label ha-nunjunks won’t see it until you refresh the page.

As it stands the performace aspect would make ha-nunjunks not suitable for Uix which needs high performance at all times. Also, adding/adapting ha-nunjunks, as well as preserving current template support would mean differet ā€˜nunjucks’ which would likley be confusing for little gain.

As for any gain from having templates run on client rather than server, recent changes in Uix (card_mod v4.x heritage) brought in performance gains in that tenplates have a cooldown period of 20s, meaning that if the same template is used on different dashboard views, it is reused from cache - or similarly if you go to a different view and back to the same view within 20s, the templates on that view will be used from cache.

Regarding using javascript, testing (thanks @Mariusthvdb) showed that expectation is to be able to use a JS template in a Jinja template, whereas the implmentation was one or the other. This could be done but tracking, updating the javascript result would be inefficient (same as variables not below). The underlying wish is to mimise written code and have variables available in Jinja/JS. Jinja variables (e.g. have a variables: config that allows for Jinja templates for variables) would also be inefficient as the templates using the variables would need to updated whenever the variables being tracked changed, becoming even more inefficient if nested variables are supported. So at the moment if you wish to try and reduce/simplify code, the CSS var approach is a good middle ground (guide on this to be published soon).

Going through the testing of the javascript implementation with @Mariusthvdb showed that implmenting an idea without understanding the expected use case is not good use of development time. So I would ask for use cases for any functional change like adopting ha-nunjucks.

Thank you for your feedback and great to have these conversations which may lead to the next best feature for UIX. :bulb:

2 Likes

I’m open to feature requests and PRs :smile:. I haven’t noticed any issues with performance in real world use and have made a few optimizations over time. There’s always room for improvement though, and I wouldn’t be against a v2 that rearchitected things to be even more efficient.

3 Likes

Noted. :bulb: If there was a project that I was involved with using ha-nunjucks then I would submit PRs for what I mentioned above.

1 Like

A quick read UIX Guide on using custom CSS to reduce your templates.

3 Likes

yep, that feature is pretty cool, and though I found it a bit daunting at first, it makes for pretty clean configs, and prevents the endless repetition of setters, if one needs those I more than 1 target of the modification .

been looking for a long time to do that, declaring a global variable for the full config, and injecting that at any level in that config.

1 Like

A quick read UIX Guide for styling new power now badges used in the built-in energy dashboard.

That reminds me of a good point to make. Custom CSS vars can be used any point higher in the DOM. I will give thought to an update to the guide.

1 Like

Speaking of instructions, I remember my early days when I was struggling at DOM selector and how to find the correct path to the element. This helper helped me a lot and thanks to it I slowly found out how everything works. I think that many people have the same problem… I was wondering if you could create a similar helper for UiX. :hugs::hugs:

https://matt8707.github.io/card-mod-helper/

2 Likes

Beat me to itšŸ˜‚ but I second this! I would love to see something like this!

Yes, I would like to cerate a DOM tree discovery tool of some sort. I was thinking along the lines of a console helpers, something like window.uix_tree($0) and window.uix_path($0). So you would go to the element inpsector, like you need to do for existing tool, but rather than copying a path and going external, you would run one of the commands:

window.uix_tree($0) - general helper

  • report of closest UIX parent (element having a non-child uix-node)
  • report on current UIX children (elements with uix-node which have the parent node as parent)
  • report on all possible paths e.g. if you run this on a card, then its likely that ha-card $ will be an available yaml target path
  • report depth will be up to next UIX parent (element with a non-child uix-node)

window.uix_path($0) - specific helper

  • report on closest UIX parent (element having a non-child uix-node)
  • report on path to target element ($0). This will stop at shadow Root that contains the element. The path will contain any specific selectors for multiple elements of same type/class, otherwise omit these as they are superfluous in majority of cases
  • report on class / id / element for CSS target within the sahdow Root
  • perhaps generate some boilerplate uix config yaml

I believe these would be super handy in this format, and take away a lot of guess work that still exists with the external helper due to the smarts of constraining to uix parent nodes.

Let me know your thoughts. :bulb:

5 Likes

Quick read of using templates with themes when needing to target a specific card/badge type.

sweet, and a new var to template: config.type , now that creates opportunities galore

1 Like

What’s the difference between this and card-mod? I have had no issues with card mod during the March beta.

What new features/improvements does this bring? The docs tell me how to do things but not actually what the differences are.

There are a lot of changes with ha-dialog in the beta. If you don’t have any mods for it, you won’t know. But uix mod is already ready for these changes

May I ask, why you released a new card-mod version contrarely to the message here? Will it now again a parallel live and maintenance?

Card_mod 4.2.1 was released 3 weeks ago. Uix 5.0.0 week and a half ago. My post you refer to just over a week ago.

No, I will not be contributing to card-mod any more and focusing on UIX.

You are right. Absolutely. I mixed it with your update of browser mod. Sorry for the confusion.

1 Like