I always wanted to have some custom icons for my Home-Assistant setup. Unfortunately, if you set a SVG directly via URL (/local/myicon.svg) it does not change color depending on its state. On the other hand, if you set an MDI icon, the color changes.
So I looked for ways to get color changing icons and came across Thomas Lovรฉn’s hass-fontawesome that does exactly that for the Font-Awesome icons.
I tried to use his generate.py
to generate a custom font file from my SVG’s but it failed.
After looking into it, I change quite a bit so that the script worked for me (see
my fork
).
I struggled a bit getting my font to work but finally here’s an example of what I got (the two bottom icons):
If you also want to create your own iconfont, here are some obstacles that made me strugle.
1. Make sure your SVG has just one path, the generate script will grab the first path and use that in the font file. ๐
This is an example of a not working SVG, as you can see it contains multiple path nodes.
|
|
Simply use Inkscape for example an combine the paths using the appropriate tools.
2. Adjust the settings in the generator sxcript ๐
There a 3 settings that can be adjusted in the generate.py
.
|
|
PREFFIX
defines what will be the preffix you later on will use in your HA config. If you for example set it to fas
you will define a icon in your config like icon: fas:clone
OUTFILE
defines the name of the resulting html file.
SIZE
defines the size of the iocns, let this value as it is.
Place the generator.py in the same folder as your SVG icons and run it from there: python3 generator.py
. The resulting html will appear in the same folder.
3. Install the font file in the right place ๐
Make sure you’ve created a www
folder inside your Home Assistant config folder. In there, place the generated html file.
4. Configure the custom font file for use in your HA config ๐
|
|
I used cutomize_glob
to set one of my new icons for all of my heating valves like so:
|
|
Restart HA after editing the config!
5. Make sure the cache of your browser doesn’t fool you ๐
My firefox fooled me with its cache. Simply hit Ctrl + Shift + Del
and make sure to delete the cache when trying to get the font working, after that refresh the browser with F5.