Custom icons status dependent

Hallo

Can somebody help me with this, i want to switch between png file when status is ON or OFF
this is already working ( at /config/configuration.yaml):
‘’’’’’’’’’’’’’’’’’
homeassistant:
name: Home
unit_system: metric
customize:
switch.tuin_verlichting_waterornament:
friendly_name: Tuin verlichting
entity_picture: /local/GardenLight48_On.png
‘’’’’’’’
the entity “switch.tuin_verlichting_waterornament” has the .png icon at the dashboard, but it should change when it is OFF ( to icon /local/GardenLight48_Off.png)

i did try many codes but non was working
can somebody give be the correct direction

did something like this:
‘’’’’’’’
state_image:
“on”: /local/GardenLight48_On.jpg
“off”: /local/GardenLight48_Off.jpg
‘’’’’’’’

did something like this:
‘’’’’’’’
type: picture-entity
entity: switch.tuin_verlichting_waterornament
state_image:
“on”: /local/GardenLight48_On.png
“off”: /local/GardenLight48_Off.png

did something like this:
‘’’’’’’’
switch.tuin_verlichting_waterornament:
templates:
icon: if (state > 0) return ‘/local/GardenLight48_On.png’ ; return ‘/local/GardenLight48_Off.png’;
‘’’’’’’’

but non is working: :roll_eyes:

Are you using:


Mariusthvdb/custom-ui: Adapted Custom-ui for HA 110+ (github.com)

?

And please use this button when you write code on the forum:

i checked at configuration / info
but i do not see CustomUI listed

Does nobody knows ??

You think I asked a completely unrelated question?
OK…

im sorry but im new at HA , what is CustomUI?

And is there no way to do that with

homeassistant:
  customize:
    # Add an entry for each entity that you want to overwrite.
    switch.tuin_verlichting_waterornament:
     friendly_name: Tuin verlichting
     entity_picture: /local/Custom_icons/GardenLight48_Off.png

?? how to add to configuration.yaml
entity_picture: /local/Custom_icons/GardenLight48_On.png

if you want to use templates like:

switch.tuin_verlichting_waterornament:
  templates:
    entity_picture: >
      if (state > 0) return '/local/GardenLight48_On.png' ;
      return '/local/GardenLight48_Off.png';

you need to install GitHub - Mariusthvdb/custom-ui: Add templates and icon_color to Home Assistant UI is what @Hellis81 meant, and could have said a bit more helpful tbh…

Please note that is not officially supported in Core HA, but it works great, all of my 2800+ entities are customized :wink:

of course, until the dev team changes Core HA so that it breaks custom-ui …

I didnt question the logic of your template, are you sure the switch has numeric values, and not ‘on’ or ‘off’?

secondly, note that I changed the template to customize entity_picture: where you used icon:

thx Mariusthvdb

Ok , a little more help i need

i installed custom-ui
image

but still this is not working

switch.tuin_verlichting_waterornament:
  templates:
    entity_picture: >
      if (state > 0) return '/local/GardenLight48_On.png' ;
      return '/local/GardenLight48_Off.png';

it should me added to the configuration.yaml right ?
but should there be added some more text in front like

homeassistant:
  customize:

if (state > 0) is not working
everytime it is ‘/local/GardenLight48_Off.png’;

so looks like state in not 0 but ?

this is working

homeassistant:
  customize:

     switch.tuin_verlichting_waterornament:
      templates:
       entity_picture: >
        if (state === 'off') return '/local/Custom_icons/GardenLight48_Off.png' ;
        return '/local/Custom_icons/GardenLight48_On.png'; 

Yes that’s expected for a switch, as I wrote and asked you above :wink:
Glad you got it working

you could even make it shorter:

return '/local/Custom_icons/GardenLight48_' + state + '.png'; 

or better even:

return '/local/custom_icons/gardenlight48_' + state + '.png'; 

if you’d use only lower characters in you path and file names (which is my preferred way)

OK for supporting . im a newbe and every week testing and learning about HA. I run for some years Domoticz now, but that has its limitations. So i hoping HA will do the job for me in future