tom_l
October 20, 2019, 1:58pm
1
For a lovelace clock card I would like to use an LCD TTF font file I have here:
/local/fonts/DJB Get Digital.ttf
Is this possible?
Current card config:
type: markdown
style: |
ha-card {
padding-top: 18px;
border: solid 2px var(--primary-color);
}
h1 {
text-align: center;
font-size: 6em;
margin-bottom: 0px;
}
h2 {
text-align: center;
}
content: |
# {{ states("sensor.time") }}
## {{ states("sensor.date") }}
klogg
(Klogg)
October 20, 2019, 2:09pm
2
I do this using (in a picture-elements card):
- type: custom:hui-markdown-card
content: >
Coming Up...
style:
top: 8%
left: 83%
width: 28%
text-align: center
font-family: Quicksand
font-size: 34px
"--primary-text-color": "#A1A1A1"
"--paper-card-background-color": "rgba(0, 0, 0, 0.0)"
"--ha-card-box-shadow": none
This is in my resources.yaml
- url: https://fonts.googleapis.com/css?family=Quicksand
type: css
I’m not sure how you’d relate that to a local font but maybe it is helpful?
tom_l
October 20, 2019, 2:21pm
3
Yeah a search tuned up similar results but this font isn’t available as a hosted css resource. It’s a local ttf file.
ceh
October 20, 2019, 2:39pm
4
Can you refer to the local file as a resource? file://…
tom_l
October 20, 2019, 2:42pm
5
Sure the url is just local/fonts/etc...
But what is the type?
And how do I use it in the card?
tom_l
October 20, 2019, 11:38pm
6
I think I can use this to generate the css resource:
tom_l
October 23, 2019, 1:05pm
7
I’ve found another way that does not work.
I used the link above to generate the font kit. Saved it to my www folder. They include a sample html file that displays the font correctly.
Added this to my resources:
- url: /local/fonts/lcd/css?family=djb_get_digitalregular
type: css
But adding this to my card does not change to font to the expecte one.
content: |
# {{ states("sensor.time") }}
## {{ states("sensor.date") }}
style: |
ha-card {
font-family: 'djb_get_digitalregular';
padding-top: 18px;
border: solid 2px var(--primary-color);
}
h1 {
text-align: center;
font-size: 6em;
margin-bottom: 0px;
}
h2 {
text-align: center;
}
type: markdown
Did you figure this out? I have an otf-file I want to use.
KTibow
(Kendell R)
August 9, 2020, 5:06pm
10
If you want to use a Google font, just do
If you want to use your own font, put them in /config/www/
, and then put this in /config/www/fonts.css
:
@font-face {
font-family: 'My Font';
font-style: normal;
font-weight: 400;
src: url(/local/myfont.ttf) format('ttf');
}
tom_l
August 9, 2020, 5:40pm
11
Thanks but that still does not seem to work.
- card_type: markdown
content: |
<br>
<b>
{{states("sensor.time")}}
</b>
style: |
ha-card {
--ha-card-background: 'rgba(0, 0, 0, 0)';
--ha-card-box-shadow: 'none';
font-size: 84px;
font-family: 'djb_get_digital';
text-align: center;
}
I have restarted and cleared my cache.
tom_l
August 9, 2020, 5:51pm
13
I can access both from my browser.
No change
From the css file? - no change
Could not see it in the list. Should I be adding a configuration / dashboard / resource?
KTibow
(Kendell R)
August 9, 2020, 5:53pm
14
Yes, you need to add /local/fonts.css
to your resources as a CSS file.
tom_l
August 9, 2020, 6:00pm
15
Added /local/fonts.css
to resources as a stylesheet.
Refreshed cache.
Still not loading according to the inspector/network tab.
KTibow
(Kendell R)
August 9, 2020, 6:02pm
16
Make sure to clear any selectors in the network tab and reload…
That’s odd though. You used the UI right?
tom_l
August 9, 2020, 6:03pm
17
KTibow:
You used the UI right?
To add the resource? Yes.
It was on all. I tried css and fonts neither contained anything.
KTibow
(Kendell R)
August 9, 2020, 6:06pm
18
Sounds like a Home Assistant problem then…
kdw2060
(Kris De Winter)
August 9, 2020, 6:32pm
20
yeah it’s a pain in the ass, your story sounds similar to mine. At one point i did manage to get the fonts loaded, don’t really remember what did the trick though, sorry.
Just one tip: use versioning on the resource url (like ?v=0.1
) in between restarts, then check in developer tools of the browser if the updated version has been loaded.