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
wrong entity in javascript template #389
Comments
Hi, I understand your use case, but that's not possible. |
That's an unexpected limitation. Would a template have the same problem if it had both the parent and the child button-card in the template? What about 3 nesting levels in the template? I'm curious what specifically causes the technical challenge. I haven't had a chance to review your code to see what it's doing, but I'm a developer by trade and quite familiar with javascript and DOM so I should be able to understand the tech details if you have time to explain. A related issue I found after creating this issue is that the triggers_update don't seem to be able to use javascript for the array values. I have a case where I use variables for 2 entities that are related to the main entity for a composite button and I wanted to automatically set up the triggered_updates for them in the template because they aren't auto-detected in the javascript (I assume because they are variable names in the javascript). I can create a separate issue for this if there is a chance it can be implemented. I also discovered variables don't seem to automatically pass down to nested templates, nor can a variable use javascript to refer to another variable in the same list. Is that feasible to do? |
You can nest templates inside templates.
The reason triggers_update was introduced is because the card was updating on every change in every entity of HA and it could become quite slow.
If you have an idea of how to implement variables dependencies in YAML, I'm all ears ;) (except by running them in the alphabetical order, which is the only solution that I found to be not too bad) |
Thanks, I appreciate the details. I have a thought on the entity localization. This is just a brainstorming concept and not based on any review of your implementation or any knowledge of lovelace because I haven't dug into any of that yet (I will eventually...too many projects LOL). I don't know how much of the yaml merging you have control over, but what I'm picturing is during the merge each button card gets a fresh entity that is defined for that card, with a Regarding Variables passing down to child button cards would probably just be handled while merging everything. Essentially the top card initiates the dictionary, and then as each button card is found it is given a clone of the parent button card's dictionary and any local variables of the same name override what was in the cloned instance. Do variables support re-evaluation on state change? I can imagine that walking the hierarchy to do re-evaluation would have some significant overhead. No idea if you're already doing something like this, but it occurs to me that a map can be built up while running through the first merge & evaluation to simplify re-evaluation. Perhaps a dictionary of triggers (one entry per entity trigger), and each trigger having an array of wrapper objects. One wrapper for each javascript encountered, with references to the local entity instance, the local variables instance and a DOM reference of where to stick the result. I really should spend some time looking at your implementation before I get too crazy with ideas so I can understand the challenges. This is my new favorite element for Lovelace because it has the power to create some really nice composite elements. I've already created a bunch, and the templates really help reduce repetition. My templates are getting out of control though...I wish there was a better way to organize them as files instead of at the top of my raw dashboard config. I have multiple dashboards, so I still have to replicate all my templates by hand. Last night I just clobbered some recently added changes that I hadn't yet copied to the other dashboards because I was experimenting in a different dashboard that didn't have the changes. I saw passing mention of Thanks again for the details on my questions. |
I've run across the same challenge. This is indeed unexpected behaviour and should be documented explicitly. It leads to the effect that you cannot copy a working |
It's not unexpected 😊 however it's not explained in the documentation, I agree. The template way works so maybe you did something wrong. Please share the config if you want. |
This is fixed in 4.0.0. You can stop template evaluation on a per custom_field basis. I'm closing. |
Checklist
Describe the bug
A
button-card
nested inside anotherbutton-card
usingcustom_fields
is not getting the correct entity variable in javascript templates. It is receiving the parent card's entity.Version of the card
Version: 3.3.6
To Reproduce
This is the configuration I used:
Screenshots
The yaml above gives this result. The icon is from the correct local entity, but the name is from the parent card's entity.
Expected behavior
The javascript should receive the entity for the local card. It may be ok to inherit entity from the parent card if the local card does not define an entity, but only if not defined. If an entity is defined on the local card but does not exist then the javascript should get undefined.
The text was updated successfully, but these errors were encountered: