This is my code from my ESPhome yaml.
First I only select icons that I will use, this to save on memory (and it’s more easy to copy/paste when needed). All those squares are just copy/paste from icons when font is opened on my computer.
- file: 'fonts/materialdesignicons-webfont.ttf'
id: icon_font_20
size: 20
glyphs: [
"", # mdi-thermometer
"", # mdi-water-percent
"ﴟ" # mdi-air-filter
]
- file: 'fonts/materialdesignicons-webfont.ttf'
id: icon_font_25
size: 25
glyphs: [
'', # mdi-thermometer
'', # mdi-water-percent
"ﴟ", # mdi-air-filter
# Alert
"", # mdi-alert-outline
# Weather
"", # mdi-weather-sunny
"", # mdi-weather-night
"", # mdi-weather-cloudy
"", # mdi-weather-pouring
"", # mdi-weather-snowy-rainy
"s", # mdi-weather-snowy-heavy
"", # mdi-weather-windy-variant
"", # mdi-weather-fog
"", # mdi-weather-partly-cloudy
"n" # mdi-weather-night-partly-cloudy
]
- file: 'fonts/materialdesignicons-webfont.ttf'
id: icon_font_30
size: 30
glyphs: [
"", # mdi-thermometer
"", # mdi-water-percent
"ﵜ", # mdi-home-floor-1
"ﶮ" # mdi-home-floor-0
]
- file: 'fonts/materialdesignicons-webfont.ttf'
id: icon_font_35
size: 35
glyphs: [
'', # mdi-thermometer
'' # mdi-water-percent
]
- file: 'fonts/materialdesignicons-webfont.ttf'
id: icon_font_40
size: 40
glyphs: [
'', # mdi-thermometer
'' # mdi-water-percent
]
Then in lambda:
it.printf(10, 84, id(icon_font_35), TextAlign::BASELINE_LEFT, "");
it.printf(120, 80, id(icon_font_40), TextAlign::BASELINE_LEFT, "");
if (id(weather_icon).has_state()) {
std::map<std::string, std::string> weather_state {
{ "clear-day", "" }, // mdi:weather-sunny
{ "clear-night", "" }, // mdi:weather-night
{ "cloudy", "" }, // mdi:weather-cloudy
{ "rain", "" }, // mdi:weather-pouring
{ "sleet", "" }, // mdi:weather-snowy-rainy
{ "snow", "s" }, // mdi:weather-snowy-heavy
{ "wind", "" }, // mdi:weather-windy-variant
{ "fog", "" }, // mdi:weather-fog
{ "partly-cloudy-day", "" }, // mdi:weather-partly-cloudy
{ "partly-cloudy-night", "n" } // mdi:weather-night-partly-cloudy
};
if (time < 1900) {
it.printf(20, 320, id(icon_font_25), TextAlign::BASELINE_LEFT, weather_state[id(weather_icon).state.c_str()].c_str());
} else {
it.printf(20, 320, id(icon_font_25), TextAlign::BASELINE_LEFT, weather_state[id(weather_icon_1).state.c_str()].c_str());
}
}
where weather_icon is Dark Sky icon for today and weather_icon_1 for tomorrow:
text_sensor:
- platform: homeassistant
name: "Today Weather Icon"
entity_id: sensor.dark_sky_icon_0d
id: weather_icon
internal: true
- platform: homeassistant
name: "Tomorrow Weather Icon"
entity_id: sensor.dark_sky_icon_1d
id: weather_icon_1
internal: true