From 250bfa94bd61139089d55cedec1bd309eb6d01fb Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sat, 11 Jul 2026 22:58:23 +0200 Subject: [PATCH] Add daily e-paper quote rotation --- automations.yaml | 19 +++++++++++++++++++ configuration.yaml | 3 +++ esphome/epaperframe.yaml | 30 +++++++++++++++++++++++++----- input_select.yaml | 40 ++++++++++++++++++++++++++++++++++++++++ template.yaml | 4 ++++ 5 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 input_select.yaml diff --git a/automations.yaml b/automations.yaml index 02c9895..6d6f99b 100644 --- a/automations.yaml +++ b/automations.yaml @@ -1438,3 +1438,22 @@ device_id: 6d1be741876624a70ab5b01b54c6fd6f entity_id: 621e4377a089b7f5d92c7c9f2cc171a1 domain: switch + +- id: epaper_daily_demotivational_quote + alias: Epaper tägliches Demotivationszitat + description: Wählt täglich ein festes Zitat aus der lokalen Zitatbibliothek aus. + triggers: + - trigger: homeassistant + event: start + - trigger: time + at: "00:00:00" + conditions: [] + actions: + - action: input_select.select_option + target: + entity_id: input_select.epaper_demotivationszitat + data: + option: >- + {% set quotes = state_attr('input_select.epaper_demotivationszitat', 'options') %} + {{ quotes[(now().strftime('%j') | int - 1) % (quotes | count)] }} + mode: single diff --git a/configuration.yaml b/configuration.yaml index a1e04cc..1506ed9 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -38,6 +38,9 @@ mqtt_statestream: !include mqtt_statestream.yaml # Calendar data is normalised in a sandboxed script before ESPHome receives it. python_script: +# Home Assistant-managed e-paper quote library +input_select: !include input_select.yaml + # Template sensors template: !include template.yaml diff --git a/esphome/epaperframe.yaml b/esphome/epaperframe.yaml index 40bea55..c1fbbfd 100644 --- a/esphome/epaperframe.yaml +++ b/esphome/epaperframe.yaml @@ -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, diff --git a/input_select.yaml b/input_select.yaml new file mode 100644 index 0000000..9852ea0 --- /dev/null +++ b/input_select.yaml @@ -0,0 +1,40 @@ +epaper_demotivationszitat: + name: Epaper Demotivationszitat + icon: mdi:emoticon-sad-outline + options: + - "Erwarte nichts. Dann kann dich auch wenig enttäuschen." + - "Du musst nicht scheitern. Es reicht, es nie zu versuchen." + - "Der Weg ist das Ziel. Leider führt er im Kreis." + - "Auch ein Rückschritt ist Bewegung. Nur eben rückwärts." + - "Nicht jeder Tag muss gut sein. Dieser hier zum Beispiel nicht." + - "Dein Potenzial ist beeindruckend. Seine Nutzung bleibt optional." + - "Morgen wird alles besser. Wahrscheinlich aber auch nicht." + - "Motivation ist vergänglich. Frust ist zuverlässig." + - "Man kann nicht alles haben. Nicht einmal gute Laune." + - "Wenn Plan A scheitert, war Plan B vermutlich auch keine Hilfe." + - "Es ist nie zu spät, die Erwartungen zu senken." + - "Du bist nicht zu spät. Die anderen sind nur früher gescheitert." + - "Das wird schon. Nur eben nicht gut." + - "Ziele sind wichtig. Besonders wenn man sie verfehlt." + - "Die Konkurrenz schläft nicht. Du darfst trotzdem weitermachen." + - "Du gibst dein Bestes. Das erklärt einiges." + - "Jeder Fehler ist eine Lektion. Du bist bald Experte." + - "Heute ist ein neuer Tag. Die Probleme sind dieselben." + - "Erfolg braucht Geduld. Enttäuschung ist sofort verfügbar." + - "Ein kleiner Schritt für dich. Ein kaum bemerkbarer für alle anderen." + - "Wer früh aufgibt, hat länger frei." + - "Es gibt keine dummen Fragen. Nur ungünstige Zeitpunkte." + - "Deine Komfortzone vermisst dich nicht." + - "Manchmal gewinnt man. Meistens lernt man daraus." + - "Der erste Schritt ist der schwerste. Die anderen sind nur länger." + - "Arbeite hart. Vielleicht merkt es niemand." + - "Nicht aufgeben. Es könnte noch schlimmer werden." + - "Träume groß. Die Realität übernimmt den Rest." + - "Das Glas ist halb voll. Mit Problemen." + - "Jeder Tag bietet Chancen. Manche davon sind Termine." + - "Du kannst alles schaffen. Außer vielleicht heute." + - "Das Leben ist kurz. Besprechungen sind länger." + - "Mut steht am Anfang. Die Rechnung kommt später." + - "Wenn es einfach wäre, würde es jemand anders machen." + - "Deine To-do-Liste glaubt an dich. Sie muss ja nicht mitmachen." + - "Perfektion ist erreichbar. Nur nicht von hier." diff --git a/template.yaml b/template.yaml index f347d7a..f5bed7e 100644 --- a/template.yaml +++ b/template.yaml @@ -49,6 +49,10 @@ name: Sun Setting Template state: '{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom (''%H:%M'') }}' + - unique_id: epaper_demotivational_quote + default_entity_id: sensor.epaper_demotivationszitat + name: Epaper Demotivationszitat + state: "{{ states('input_select.epaper_demotivationszitat') }}" - name: "power_other" unique_id: '5579422933393'