Add daily e-paper quote rotation
This commit is contained in:
@@ -221,6 +221,11 @@ text_sensor:
|
||||
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:
|
||||
@@ -1258,12 +1263,27 @@ display:
|
||||
}
|
||||
}
|
||||
|
||||
/* RIGHT BOTTOM: quote placeholder, intentionally inverted */
|
||||
/* RIGHT BOTTOM: daily quote selected by Home Assistant */
|
||||
it.filled_rectangle(375, 220, 255, 130, COLOR_ON);
|
||||
it.print(502, 246, id(sensor_unit), COLOR_OFF, TextAlign::TOP_CENTER, "Es ist nie zu spät,");
|
||||
it.print(502, 271, id(sensor_unit), COLOR_OFF, TextAlign::TOP_CENTER, "die Erwartungen zu");
|
||||
it.print(502, 296, id(sensor_unit), COLOR_OFF, TextAlign::TOP_CENTER, "senken.");
|
||||
it.print(502, 326, id(footer_font), COLOR_OFF, TextAlign::TOP_CENTER, "Zitatquelle folgt");
|
||||
std::string quote = "Zitat wird geladen.";
|
||||
if (id(demotivational_quote).has_state() && !id(demotivational_quote).state.empty()) {
|
||||
quote = id(demotivational_quote).state;
|
||||
}
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user