I don’t know if this problem can be posted here, but here I go: since compiling yaml is painfully slow on my HA Green, I have installed Python and ESPHome on my desktop computer, but every time I try to compule the yaml code, I get the error that the font I want to use is not a valid font file. I have literally tried every supported way of referencing a font, but I always get the same error.
But even when I reference locally installed fonts in the .esphome folder, I get the same error “not a valid font file”. (The font names and path are correct, and the font files are not corrupted - I tried with various fonts.)
You should be able to use forward (/) slashes, but perhaps it’s easier to just copy the font file to the same directory as the Python script, and simply use just the filename (not the directory path) in the script:
from freetype import ( Face )
Face("Roboto-Bold.ttf")
I just put the font in the same directory as the Python script, and it doesn’t give me an error (nor anything else), so now I’m even more confused about the cause of the error …
Possibly an incorrectly formatted path in the YAML, like with the script?
Wouldn’t explain the issue with type: gfonts, but since you’re using Windows it wouldn’t surprise me if there’s some sort of firewall getting in the way there.
No problem - thanks for your help. I haven’t found any useful information online on this error, at least not with other suggestions to solve it. Compiling via ESPHome Device builder inside HA works fine, at least.
Thanks for the advice, but Pillow was already up to date …
Requirement already satisfied: Pillow in C:\Users\Björn\AppData\Local\Programs\Python\Python312\Lib\site-packages (12.2.0)
As stated above, I already tried with the .ttf in the same folder as my project, but to no avail: I keep getting the error … I’ve also tried with multiple fonts and font types supported by esphome by all give the same error.
Edit: I got a step further by referencing the fonts directly in the Windows Fonts folder, and I no longer got the error. But I now get CMake error (fatal: not a git repository (or any of the parent directories): .git) … but that’s not something to be discussed here, I suppose
You should not have to manually download a Google font. If you use the YAML format you have, it’s suppose to download the font to your .esphome folder and cache it for use. If you’re trying to find a way to point to a local folder, you are likely spending time on something that isn’t going to help you.
I would try deleting the .esphome folder (should be in the same directory as the YAML file but might be hidden) and then try again. If that doesn’t work, try this format in the YAML instead:
Strangely enough, the font seems to be downloaded, as after I deleted the .esphome folder and run the YAML-file again, I get a “font”-folder inside the recreated .esphome folder with the font file which gets the name “Roboto@400@[email protected]”. I can open that font file without any problems in Windows.
Now that we aren’t down the “font must be downloaded” rabbit hole, I’d suggest going back to one of the earlier troubleshooting things. Move that test.py file you created earlier into the same directory as the YAML. Then modify it to read:
from freetype import ( Face )
Face(".esphome/font/Roboto@400@[email protected]")
I’d be curious to see if you get a different result than last time, since now you are testing the actual font that was downloaded that ESPHome is trying to use.
The only other thing I can think of offhand is that there is some odd permissions issue with your .esphome folder that is keeping ESPHome from properly reading the file when it runs versus when you open it by hand.