hi in esphome you can use subsitutions and variables… as i wanna be able to change 1 line in switch template and it just used through out… instead of needing to change swtich name 3 4 times
so my example is
but of course it doesnt work that way… but can i do that ? does the template card let you do stuff like this where you can sub 1 line and it gets referenced so your not having to change multiple spots…
also trying to do color icon but it doesnt like it… i tried this
icon_color: >-
{% if is_state('switch.dehumidifier_1'), 'on' %}
yellow
{% elif is_state('switch.dehumidifier_1'), 'off' %}
green
{% else %}
blue
{% endif %}
Although you can use a Jinja template for the entity_id, it isn’t possible to define a variable using the YAML for a template switch, so it is not possible to do a cookie-cutter template switch the way your code suggests. (You also can’t use { { and } } as Jinja print delimiters; there can’t be spaces between the brackets–it needs to be {{ and }}.)
Blueprints support template entities, but I think that technically the template switch is in the switch domain, not template, so you probably can’t use a blueprint for this, although you might look into it further.
(Also, I don’t think icon_color is something you can define in the YAML, Jinja or not…; at least it’s not listed as a valid option in the docs).
ah ok ya so cant do that
i even figured maybe how you can use like Basic or Python
where
switchname: “switch.plug_1”
$switchname or switchname$
to be the place holder for it… so not able to do it… and since the changing of the template icon can be done… i figured i can do the same with the color
i dunno is it worth asking for a feature request if it hasnt been asked for place holder…
so for now just stick to if i have to change it change them all at once… i figured be nice to just fill in 1 spot…
@tom_l cant seem to understand it. from that link with the people having issues and it seems for just mqtt but i trying to add to add like 1 variable to to equal those few spots where i have {{switchname}}
No, it is an example of YAML anchors that has been applied to mqtt light configuration.
You can use YAML anchors with any YAML. Think of it like supplying a template then for each thing you want to define all you have to do is tell the template which bits are different.
@tom_l
so i guess i did it wrong i followed the first example but of course i did it wrong in the wrong order… i also wanted to do 3 different icon color changes in the template but it doesnt let me i guess you can only do it in the card? as i figured u could do in the template… since you can change the icon in the template but you cant do it if its unavaliable
but here is what i did with anchor… now im sure its totaly wrong but thats how i figured it worked?
as im a visual learner is there a good video that explains how anchor works step by step… as i trying to understand the second with key: << etc but i not getting it as i try to learn something new everyday just struggling learning that
@tom_l i dont think these anchors work for switchs … probably just like colors… as i been reading people use it with colors or sensors but not a switch like i trying to do… probably cant be done as i even tried
so i going to research more about this anchor thing and see if it works for other things i might be able to do… for now i just have to specficy the switch name multiple times instead of 1 reference
unless you have to specify in different sub headings but guess ill keep trying to learn this anchor stuff