Issue a warning about open windows

Hi there,

I would like to integrate several window sensors into an automation, but have little knowledge of programming.

The following goal:
If a window is open for longer than 5 minutes, a voice output should indicate this. I will include every window as a trigger. The speech output should be general (i.e. the window does not have to be named precisely).
The voice output should then take place every 3 minutes (at most 4x) until there is no longer a window that has been open for more than 5 minutes.

I created the following automation (initially I only included two windows).

Here is my previous draft:

alias: Fensterwarnung
description: ''
trigger:
  - type: opened
    platform: device
    device_id: a3b660743a3ade9f221523df6512bbe7
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_19330507_on_off
    domain: binary_sensor
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - type: opened
    platform: device
    device_id: d8e8f30f98adcd2234289e599c98affc
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_0005ff06_on_off
    domain: binary_sensor
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
condition: []
action:
  - repeat:
      count: '4'
      sequence:
        - service: media_player.play_media
          data:
            media_content_id: amzn_sfx_doorbell_chime_01
            media_content_type: sound
          target:
            entity_id:
              - media_player.arbeitszimmer
              - media_player.eva_s_bose_smart_soundbar_300
              - media_player.bad
              - media_player.terrasse
              - media_player.workstatt
        - service: notify.alexa_media
          data:
            message: >-
              Eine oder mehrer Fenster sind schon länger geöffnet. Bitte wieder
              schließen
            target:
              - media_player.workstatt
              - media_player.terrasse
              - media_player.moritz
              - media_player.bad
              - media_player.arbeitszimmer
              - media_player.eva_s_bose_smart_soundbar_300
            data:
              type: tts
        - delay:
            hours: 0
            minutes: 3
            seconds: 0
            milliseconds: 0
mode: single

My questions:

  • How can I ensure that the automation ends when no more windows meet the condition (opened for at least 5 minutes)?
  • How can I set the automation to only run from October to March?

Thank you very much, Werner

create an automation that runs at midnight ever night and checks the date. Unfortunately you have to use templates when checking against month/day.

trigger:
- platform: time
  at: "00:00:00"
variables:
  my_custom_action: >
    {% set time = now() %}
    {% if time.month == 3 and time.day == 1 %}
      turn_off
    {% elif time.month == 10 and time.day == 31 %}
      turn_on
    {% else %}
      do_nothing
    {% endif %}
condition:
- condition: template
  value_template: "{{ my_custom_action != 'do_nothing' }}"
action:
- service: automation.{{ my_custom_action }}
  target:
    entity_id: automation.whatever_the_entity_id_of_your_automation_is

Create a template binary_sensor that detects open windows. Then repeat your action until that reaches zero.

Just list your entity_id’s in the first line, make sure they are wrapped in quotes and separated by a comma.

template:
- binary_sensor:
  - name: Windows Open
    unit_of_measurement: windows
    state: >
      {% set mywindows = 'binary_sensor.lumi_lumi_sensor_magnet_aq2_19330507_on_off', 'binary_sensor.lumi_lumi_sensor_magnet_aq2_0005ff06_on_off' %}
      {{ expand(mywindows) | selectattr('state','in', ['open','on']) | list | count > 0 }}

Then in your automation…

  - repeat:
      until: "{{ is_state('binary_sensor.windows_open','off') }}"
      ....
1 Like

Hallo,

vielen lieben Dank für die Antwort. Es ist doch komplizierter als iich gedacht habe.
Ich werde es versuchen und mich bei Fragen melden.

Gruß Werner