Hello,
I am currently trying to create an automation that tells me which window is still open when I open my front door.
The id’s and also the “on” is correct but still the array remains empty.
I just can’t get any further. Maybe someone else has a tip for me?
Here is my code:
alias: Fenster offen beim Öffnen der Haustür
description: >-
Prüft offene Fenster, wenn die Haustür geöffnet wird, und gibt eine Ansage
aus.
variables:
fenster_kontakte: # Die Fensterliste wird hier global für die Automatisierung definiert
- entity_id: binary_sensor.badezimmer_sensor_offnung
name: "Badezimmer Sensor"
- entity_id: binary_sensor.schlafzimmer_sensor_offnung
name: "Schlafzimmer Sensor"
- entity_id: binary_sensor.terrassentur_sensor_offnung
name: "Terrassentür Sensor"
- entity_id: binary_sensor.schiebetur_sensor_offnung
name: "Schiebetür Sensor"
trigger:
- platform: state
entity_id: binary_sensor.deine_haustuer_entitaet # <--- HIER DEINE HAUSTÜR ENTITY_ID EINFÜGEN!
from: 'off'
to: 'on'
conditions: []
action:
- choose:
- conditions:
- condition: template
value_template: >
{% set open_windows_temp = [] %}
{% for window in fenster_kontakte %}
{% if is_state(window.entity_id, 'on') %}
{% set open_windows_temp = open_windows_temp + [window.name] %}
{% endif %}
{% endfor %}
{{ open_windows_temp | length > 0 }}
sequence:
- service: tts.cloud_say
data:
cache: false
entity_id: media_player.hub_buro # <--- HIER DEINEN MEDIAPLAYER EINFÜGEN!
message: >
{% set open_windows_temp = [] %}
{% for window in fenster_kontakte %}
{% if is_state(window.entity_id, 'on') %}
{% set open_windows_temp = open_windows_temp + [window.name] %}
{% endif %}
{% endfor %}
{% if open_windows_temp | length == 1 %}
Achtung, das {{ open_windows_temp[0] }} ist noch offen.
{% elif open_windows_temp | length > 1 %}
Achtung, folgende Fenster sind noch offen:
{% for i in range(open_windows_temp | length) %}
{% if i == open_windows_temp | length - 1 and open_windows_temp | length > 1 %}
und das {{ open_windows_temp[i] }}
{% else %}
{{ open_windows_temp[i] }}{% if i < open_windows_temp | length - 2 %},{% endif %}
{% endif %}
{% endfor %}.
{% endif %}
- conditions: []
sequence:
- service: tts.cloud_say
data:
cache: false
entity_id: media_player.hub_buro # <--- HIER DEINEN MEDIAPLAYER EINFÜGEN!
message: > # <--- HIER DAS ">" HINZUFÜGEN!
{% set open_windows_temp = [] %}
{% for window in fenster_kontakte %}
{% if is_state(window.entity_id, 'on') %}
{% set open_windows_temp = open_windows_temp + [window.name] %}
{% endif %}
{% endfor %}
Alle Fenster sind geschlossen. Die Länge ist {{ open_windows_temp | length }}. Das ist super.
mode: single
the comments in the code are in German.