Merge branch 'epaperframe-gpt5.6'
This commit is contained in:
+182
-182
@@ -15,7 +15,7 @@ esphome:
|
||||
priority: -10
|
||||
then:
|
||||
- delay: 10s
|
||||
- display.page.show: environment # temporary for power page dev
|
||||
- display.page.show: calendar # temporary for power page dev
|
||||
- component.update: epaper
|
||||
|
||||
esp32:
|
||||
@@ -46,6 +46,9 @@ api:
|
||||
encryption:
|
||||
key: !secret apikey
|
||||
|
||||
# Include ArduinoJson support for the compact calendar event feed.
|
||||
json:
|
||||
|
||||
ota:
|
||||
platform: esphome
|
||||
password: !secret ota
|
||||
@@ -183,29 +186,7 @@ sensor:
|
||||
entity_id: sensor.serverroom_serveraum_temperatur
|
||||
id: temp_serverroom
|
||||
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.netzleistung
|
||||
id: power_total
|
||||
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.serverraum_power
|
||||
id: power_serverroom
|
||||
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.schreibtisch_power
|
||||
id: desk_livingroom
|
||||
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.wohnzimmer_heimkino_power
|
||||
id: media_livingroom
|
||||
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.schlafzimmer_bett_power
|
||||
id: bedlight_sleepingroom
|
||||
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.schlafzimmer_heimkino_power
|
||||
id: media_sleepingroom
|
||||
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.radioaktive_strahlungsleistung
|
||||
@@ -234,12 +215,18 @@ text_sensor:
|
||||
entity_id: weather.zuhause
|
||||
id: weather
|
||||
|
||||
graph:
|
||||
- id: line_power_graph
|
||||
sensor: power_total
|
||||
duration: 2h
|
||||
width: 235
|
||||
height: 100
|
||||
# Display-ready JSON produced by the Home Assistant calendar template sensor.
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.epaper_kalenderdaten
|
||||
attribute: entries
|
||||
id: calendar_entries
|
||||
|
||||
# Home Assistant selects one quote per day from its local quote library.
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.epaper_demotivationszitat
|
||||
id: demotivational_quote
|
||||
|
||||
|
||||
|
||||
time:
|
||||
- platform: homeassistant
|
||||
@@ -269,6 +256,12 @@ font:
|
||||
id: roboto_med_30
|
||||
size: 30
|
||||
|
||||
# Small, digits-only font used to emphasize the current date in the month grid.
|
||||
- file: "fonts/Roboto-Bold.ttf"
|
||||
id: calendar_day_bold
|
||||
size: 15
|
||||
glyphs: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
|
||||
|
||||
- file: "fonts/Roboto-Regular.ttf"
|
||||
id: footer_font
|
||||
size: 15
|
||||
@@ -1110,184 +1103,191 @@ display:
|
||||
ESP_LOGI("WiFi", "Unlikely");
|
||||
}
|
||||
}
|
||||
|
||||
- id: calendar
|
||||
lambda: |-
|
||||
/* Fetch today and tomorrow dates */
|
||||
auto now = id(homeassistant_time).now();
|
||||
int today_day = now.day_of_month;
|
||||
int today_month = now.month;
|
||||
int today_wday = now.day_of_week; // 0=Sunday .. 6=Saturday
|
||||
const char* weekdays[] = {"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"};
|
||||
const char* today_weekday_str = weekdays[today_wday];
|
||||
int today_year = now.year;
|
||||
const char *months[] = {"Januar", "Februar", "März", "April", "Mai", "Juni",
|
||||
"Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
const char *weekdays[] = {"Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"};
|
||||
|
||||
/* Tomorrow's date */
|
||||
int tomorrow_day = today_day + 1;
|
||||
int tomorrow_month = today_month;
|
||||
int tomorrow_wday = (today_wday + 1) % 7;
|
||||
const char* tomorrow_weekday_str = weekdays[tomorrow_wday];
|
||||
int tomorrow_year = today_year;
|
||||
const int year = now.year;
|
||||
const int month = now.month;
|
||||
const int today = now.day_of_month;
|
||||
|
||||
/* C1024 logo */
|
||||
it.image(10, 37, id(c1024_logo));
|
||||
auto days_in_month = [](int calendar_year, int calendar_month) {
|
||||
const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
if (calendar_month == 2) {
|
||||
return (calendar_year % 4 == 0 && (calendar_year % 100 != 0 || calendar_year % 400 == 0)) ? 29 : 28;
|
||||
}
|
||||
return days[calendar_month - 1];
|
||||
};
|
||||
auto weekday_monday = [](int calendar_year, int calendar_month, int day) {
|
||||
const int offsets[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
|
||||
calendar_year -= calendar_month < 3;
|
||||
const int sunday_first = (calendar_year + calendar_year / 4 - calendar_year / 100 +
|
||||
calendar_year / 400 + offsets[calendar_month - 1] + day) % 7;
|
||||
return (sunday_first + 6) % 7;
|
||||
};
|
||||
auto iso_weeks_in_year = [&weekday_monday](int calendar_year) {
|
||||
// 28 December is always in the final ISO week of its year.
|
||||
const int day_of_year = 362 + ((calendar_year % 4 == 0 &&
|
||||
(calendar_year % 100 != 0 || calendar_year % 400 == 0)) ? 1 : 0);
|
||||
const int weekday = weekday_monday(calendar_year, 12, 28) + 1;
|
||||
return (day_of_year - weekday + 10) / 7;
|
||||
};
|
||||
auto iso_week = [&weekday_monday, &days_in_month, &iso_weeks_in_year](int calendar_year, int calendar_month, int day) {
|
||||
int day_of_year = day;
|
||||
for (int current_month = 1; current_month < calendar_month; current_month++) {
|
||||
day_of_year += days_in_month(calendar_year, current_month);
|
||||
}
|
||||
const int weekday = weekday_monday(calendar_year, calendar_month, day) + 1;
|
||||
int week = (day_of_year - weekday + 10) / 7;
|
||||
if (week < 1) return iso_weeks_in_year(calendar_year - 1);
|
||||
if (week > iso_weeks_in_year(calendar_year)) return 1;
|
||||
return week;
|
||||
};
|
||||
|
||||
/* ── LEFT PANE: Today ── */
|
||||
int leftX = 0;
|
||||
int leftY = 85; // start below header row
|
||||
/* LEFT PANE: agenda */
|
||||
it.image(10, 10, id(c1024_logo));
|
||||
it.print(226, 38, id(roboto_med_30), TextAlign::BASELINE_CENTER, "TERMINE");
|
||||
it.line(10, 55, 355, 55);
|
||||
it.line(365, 10, 365, 352);
|
||||
|
||||
it.print(10 + leftX, 10 + leftY, id(sensor_unit), "Heute");
|
||||
it.filled_rectangle(64 + leftX, 21 + leftY, 370, 3);
|
||||
JsonDocument calendar_doc;
|
||||
const DeserializationError calendar_error = deserializeJson(calendar_doc, id(calendar_entries).state.c_str());
|
||||
JsonArray calendar_days = calendar_doc.as<JsonArray>();
|
||||
int agenda_y = 72;
|
||||
bool has_events = false;
|
||||
bool has_hidden_events = false;
|
||||
|
||||
/* Today's date strip */
|
||||
it.printf(50 + leftX, 50 + leftY, id(big_sensor_font), "%d", today_day);
|
||||
it.printf(130 + leftX, 45 + leftY, id(sub_sensor_font), "%s.", today_weekday_str);
|
||||
it.printf(160 + leftX, 45 + leftY, id(sensor_unit), "%02d.%04d.", today_month, today_year);
|
||||
if (calendar_error || calendar_days.isNull()) {
|
||||
it.print(18, agenda_y, id(sensor_unit), TextAlign::TOP_LEFT, "Kalenderdaten werden geladen ...");
|
||||
} else if (calendar_days.size() == 0) {
|
||||
it.print(18, agenda_y, id(sensor_unit), TextAlign::TOP_LEFT, "Keine Termine in den nächsten Tagen.");
|
||||
} else {
|
||||
for (JsonVariant day_variant : calendar_days) {
|
||||
JsonObject day = day_variant.as<JsonObject>();
|
||||
JsonArray events = day["events"].as<JsonArray>();
|
||||
if (events.isNull() || events.size() == 0) continue;
|
||||
if (agenda_y + 38 > 345) {
|
||||
has_hidden_events = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Event placeholder row (top) */
|
||||
int eventOffsetY = 90;
|
||||
it.print(10 + leftX, 50 + leftY + eventOffsetY, id(mdi_med), TextAlign::BASELINE_LEFT, "");
|
||||
it.print(40 + leftX, 50 + leftY + eventOffsetY, id(sub_sensor_font), "Eintrag 1");
|
||||
const int group_y = agenda_y;
|
||||
int event_y = group_y;
|
||||
const int day_number = day["day"] | 0;
|
||||
const char *weekday = day["weekday"] | "";
|
||||
it.printf(30, group_y, id(sub_sensor_font), TextAlign::TOP_CENTER, "%d", day_number);
|
||||
it.printf(30, group_y + 28, id(footer_font), TextAlign::TOP_CENTER, "%s", weekday);
|
||||
|
||||
/* Event placeholder row (bottom) */
|
||||
it.print(10 + leftX, 85 + leftY + eventOffsetY, id(mdi_med), TextAlign::BASELINE_LEFT, "");
|
||||
it.print(40 + leftX, 85 + leftY + eventOffsetY, id(sub_sensor_font), "Eintrag 2");
|
||||
for (JsonVariant event_variant : events) {
|
||||
if (event_y + 33 > 345) {
|
||||
has_hidden_events = true;
|
||||
break;
|
||||
}
|
||||
JsonObject event = event_variant.as<JsonObject>();
|
||||
const char *title = event["title"] | "Ohne Titel";
|
||||
const char *time = event["time"] | "";
|
||||
const char *end_time = event["end"] | "";
|
||||
const char *meta = event["meta"] | "";
|
||||
it.printf(72, event_y, id(sensor_unit), TextAlign::TOP_LEFT, "%s", title);
|
||||
it.printf(350, event_y, id(sensor_unit), TextAlign::TOP_RIGHT, "%s", time);
|
||||
it.printf(72, event_y + 20, id(footer_font), TextAlign::TOP_LEFT, "%s", meta);
|
||||
if (end_time[0] != '\0') {
|
||||
it.printf(350, event_y + 20, id(footer_font), TextAlign::TOP_RIGHT, "%s", end_time);
|
||||
}
|
||||
event_y += 35;
|
||||
has_events = true;
|
||||
}
|
||||
|
||||
/* ── RIGHT PANE: Tomorrow ── */
|
||||
int rightX = 390;
|
||||
int rightY = 85;
|
||||
|
||||
it.print(10 + rightX, 10 + rightY, id(sensor_unit), "Morgen");
|
||||
it.filled_rectangle(64 + rightX, 21 + rightY, 370, 3);
|
||||
|
||||
/* Date strip */
|
||||
it.printf(50 + rightX, 50 + rightY, id(big_sensor_font), "%d", tomorrow_day);
|
||||
it.printf(130 + rightX, 45 + rightY, id(sub_sensor_font), "%s.", tomorrow_weekday_str);
|
||||
it.printf(160 + rightX, 45 + rightY, id(sensor_unit), "%02d.%04d.", tomorrow_month, tomorrow_year);
|
||||
|
||||
/* Event placeholder row (top) */
|
||||
it.print(10 + rightX, 50 + rightY + eventOffsetY, id(mdi_med), TextAlign::BASELINE_LEFT, "");
|
||||
it.print(40 + rightX, 50 + rightY + eventOffsetY, id(sub_sensor_font), "Eintrag 1");
|
||||
|
||||
/* Event placeholder row (bottom) */
|
||||
it.print(10 + rightX, 85 + rightY + eventOffsetY, id(mdi_med), TextAlign::BASELINE_LEFT, "");
|
||||
it.print(40 + rightX, 85 + rightY + eventOffsetY, id(sub_sensor_font), "Eintrag 2");
|
||||
|
||||
/* FOOTER */
|
||||
it.strftime(614, 380, id(footer_font), TextAlign::BASELINE_RIGHT, "Aktualisiert um %d.%m.%Y %H:%M", id(homeassistant_time).now());
|
||||
|
||||
/* WiFi Signal strength */
|
||||
if(id(wifisignal).has_state()) {
|
||||
int x = 630;
|
||||
int y = 384;
|
||||
if (id(wifisignal).state >= -50) {
|
||||
it.print(x, y, id(mdi_wifi), TextAlign::BASELINE_CENTER, "");
|
||||
} else if (id(wifisignal).state >= -60) {
|
||||
it.print(x, y, id(mdi_wifi), TextAlign::BASELINE_CENTER, "");
|
||||
} else if (id(wifisignal).state >= -75) {
|
||||
it.print(x, y, id(mdi_wifi), TextAlign::BASELINE_CENTER, "");
|
||||
} else if (id(wifisignal).state >= -100) {
|
||||
it.print(x, y, id(mdi_wifi), TextAlign::BASELINE_CENTER, "");
|
||||
} else {
|
||||
it.print(x, y, id(mdi_wifi), TextAlign::BASELINE_CENTER, "");
|
||||
int group_bottom = event_y;
|
||||
if (group_bottom < group_y + 36) group_bottom = group_y + 36;
|
||||
it.line(58, group_y, 58, group_bottom);
|
||||
agenda_y = group_bottom + 5;
|
||||
if (has_hidden_events) break;
|
||||
}
|
||||
}
|
||||
|
||||
- id: power
|
||||
lambda: |-
|
||||
|
||||
float total_power = id(power_total).state;
|
||||
float serverroom_power = id(power_serverroom).state;
|
||||
float livingroom_desk = id(desk_livingroom).state;
|
||||
float livingroom_media = id(media_livingroom).state;
|
||||
float sleepingroom = id(media_sleepingroom).state + id(bedlight_sleepingroom).state;
|
||||
int offsetX = 0;
|
||||
int offsetY = 0;
|
||||
|
||||
/* BASEMENT */
|
||||
it.print(10, 10, id(sensor_unit), "Keller");
|
||||
/*
|
||||
Draw the outline of a rectangle with the top left at [86,21],
|
||||
a width of 297 and a height of 3
|
||||
*/
|
||||
it.filled_rectangle(76, 21, 307, 3);
|
||||
|
||||
/* C1024 logo */
|
||||
it.image(10 , 37, id(c1024_logo));
|
||||
|
||||
/* Livingroom */
|
||||
offsetY = 127;
|
||||
it.print(10, 10 + offsetY, id(sensor_unit), "Wohnzimmer");
|
||||
it.filled_rectangle(136, 21 + offsetY, 247, 3);
|
||||
|
||||
it.print(375, 75 + offsetY, id(mdi_small), TextAlign::BASELINE_CENTER, ""); // power-plug
|
||||
it.print(375, 115 + offsetY, id(mdi_small), TextAlign::BASELINE_CENTER, ""); // power-plug
|
||||
|
||||
it.print(20, 75 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_LEFT, "Schreibtisch");
|
||||
if(livingroom_desk >= 0) {
|
||||
it.printf(357, 75 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, "%2.1f W", livingroom_desk);
|
||||
}
|
||||
else {
|
||||
it.print(357, 75 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, " - W");
|
||||
if (!has_events && !calendar_error && !calendar_days.isNull() && calendar_days.size() > 0) {
|
||||
it.print(18, 72, id(sensor_unit), TextAlign::TOP_LEFT, "Keine Termine im sichtbaren Bereich.");
|
||||
}
|
||||
|
||||
it.print(20, 115 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_LEFT, "Heimkino");
|
||||
if(livingroom_media >= 0) {
|
||||
it.printf(357, 115 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, "%2.1f W", livingroom_media);
|
||||
}
|
||||
else {
|
||||
it.print(357, 115 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, " - W");
|
||||
|
||||
/* RIGHT TOP: month view, Monday-first with ISO week numbers */
|
||||
char month_title[24];
|
||||
snprintf(month_title, sizeof(month_title), "%s %d", months[month - 1], year);
|
||||
it.printf(502, 18, id(sensor_unit), TextAlign::TOP_CENTER, "%s", month_title);
|
||||
it.print(384, 47, id(footer_font), TextAlign::TOP_CENTER, "KW");
|
||||
for (int column = 0; column < 7; column++) {
|
||||
it.printf(415 + column * 30, 47, id(footer_font), TextAlign::TOP_CENTER, "%s", weekdays[column]);
|
||||
}
|
||||
|
||||
/* Sleepingroom */
|
||||
offsetY = 247;
|
||||
it.print(10, 10 + offsetY, id(sensor_unit), "Schlafzimmer");
|
||||
it.filled_rectangle(144, 21 + offsetY, 239, 3);
|
||||
const int first_weekday = weekday_monday(year, month, 1);
|
||||
const int month_days = days_in_month(year, month);
|
||||
const int calendar_rows = (first_weekday + month_days + 6) / 7;
|
||||
for (int row = 0; row < calendar_rows; row++) {
|
||||
const int monday_day = 1 - first_weekday + row * 7;
|
||||
int week_year = year;
|
||||
int week_month = month;
|
||||
int week_day = monday_day;
|
||||
if (week_day < 1) {
|
||||
week_month--;
|
||||
if (week_month == 0) {
|
||||
week_month = 12;
|
||||
week_year--;
|
||||
}
|
||||
week_day += days_in_month(week_year, week_month);
|
||||
} else if (week_day > month_days) {
|
||||
week_day -= month_days;
|
||||
week_month++;
|
||||
if (week_month == 13) {
|
||||
week_month = 1;
|
||||
week_year++;
|
||||
}
|
||||
}
|
||||
const int cell_y = 69 + row * 23;
|
||||
it.printf(384, cell_y, id(footer_font), TextAlign::TOP_CENTER, "%02d", iso_week(week_year, week_month, week_day));
|
||||
|
||||
it.print(375, 115 + offsetY, id(mdi_small), TextAlign::BASELINE_CENTER, ""); // power-plug
|
||||
|
||||
// it.print(20, 115 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_LEFT, "Heimkino");
|
||||
if(sleepingroom >= 0) {
|
||||
it.printf(357, 115 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, "%2.1f W", sleepingroom);
|
||||
}
|
||||
else {
|
||||
it.print(357, 115 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, " - W");
|
||||
for (int column = 0; column < 7; column++) {
|
||||
const int day = row * 7 + column - first_weekday + 1;
|
||||
if (day < 1 || day > month_days) continue;
|
||||
const int cell_x = 415 + column * 30;
|
||||
if (day == today) {
|
||||
it.filled_rectangle(cell_x - 12, cell_y - 2, 25, 18, COLOR_ON);
|
||||
it.printf(cell_x, cell_y, id(calendar_day_bold), COLOR_OFF, TextAlign::TOP_CENTER, "%d", day);
|
||||
} else {
|
||||
it.printf(cell_x, cell_y, id(footer_font), TextAlign::TOP_CENTER, "%d", day);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* LINEPOWER */
|
||||
offsetX = 390;
|
||||
offsetY = 65;
|
||||
it.print(10 + offsetX, 10, id(sensor_unit), "Gesamt");
|
||||
it.filled_rectangle(90 + offsetX, 21, 155, 3);
|
||||
|
||||
it.print(227 + offsetX, 20 + offsetY, id(mdi_small), TextAlign::BASELINE_CENTER, ""); // transmission-tower
|
||||
|
||||
if(total_power >= 0) {
|
||||
it.printf(207 + offsetX, 20 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, "W");
|
||||
it.printf(170 + offsetX, 20 + offsetY, id(big_sensor_font), TextAlign::BASELINE_RIGHT, "%2.1f", total_power);
|
||||
/* RIGHT BOTTOM: daily quote selected by Home Assistant */
|
||||
it.filled_rectangle(375, 220, 255, 130, COLOR_ON);
|
||||
std::string quote = "Zitat wird geladen.";
|
||||
if (id(demotivational_quote).has_state() && !id(demotivational_quote).state.empty()) {
|
||||
quote = id(demotivational_quote).state;
|
||||
}
|
||||
else {
|
||||
it.print(207 + offsetX, 20 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, " - W");
|
||||
}
|
||||
|
||||
it.graph(10 + offsetX, 30 + offsetY, id(line_power_graph));
|
||||
|
||||
/* Serverroom */
|
||||
offsetY = 247;
|
||||
it.print(10 + offsetX, 10 + offsetY, id(sensor_unit), "Serverraum");
|
||||
it.filled_rectangle(125 + offsetX, 21 + offsetY, 110, 3);
|
||||
|
||||
it.print(227 + offsetX, 110 + offsetY, id(mdi_small), TextAlign::BASELINE_CENTER, ""); // power-plug
|
||||
|
||||
if(serverroom_power >= 0) {
|
||||
it.printf(207 + offsetX, 110 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, "W");
|
||||
it.printf(170 + offsetX, 110 + offsetY, id(big_sensor_font), TextAlign::BASELINE_RIGHT, "%2.1f", serverroom_power);
|
||||
}
|
||||
else {
|
||||
it.print(207 + offsetX, 110 + offsetY, id(sub_sensor_font), TextAlign::BASELINE_RIGHT, " - W");
|
||||
const size_t max_quote_characters = 27;
|
||||
size_t quote_start = 0;
|
||||
for (int line = 0; line < 4 && quote_start < quote.length(); line++) {
|
||||
size_t quote_end = quote_start + max_quote_characters;
|
||||
if (quote_end < quote.length()) {
|
||||
const size_t word_break = quote.rfind(' ', quote_end);
|
||||
if (word_break != std::string::npos && word_break > quote_start) quote_end = word_break;
|
||||
} else {
|
||||
quote_end = quote.length();
|
||||
}
|
||||
const std::string quote_line = quote.substr(quote_start, quote_end - quote_start);
|
||||
it.printf(502, 234 + line * 24, id(sensor_unit), COLOR_OFF, TextAlign::TOP_CENTER, "%s", quote_line.c_str());
|
||||
quote_start = quote_end;
|
||||
while (quote_start < quote.length() && quote[quote_start] == ' ') quote_start++;
|
||||
}
|
||||
|
||||
/* FOOTER */
|
||||
it.strftime(614, 380, id(footer_font), TextAlign::BASELINE_RIGHT , "Aktualisiert um %d.%m.%Y %H:%M", id(homeassistant_time).now());
|
||||
it.strftime(614, 380, id(footer_font), TextAlign::BASELINE_RIGHT,
|
||||
"Aktualisiert um %d.%m.%Y %H:%M", now);
|
||||
|
||||
/* WiFi Signal strength */
|
||||
if(id(wifisignal).has_state()) {
|
||||
|
||||
Reference in New Issue
Block a user