Hallo zusammen,
ich möchte per ICAL Kalender einen Sensor machen, der mir dann die nächsten Geburstage “ausspuckt”
Sensor wurde auch soweit schon erstellt.
Die Entität von dem ICAL Kalender sagt folgendes:
Wenn ich aber jetzt nach der Entität des Sensors schaue, wo mir den nächsten Geburtstag anzeigen soll, findet er nichts…
Hier der Sensor code… sieht hier irgendjemand nen Fehler ?
- sensor:
- name: "Nächster Geburtstag"
unique_id: naechster_geburtstag_sensor
icon: mdi:cake
state: >
{% set calendar_entity = 'calendar.gemeinsamer_kalender' %} {# <== WICHTIG: Entitätsnamen anpassen! #}
{% set next_event = state_attr(calendar_entity, 'next_event') %}
{% if next_event is not none %}
{{ next_event.summary }}
{% else %}
Kein bevorstehender Geburtstag gefunden
{% endif %}
attributes:
datum: >
{% set calendar_entity = 'calendar.gemeinsamer_kalender' %} {# <== WICHTIG: Entitätsnamen anpassen! #}
{% set next_event = state_attr(calendar_entity, 'next_event') %}
{% if next_event is not none %}
{{ next_event.start | as_datetime | as_local | strftime('%Y-%m-%d') }}
{% else %}
N/A
{% endif %}
tage_bis: >
{% set calendar_entity = 'calendar.gemeinsamer_kalender' %} {# <== WICHTIG: Entitätsnamen anpassen! #}
{% set next_event = state_attr(calendar_entity, 'next_event') %}
{% if next_event is not none %}
{% set start_dt = next_event.start | as_datetime | as_local %}
{% set today = now().date() %}
{% set start_date = start_dt.date() %}
{# Handle recurring birthdays - check if date this year has passed #}
{% set next_birthday_this_year = start_date.replace(year=today.year) %}
{% if next_birthday_this_year < today %}
{# Birthday for this year has passed, calculate for next year #}
{% set next_birthday = start_date.replace(year=today.year + 1) %}
{% else %}
{# Birthday is still this year #}
{% set next_birthday = next_birthday_this_year %}
{% endif %}
{{ (next_birthday - today).days }}
{% else %}
N/A
{% endif %}
DANKE schon mal