6 Commits

4 changed files with 846 additions and 288 deletions
+3
View File
@@ -35,6 +35,9 @@ utility_meter: !include utility_meters.yaml
mqtt: !include mqtt.yaml mqtt: !include mqtt.yaml
mqtt_statestream: !include mqtt_statestream.yaml mqtt_statestream: !include mqtt_statestream.yaml
# Calendar data is normalised in a sandboxed script before ESPHome receives it.
python_script:
# Template sensors # Template sensors
template: !include template.yaml template: !include template.yaml
+725 -288
View File
File diff suppressed because it is too large Load Diff
+88
View File
@@ -0,0 +1,88 @@
# Calendar data is compacted here so the ESP32 only receives display-ready entries.
CALENDAR_NAMES = {
"calendar.tkrz_kalender": "Arbeit",
"calendar.privat": "Privat",
}
DAY_NAMES = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
MAX_ENTRIES = 8
# Reserve the right side of each row for start and end times.
MAX_TITLE_LENGTH = 25
MAX_META_LENGTH = 35
def shorten(value, maximum):
value = (value or "").strip()
if len(value) <= maximum:
return value
return value[: maximum - 3].rstrip() + "..."
def compact_event(event, calendar_name):
start = event.get("start", "")
all_day = "T" not in start
end = event.get("end", "")
time = "ganztägig" if all_day else start[11:16]
end_time = "" if all_day or "T" not in end else end[11:16]
location = (event.get("location") or "").split("\n")[0].strip()
meta = calendar_name
if location:
meta += " / " + location
return {
"title": shorten(event.get("summary", "Ohne Titel"), MAX_TITLE_LENGTH),
"time": time,
"end": end_time,
"meta": shorten(meta, MAX_META_LENGTH),
"all_day": int(all_day),
}
calendar_data = data.get("calendar", {})
today = str(data.get("now", ""))[:10]
events_by_date = {}
for calendar_id, calendar in calendar_data.items():
calendar_name = CALENDAR_NAMES.get(calendar_id, calendar_id.split(".")[-1].capitalize())
for event in calendar.get("events", []):
start = event.get("start", "")
end = event.get("end", "")
event_date = start[:10]
end_date = end[:10]
# Ignore malformed or already finished entries. All-day event end dates
# are exclusive in Home Assistant; timed events ending today may still be
# active. Multi-day entries remain visible on today's date rail.
all_day = "T" not in start
if not event_date or (all_day and end_date <= today) or (not all_day and end_date < today):
continue
if event_date < today:
event_date = today
events_by_date.setdefault(event_date, []).append(
compact_event(event, calendar_name)
)
entries = []
entry_count = 0
for date in sorted(events_by_date):
if entry_count >= MAX_ENTRIES:
break
events = events_by_date[date]
events.sort(key=lambda item: (item["all_day"] == 0, item["time"]))
remaining = MAX_ENTRIES - entry_count
events = events[:remaining]
entry_count += len(events)
parsed_date = dt_util.parse_datetime(date)
entries.append(
{
"day": parsed_date.day,
"weekday": DAY_NAMES[parsed_date.weekday()],
"today": int(date == today),
"events": events,
}
)
output["entries"] = entries
+30
View File
@@ -49,6 +49,7 @@
name: Sun Setting Template name: Sun Setting Template
state: '{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom state: '{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom
(''%H:%M'') }}' (''%H:%M'') }}'
- name: "power_other" - name: "power_other"
unique_id: '5579422933393' unique_id: '5579422933393'
unit_of_measurement: "W" unit_of_measurement: "W"
@@ -79,6 +80,35 @@
attributes: attributes:
last_reset: '1970-01-01T00:00:00+00:00' last_reset: '1970-01-01T00:00:00+00:00'
# Compact calendar feed for the e-paper display. The actual event data lives in
# the `entries` attribute, which ESPHome reads as a text sensor.
- trigger:
- trigger: homeassistant
event: start
- trigger: time_pattern
minutes: /15
action:
- action: calendar.get_events
target:
entity_id:
- calendar.tkrz_kalender
- calendar.privat
data:
duration:
days: 14
response_variable: calendar_response
- action: python_script.epaper_calendar_data
data:
calendar: "{{ calendar_response }}"
now: "{{ now().date() }}"
response_variable: calendar_converted
sensor:
- name: Epaper Kalenderdaten
unique_id: epaper_calendar_data
state: "{{ calendar_converted.entries | count }}"
attributes:
entries: "{{ calendar_converted.entries }}"
# Shelly 3EM cumulative sensors (incl. PV) # Shelly 3EM cumulative sensors (incl. PV)
- sensor: - sensor:
# Template sensor for values of power import (active_power > 0) # Template sensor for values of power import (active_power > 0)