I am trying to get better in Jinja and yaml and I hope I post this in the right category. I have added some extra buttons to the map card which I want to use to toggle a specific person on the map. Is it possible to use Jinja templates to conditionally add person entities to the entities attribute of the map card?
Something like this:
I have tried many things, but I cant get to return an array within the Jinja template. Or does anyone have another approach to toggle the entity on the map card?
You would have to use card templater to add templates to this card (and most ootb cards)
I myself used this for sort-of the same as above but am now using tabbed-card where I have each tab represent a map with the person/people I am interested in
Works perfectly! I have the following code in a custom:stack-in-card, with a button overlaying the map card that toggles the input boolean on tap action:
Deleted my first reply to your answer (don’t know if you read it), the lovelace-card-templater card is awesome! Both @Edwin_D and your answer works, but I am going to mark this one as the solution, since this card allows me to apply Jinja2 templates to a few more things I wanted to do as well. E.g. add another toggle for 24 hour path display on the map (see code below). Thanks to both of you!
After testing I found that for this threads question, it is best to use custom:auto-entities to toggle entities on the map card. All the code shared above works, but both the custom:config-template-card and the custom:card-templater need to reload the card based on entities state changes. For the map card, this shows a quick black map on the entity state changes.
I am now using a combination of custom:auto-entities and custom:config-template-card / custom:card-templater. Where the auto-entities toggles the entity on the map card, and either the template-card or card-templater can toggle the hours_to_show path on the map.
This is not the ideal solution.
You said that blinking was there - probably it is NOT now because the CTC card monitors only input_boolean.
But the map will not be updated automatically if you keep it open - you are not monitoring trackers.
If you add trackers to the “entities” - the card will be updated. But you will see blinking )))
If you need the map to be updated - do not use CTC.
Generate a map inside auto-entities - use a template for hours_to_show.
What you need is a bit of imagination)))
Hint: a vertical stack filled with maps; but generate only ONE map.
The card seems to be updating automatically within CTC. The hours to show path is disappearing live on the map when I just looked at it. CTC just does an extra re-draw of the card when the input boolean state has changed. The internal features of the card (updating location etc) seems to be still working.
The map also updates when I use the input boolean used in the template of auto entities, while this input boolean is not watched by CTC.
No. I will try to reproduce your case in a few days.
What I observed is - CTC does not update the card if a changed entity is not declared as monitored.
For instance - place history-graph inside CTC, it will not change.
But I never put auto-entities inside CTC.
If you say that the map is updated - then probably it is somehow related to processing jjinja.
You are right! For the person entity to be live updated on the map, I have to declare it in the entities attribute of the CTC card (to be monitored).
I will update the solution code that the person entities must be included in the CTC card. I don’t mind the quick blink on an update, and use the auto-entities card to prevent the blinking when I toggle the person entity on the map.
The vertical stack solution wont work for me, since I want to toggle up to 5 persons, so I would have to fill the stack with all the person combinations.
In my proposed solution you will not need CTC.
Only auto-entities.
As I said - stack will contain only one card))). Call it a trick. Idea is to wrap the WHOLE card with all trackers and hours-to-show inside a template.
The auto-entities card with a template which generates ONE card with dynamically defined properties.
But the result is supposed to be placed into a destination card (stack) with a defined card-param (“cards”). So, the template generates ONE card, and the stack will be fictional))