You are the one @Mariusthvdb!
I was editing my config on the customize.yaml instead of in the folder. Dumb…
Thank you to point out my mistake and for the great help you always gave me.
You are the one @Mariusthvdb!
I was editing my config on the customize.yaml instead of in the folder. Dumb…
Thank you to point out my mistake and for the great help you always gave me.
Most welcome!
Hi
I try change icon for my cover in home assistant and i add to customize.yaml file this but no working… Still show default icon:
cover.roller_shutter_for_ha_0_1:
templates:
icon: >
{% if is_state('cover.roller_shutter_for_ha_0_1', 'open') %} mdi:window-shutter-open
{% else %} mdi:window-shutter
{% endif %}
Please anybody can help me…
I’m using following:
icon: "if (state === 'off') return 'mdi:door-closed'; else if (state == 'on') return 'mdi:door-open';"
OK i test you solution but also not working. I add it to customize.yaml for my Roller Shutter and it looks like:
cover.roller_shutter_for_ha_0_1:
icon: "if (state === 'open') return 'mdi:window-shutter-open'; else if (state == 'closed') return 'mdi:window-shutter';"
Now for Roller not show any icon.
Yau are using it on default entity card ?
And you have this code for icon in customize.yaml or in code card in Lovelace ?
And what type entity is your ? It is platform templating or binary sensor ?
your template seems fine, what happens in developer/template?
if that works, you should be able to use it as an icon_template, provided the component supports an icon template. don’t think Cover does though: Cover - Home Assistant
If not you could use custom-ui, and use the JS template
homeassistant:
customize:
cover.roller_shutter_for_ha_0_1:
templates:
icon: >
if (state === 'open') return 'mdi:window-shutter-open';
return 'mdi:window-shutter';
note this is not in Lovelace cards. Depending on the cards you use Lovelace cards need their own syntax, or can’t use templating at all…
Summary
For cover i can not change icon ?
Only by custom UI i can ?
not sure, did you try what I suggested above?
i put this to template in developer tool it show error:
Error rendering template: TemplateSyntaxError: unexpected char ‘‘’ at 15
correct to
{% if is_state('cover.roller_shutter_for_ha_0_1', 'open') %} mdi:window-shutter-open {% else %} mdi:window-shutter {% endif %}
and in dev tool - template show only: mdi:window-shutter (state is closed)
But when state is open show in dev-tool template mdi:window-shutter-open
add it to config card entity and it looks like:
entities:
- entity: scene.swiatlo_scene
- entity: cover.roller_shutter_for_ha_0_1
templates:
icon: >
{% if is_state('cover.roller_shutter_for_ha_0_1', 'open') %}
mdi:window-shutter-open {% else %} mdi:window-shutter {% endif %}
show_header_toggle: false
title: Sceny
type: entities
and also not showing correct icon. Still default icon.
haha, note that the quote was your own code, but because of the editor here in the community that sometimes gets changed to us reversed quotes, always be careful copying from the community
so, the template itself is correct.
next step would be to add it in the config to customize the entity, following these guidelines: https://www.home-assistant.io/docs/configuration/customizing-devices/
but since you need the template, this can’t be done straightaway. Now I dont know about the cover integration, but the docs seems not to show an option for customizing the icon? You could try of course it would probably say ‘invalid config’ is not supported.
After that, your final solution would be to use custom-ui indeed. Which makes it all possible… use the js template I suggested, and you’re done.
the card you show above is a lovelace card, the cant use templates at all. so you should take that out.
You can use other cards, like custom button card, and have icons change depending on state.
Or have a look at Picture entity card and use the state filter: https://www.home-assistant.io/lovelace/picture-entity/#examples (picture, not icon though)
i added it to customize.yaml and still not working:
cover.roller_shutter_for_ha_0_1:
templates:
icon: >
{% if is_state('cover.roller_shutter_for_ha_0_1', 'open') %} mdi:window-shutter-open {% else %} mdi:window-shutter {% endif %}
If no working solution is only use custom card to do it ?
I dont know why option change icon for cover is no implement in Home Assistant. This is no look good…
I am using customizer and customize_glob.yaml (add on for HA) as mentionned by @km2000us on Mar 21, 19…
Here is an example from customize_glob.yaml:
"switch.etang_interieur":
friendly_name: Pompe Etang Intérieur
templates:
icon_color: if (state === 'on') return 'lime'; else return 'red';
icon: if (state === 'on') return 'mdi:water-pump'; else return 'mdi:water-pump-off';
But it is for switch not for cover.
you need to be precise. The template you use is a Jinja template, and is only supported in native components explicitly supporting that. Or in template sensors and automations. see the links on https://hvb.duckdns.org:8125/developer-tools/template
if so it uses the syntax:
icon_template: >
{{etc}}
Custom-ui uses javascript templates (JS). This uses the syntax:
entity_id:
templates:
icon: >
if (this) return 'that';
SO, not only are you using the wrong template (jinja instead of js) you are also mixing the syntaxes …
In order to use the JS icon template I provided above, you need to install custom-ui first and then save the template in a customize section in your config.
though the templates are fine (you can leave out both 'else’s) they shouldn’t be in customize.glob which is for global customizations. These templates are for an individual entity and should ideally be under
homeassistant:
customize:
switch.etang_interieur:
(note there’s no need to quote the entity_id)
But in configuration.yaml i have add this:
homeassistant:
customize: !include customize.yaml
and i must add to customize.yaml…
If i use standard card i must use
icon_template: >
{{etc}}
???
yes, thats fine, simply only add the entity and the template
not sure what you mean here, but no support for templating in standard Lovelace cards. You can use templating in the ‘backend’. Server-side. Where you create your sensors, automations, and define the config of integration etc etc.
Lovelace is a frontend thing. Browser-side
ok but still dont understand… Why i can not use template from custmize.yaml to my cover… Sorry… i am begginer.
because you can only do what is designed to be done. If it is not supported natively, than you can use custom-ui. And need to conform to the syntax and techniques it uses.
everything is explained in the docs I linked you to. It is of utmost relevance you should read that, and try to grasp what is explained there.