Created
October 21, 2020 02:23
-
-
Save michaellunzer/37f29462ee9a17f22978e672c59e440c to your computer and use it in GitHub Desktop.
ESPHome ePaper 2.7inch Display ESP8266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
esphome: | |
name: codecard3 | |
platform: ESP8266 | |
board: esp12e | |
# on_boot: | |
# - output.turn_off: onboard_led | |
wifi: | |
ssid: !secret wifi_ssid | |
password: !secret wifi_password | |
# Enable logging | |
logger: | |
# Enable Home Assistant API | |
api: | |
ota: | |
spi: | |
clk_pin: GPIO14 | |
mosi_pin: GPIO13 | |
# s= '@!"%()+,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz.' | |
# print([','.join(_) for _ in s]) | |
font: | |
- file: 'fonts/Google_Sans_Bold.ttf' | |
id: clock_font | |
size: 45 | |
glyphs: | |
['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0', | |
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', | |
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', | |
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f', | |
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | |
'u', 'v', 'w', 'x', 'y', 'z','å', 'ä', 'ö', '/'] | |
- file: 'fonts/Google_Sans_Medium.ttf' | |
id: temp_font | |
size: 32 | |
glyphs: | |
['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0', | |
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', | |
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', | |
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f', | |
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | |
'u', 'v', 'w', 'x', 'y', 'z','å', 'ä', 'ö', '/'] | |
- file: 'fonts/Google_Sans_Bold.ttf' | |
id: status_font | |
size: 18 | |
glyphs: | |
['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0', | |
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', | |
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', | |
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f', | |
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | |
'u', 'v', 'w', 'x', 'y', 'z', 'å', 'ä', 'ö', '/'] | |
- file: 'fonts/Google_Sans_Medium.ttf' | |
id: aqi_font | |
size: 18 | |
glyphs: | |
['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0', | |
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', | |
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', | |
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f', | |
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | |
'u', 'v', 'w', 'x', 'y', 'z', 'å', 'ä', 'ö', '/'] | |
- file: 'fonts/materialdesignicons-webfont.ttf' | |
id: icon_font | |
size: 32 | |
glyphs: [ | |
'', # mdi-account-heart | |
'', # mdi-thermometer | |
'', # mdi-fire-hydrant | |
"", # mdi-umbrella | |
"", # mdi-home-thermometer-outline | |
"", # mdi-home-thermometer | |
"", # mdi-air-filter | |
# Wifi | |
'', # mdi-wifi-strength-outline | |
'', # mdi-wifi-strength-1 | |
'', # mdi-wifi-strength-2 | |
'', # mdi-wifi-strength-3 | |
'', # mdi-wifi-strength-4 | |
# Weather | |
"", # mdi-weather-sunny | |
"", # mdi-weather-night | |
"", # mdi-weather-cloudy | |
"", # mdi-weather-pouring | |
"", # mdi-weather-snowy-rainy | |
"", # mdi-weather-snowy-heavy | |
"", # mdi-weather-windy-variant | |
"", # mdi-weather-fog | |
"", # mdi-weather-night-partly-cloudy | |
"", # mdi-weather-partly-cloudy | |
# Moon | |
"", # new_moon | |
"", # waxing_crecent | |
"", # first_quarter | |
"", # waxing_gibbous | |
"", # full_moon | |
"", # waning_gibbous | |
"", # last_quarter | |
"", # waning_crescent | |
# Sun | |
"", # mdi-weather-sunset-down | |
"", # mdi-weather-sunset-up | |
] | |
- file: 'fonts/materialdesignicons-webfont.ttf' | |
id: weather_font | |
size: 50 | |
glyphs: [ | |
'', # mdi-account-heart | |
'', # mdi-thermometer | |
'', # mdi-fire-hydrant | |
"", # mdi-umbrella | |
"", # mdi-home-thermometer-outline | |
"", # mdi-home-thermometer | |
"", # mdi-air-filter | |
# Wifi | |
'', # mdi-wifi-strength-outline | |
'', # mdi-wifi-strength-1 | |
'', # mdi-wifi-strength-2 | |
'', # mdi-wifi-strength-3 | |
'', # mdi-wifi-strength-4 | |
# Weather | |
"", # mdi-weather-sunny | |
"", # mdi-weather-night | |
"", # mdi-weather-cloudy | |
"", # mdi-weather-pouring | |
"", # mdi-weather-snowy-rainy | |
"", # mdi-weather-snowy-heavy | |
"", # mdi-weather-windy-variant | |
"", # mdi-weather-fog | |
"", # mdi-weather-night-partly-cloudy | |
"", # mdi-weather-partly-cloudy | |
# Moon | |
"", # new_moon | |
"", # waxing_crecent | |
"", # first_quarter | |
"", # waxing_gibbous | |
"", # full_moon | |
"", # waning_gibbous | |
"", # last_quarter | |
"", # waning_crescent | |
# Sun | |
"", # mdi-weather-sunset-down | |
"", # mdi-weather-sunset-up | |
] | |
- file: 'fonts/materialdesignicons-webfont.ttf' | |
id: current_weather_font | |
size: 80 | |
glyphs: [ | |
'', # mdi-account-heart | |
'', # mdi-thermometer | |
'', # mdi-fire-hydrant | |
"", # mdi-umbrella | |
"", # mdi-home-thermometer-outline | |
"", # mdi-home-thermometer | |
"", # mdi-air-filter | |
# Wifi | |
'', # mdi-wifi-strength-outline | |
'', # mdi-wifi-strength-1 | |
'', # mdi-wifi-strength-2 | |
'', # mdi-wifi-strength-3 | |
'', # mdi-wifi-strength-4 | |
# Weather | |
"", # mdi-weather-sunny | |
"", # mdi-weather-night | |
"", # mdi-weather-cloudy | |
"", # mdi-weather-pouring | |
"", # mdi-weather-snowy-rainy | |
"", # mdi-weather-snowy-heavy | |
"", # mdi-weather-windy-variant | |
"", # mdi-weather-fog | |
"", # mdi-weather-night-partly-cloudy | |
"", # mdi-weather-partly-cloudy | |
# Moon | |
"", # new_moon | |
"", # waxing_crecent | |
"", # first_quarter | |
"", # waxing_gibbous | |
"", # full_moon | |
"", # waning_gibbous | |
"", # last_quarter | |
"", # waning_crescent | |
# Sun | |
"", # mdi-weather-sunset-down | |
"", # mdi-weather-sunset-up | |
] | |
# 264 x 176 display | |
display: | |
- platform: waveshare_epaper | |
id: epaper | |
cs_pin: GPIO2 | |
busy_pin: GPIO5 | |
reset_pin: GPIO4 | |
dc_pin: GPIO0 | |
model: 2.70in | |
rotation: 270° | |
# full_update_every: 30 | |
# 264 x 176 display | |
update_interval: 3600s | |
lambda: | | |
int x, y; | |
ESP_LOGI("display", "Updating.."); | |
/* Print time in HH:MM format */ | |
it.strftime(0, -10, id(clock_font), TextAlign::TOP_LEFT, "%I:%M", id(current_time).now()); | |
/* Print AM/PM */ | |
it.strftime(120, 15, id(status_font), TextAlign::TOP_LEFT, "%P", id(current_time).now()); | |
it.strftime(65, 40, id(status_font), TextAlign::TOP_LEFT, "%b %e, %Y", id(current_time).now()); | |
// it.line(259, -10, 259, 200);it.line(261, 0, 261, 200);it.line(260, 0, 260, 200); | |
// it.line(0, 200, 259, 200);it.line(0, 201, 261, 201);it.line(0, 202, 260, 202); | |
/* | |
it.print(125, 120, id(temp_font), TextAlign::BASELINE_CENTER, "HELLO SUNSHINE!"); | |
it.print(125, 160, id(icon_font), TextAlign::BASELINE_CENTER, ""); | |
it.print(125, 182, id(temp_font), TextAlign::BASELINE_CENTER, "Lea & Emma"); // 400 - ((400 - 260)/2) | |
*/ | |
/* Moon icon - used to be y = 155, x = 230 */ | |
if(id(moon_icon).has_state()) { | |
y = 165, x = 20; | |
ESP_LOGI("Moon icon", "%s", id(moon_icon).state.c_str()); | |
it.printf(x, y, id(icon_font), TextAlign::BASELINE_CENTER, "%s", id(moon_icon).state.c_str()); | |
} | |
/* WiFi Signal Strenght x = 398, y = 298; */ | |
if(id(wifisignal).has_state()) { | |
x = 175, y = 30; | |
if (id(wifisignal).state >= -50) { | |
//Excellent | |
it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, ""); | |
ESP_LOGI("WiFi", "Exellent"); | |
} else if (id(wifisignal).state >= -60) { | |
//Good | |
it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, ""); | |
ESP_LOGI("WiFi", "Good"); | |
} else if (id(wifisignal).state >= -67) { | |
//Fair | |
it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, ""); | |
ESP_LOGI("WiFi", "Fair"); | |
} else if (id(wifisignal).state >= -70) { | |
//Weak | |
it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, ""); | |
ESP_LOGI("WiFi", "Weak"); | |
} else { | |
//Unlikely working signal | |
it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, ""); | |
ESP_LOGI("WiFi", "Unlikely"); | |
} | |
} | |
// Current weather | |
if(id(weather_forecast_today).has_state()) { | |
std::string str = id(weather_forecast_today).state; | |
ESP_LOGI("Weather", "%s", str.c_str()); | |
std::size_t current, previous = 0; | |
char delim = ';'; | |
current = str.find(delim); | |
int y = 100, x = 5; | |
for (int i=0; i<3; i++) { | |
if(i == 0) { | |
it.printf(x - 15, y, id(current_weather_font), | |
TextAlign::BASELINE_LEFT, | |
"%s", str.substr(previous, current - previous).c_str()); | |
} else if (i == 1) { | |
ESP_LOGD("weather","%dx%d %s", (i % 1 ? 270 : 320), x, | |
str.substr(previous, current - previous).c_str()); | |
/* it.printf(y, x, id(status_font), | |
TextAlign::TOP_LEFT, | |
"%s", str.substr(previous, current - previous).c_str()); | |
*/ | |
} else if (i == 2) { // Chance for rain | |
it.printf(x, y + 2, id(icon_font), TextAlign::TOP_LEFT, ""); // Umbrella | |
it.printf(x + 30, y + 10, id(status_font), | |
TextAlign::TOP_LEFT, | |
"%s%%", str.substr(previous, current - previous).c_str()); | |
} | |
// y += 100; | |
previous = current + 1; | |
current = str.find(delim, previous); | |
} | |
} | |
// Print inside temperature (from homeassistant sensor) | |
y = 135, x = 100; | |
if (id(inside_temperature).has_state()) { | |
it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, ""); | |
it.printf(x, y + 4, id(temp_font), TextAlign::BOTTOM_LEFT , "%5.1f°", id(inside_temperature).state); | |
} | |
// Print outside temperature (from homeassistant sensor) | |
if (id(outside_temperature).has_state()) { | |
it.print(x, y + 4, id(icon_font), TextAlign::TOP_RIGHT, ""); | |
it.printf(x, y, id(temp_font), TextAlign::TOP_LEFT, "%5.1f°", id(outside_temperature).state); | |
} | |
// Print sniffer0 air quality index sensor (from homeassistant sensor) | |
if (id(sniffer0_aqi).has_state()) { | |
x = 91, y = 60; | |
it.print(x + 10, y + 4, id(icon_font), TextAlign::TOP_RIGHT, ""); | |
it.printf(x - 4, y, id(temp_font), TextAlign::TOP_LEFT, "%5.0f", id(sniffer0_aqi).state); | |
it.print(x + 87, y + 16, id(aqi_font), TextAlign::TOP_RIGHT, "AQI"); | |
} | |
/*// Print consumer | |
if (id(top_consumer).has_state()) { | |
it.printf(0, 295, id(status_font), TextAlign::BOTTOM_LEFT , "Total: %.0f W, %s W", id(sparsnas).state, id(top_consumer).state.c_str()); | |
} | |
*/ | |
it.line(180, 0, 180, 176); | |
it.line(0, 103, 180, 103); | |
// std::string str = "mon:cloud:12.1:30%:tue:rain:10.2:40%:wed:sunny:18.0:0%:thu:snow:-12.2:10%"; | |
// Mon;;65°/53°;12%;Tue;;70°/56°;7%;Wed;;73°/55°;2%;Thu;;73°/55°;1% | |
if(id(weather_forecast).has_state()) { | |
std::string str = id(weather_forecast).state; | |
ESP_LOGI("Weather", "%s", str.c_str()); | |
std::size_t current, previous = 0; | |
char delim = ';'; | |
current = str.find(delim); | |
int x = 240, y = 0; | |
// changed from x = 340, y = 4 | |
for (int i=0; i<4; i++) { | |
ESP_LOGI("t", "%d", i); | |
for (int j=0; j<4; j++) { | |
if(j == 1) { // Weather icon. | |
it.printf(x - 65, y + 25, id(weather_font), | |
TextAlign::BASELINE_LEFT, | |
"%s", str.substr(previous, current - previous).c_str()); | |
} else { | |
ESP_LOGD("weather","%dx%d %s", (j % 1 ? 270 : 320), x, | |
str.substr(previous, current - previous).c_str()); | |
it.printf((j == 0 ? x - 15 : 390), y, | |
id(status_font), | |
(j == 0 ? TextAlign::TOP_LEFT : TextAlign::TOP_RIGHT), | |
"%s", str.substr(previous, current - previous).c_str()); | |
y += 16; | |
} | |
previous = current + 1; | |
current = str.find(delim, previous); | |
} | |
y += 2; | |
} | |
} | |
# output: | |
# - platform: gpio | |
# id: onboard_led | |
# pin: | |
# number: 2 | |
# inverted: False | |
# light: | |
# - platform: binary | |
# name: "Onboard LED" | |
# output: onboard_led | |
time: | |
- platform: homeassistant | |
id: current_time | |
timezone: America/Los_Angeles | |
on_time: | |
# Every 1 minutes | |
- seconds: 0 | |
then: | |
- component.update: epaper | |
sensor: | |
- platform: homeassistant | |
id: inside_temperature | |
entity_id: sensor.sn1_temperature | |
internal: true | |
- platform: homeassistant | |
id: sniffer0_aqi | |
entity_id: sensor.sniffer0_pm_2_5_aqi | |
internal: true | |
- platform: homeassistant | |
id: outside_temperature | |
entity_id: sensor.openweathermap_forecast_temperature | |
internal: true | |
# - platform: homeassistant | |
# entity_id: sensor.sparsnas_energy_consumption_momentary | |
# id: sparsnas | |
# internal: true | |
- platform: homeassistant | |
entity_id: sensor.dark_sky_precip_probability | |
id: precip_probability | |
internal: true | |
- platform: wifi_signal | |
name: "WiFi Signal Sensor" | |
id: wifisignal | |
update_interval: 60s | |
text_sensor: | |
# - platform: homeassistant | |
# id: top_consumer | |
# entity_id: sensor.iotawatt_top_consumer | |
# internal: true | |
- platform: homeassistant | |
name: forecast | |
id: weather_forecast | |
entity_id: sensor.forecast | |
internal: true | |
- platform: homeassistant | |
name: forecast | |
id: weather_forecast_today | |
entity_id: sensor.forecast_today | |
internal: true | |
- platform: homeassistant | |
id: moon_icon | |
entity_id: sensor.moon_tpl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment