-
Notifications
You must be signed in to change notification settings - Fork 22
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
Feature: Access globals from Jinja Templates #57
Comments
This won't be possible anytime soon, lovelace_gen doesn't even have access to the state machine. I.e. all of the extra functionality that HA adds to Jinja2. You can use {% raw %} and {% endraw %} to put templates into fields that won't be executed. The field has to support templates though. The problem you'd need to overcome is that the configuration is loaded well before the templating engine has even started. EDIT: IF you understand the above and you don't want to load macros that use the state machines, maybe we could implement a separate feature that acts like the custom_templates, but is not shared with the custom templates. Maybe lovelace_gen_templates or something along those lines. That would be a very nice feature for sure. |
If you do the work. I'll help you test it. |
Ok, so the challenge is getting the _global variable loaded and registered very early in the HA startup process before template compilation occurs which may occur before the integration is loaded. This is not unlike restarting HA with a Lovelace Gen screen open and the rendering fails (since the integration is not loaded) I suppose another way would be to load the metadata into the state machine and then access it just like any other state machine data. |
I got it working and it was a one-liner. Basically what it does is create an entity called "lovelace_gen.data" with attributes that represent all of your top level keys -which is consistent with the way the _globals works
Or more typically accessing a specific list - this is my door list
or accessing a specific door (I may look at reworking my metadata to make this simpler)
Next step, I'm going to see how accessing this from auto-entites works. |
The PR was abandoned in April. Any reason why @PeteRager? |
Feature: have the Lovelace global definitions be available in HA templates and automations. This would allow the metadata to be used in automations (or anywhere Jinja is used). I'm willing to do the work.
Use Case: I'm using this metadata to create an object model as part of the process of generating config.
Here is an example of a light control loaded into Lovelace Gen globals (which allows the UI to be autogenerated)
So right now, I use that config to generate packages (templates and automations) using sed and yq to essentially replicate the package for each object to put in the right sensors, delays etc. So I can add a new light control in about 5 minutes. With the metadata available this process could be simplified.
The text was updated successfully, but these errors were encountered: