I have a switch and if switch is on I want it to display one icon and if it’s off, I want it to display a different icon. I created the icons and they are in the right folder (I think) This is from my customize.yaml
So this is a MQTT Sonoff Switch. I changed the name to toothbrush1 and added a tenplate switch toothbrush. (It’s a copy type switch and I added the icons as an entity_picture template.
Hope this helps someone else
Also as a postscript… I set the toothbrush1 entity to be hidden from Google Assistant. See you make ONE tiny change and that changes 4 files!
Yeah, sorry I wasn’t more helpful but I’m only just starting to get a hang of this jinja stuff and rather than give you a possibly incorrect example I thought I’d just point you in the right direction. Glad you got it sorted.
No worries, thanks for trying. I’d tried about a million different combinations before I posted and nothing worked. Frustrating a bit. Thought I could do it in customize but turns out you can’t.
maybe its the png causing issues (have that in several settings also), you could try with an mdi icon first, just to see if the logic is correct.
if that is fine, then solving the issue of the png is the next challenge…
Ive set up all customizations to use the : > and next line definitions to get rid of possible issue using the double and single quotes.
(btw, don’t be distracted by the _template in the switch name, it has nothing to do with this customizing template, it is a template switch (combining several switching and state techniques) (have a switch.sw_audio_auditorium_cl also) just to make it clear for me which is which
Yep, i merely suggested the mdi, to test the logic, sometimes the templates don’t work because the used entity isn’t in the state you’d expect it to be…
if its any help, this does work:
sensor.trash_today:
friendly_name: 'Trash today'
templates:
entity_picture: >
if (state === 'papier') return '/local/mijnafvalwijzer/papier.png';
if (state === 'gft' ) return '/local/mijnafvalwijzer/gft.png';
if (state === 'plastic verpakkingsafval') return '/local/mijnafvalwijzer/plastic.png';
if (state === 'restafval') return '/local/mijnafvalwijzer/restafval.png';
return '/local/mijnafvalwijzer/kliko.png';
_stateDisplay: >
if (state === 'papier') return 'Papier';
if (state === 'gft' ) return 'Gft';
if (state === 'plastic verpakkingsafval') return 'Plastic';
if (state === 'restafval') return 'Restafval';
return 'Geen';
then again, its a sensor, and not a switch.
about the correct folder: /local is in fact /www … at least when on Hassio.
in the original switch definition you have the a picture template. what happens when You change that into:
I actually tried in the template checker in dev tools to see if the template was working and it was returning the correct png/jpg file. Honestly I tried so many things and restarted HA so many times… it’s hard to remember what I did and didn’t try.
In any case, what I posted above solved the problem and it’s working for me now.
Only problem is the icons are bigger than the MDI ones so I edited them to make them 25x25 like MDI but it seems that the system scales them up again anyway. LOL. So I think some people are using bigger icons with lots of white space (and I cropped mine back sigh)
Anyway, I don’t think I’ll bother about the icons unless there’s an easy fix.
EDIT: Unless that is normal for this code language??? I’ve noticed that 3 equal signs are everywhere. What language is this? That seems odd. Ignore this suggestion if that’s normal code…
Yeah I’m sure I noticed that in the 1000 things I tried.
I have it working as per post 3 above.
I appreciate the help but unless anyone can either improve upon post 3 or better yet give me a way to just use customize to do this without using a platform template like I was originally wanting to do…
HELP: Saw your post concerning ICONs. Noticed you experimented with .jpg and .png formats (any luck with .gif) I need to generate my own icons but have been unable to find anyone who has done that (until I saw your post). Communicated with OttoWinter (discordapp) but no luck. My internet service is so bad, ATT will guarantee NOTHING and I go down frequently (way out at the end of the line–yet another reason NOT to use the ‘Cloud’ for anything), I can’t depend on icons provided via the net (sometimes they arrive from MDI, sometimes from FAS and sometimes not). I have generated my own icons for HA Floorplan and hoped I could do the same for HA general use. (Running HA 0.86.3, ESPHome/Lovelace on a Rasp PI 3 B+). Any suggestions would be greatly appreciated.
Thank you for the rapid response. Please excuse my ignorance, haven’t written any code since Excell Macros in the early 1990’s and programming (Basic, Dos/Batch files and Autocad Lisp) since the late 1980’s. A bit slow now. Just started with HA, mid December-18. If I understand the post, I could use something like…icon: /local//.png ?? Or could I direct it to my Floorplan directory where I store my Floorplan icons?
Thanks again
First, they aren’t icons. They are images. The icon option in home assistant is always referring to the mdi icons which you are trying to avoid. You are trying to use an image file as an icon. So, from here on out you should be looking to replace the picture or image.
Second, are you using floorplan? If so, are you using CustomUI along with it?
My HA crashed yesterday so I took the opportunity for a clean HA, ESPHome/Lovelace install…NO MQTT. I did not reload my Floorplan however; I am recreating it using the ‘Picture Elements’ card in Lovelace.
Ok, so you aren’t using custom UI. So this ability may or may not exist in the current structure. It depends on what card you are using and what entity you are trying to display. Pretty much everything in this thread is for the old ui aside from the picture_entity_templates on template sensors.