Stupid question about canceling an automation

Hi there,

I have created an automation (draft) that should remind me of open windows via Alexa.
The design looks like this:

alias: Fensterwarnung Arbeitszimmer
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: 0
      seconds: 30
condition:
  - condition: state
    entity_id: sensor.moritz_aussentemperature_wrg
    state: <6
action:
  - repeat:
      count: '4'
      sequence:
        - service: media_player.play_media
          data:
            media_content_id: amzn_sfx_lightning_strike_02
            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
              - media_player.moritz
              - media_player.torstens_echo_dot
        - service: notify.alexa_media
          data:
            message: >-
              Fenster im Arbeitszimmer 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
              - media_player.torstens_echo_dot
            data:
              type: tts
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
mode: single

Two questions about this:

  1. How can I ensure that the automation is canceled when the corresponding window is closed again?
  2. I have built in the condition that the automation only starts at a certain temperature. Did I do it correctly “<6”?

Many Thanks.

Greetings Werner

condition:
  - condition: numeric_state
    entity_id: sensor.moritz_aussentemperature_wrg
    below: 6

To cancel it you could use the repeat until loop instead of just repeat.

1 Like

Hi there,

Thanks very much. I already thought that the temperature setting was wrong.
Unfortunately, I don’t understand that with repeating to the loop.
I only have the choice of “number”, “until condition” or “during condition”.

Greetings Werner

The “repeat until” documentation is here

you can use the condition to be until the window is closed or you can use a template condition that uses the repeat.index value of 4 so that it will repeat until the window is closed or the action repeats for 4 times.

I believe this should work:

  - repeat:
      sequence:
        - service: media_player.play_media
          data:
            media_content_id: amzn_sfx_lightning_strike_02
            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
              - media_player.moritz
              - media_player.torstens_echo_dot
        - service: notify.alexa_media
          data:
            message: >-
              Fenster im Arbeitszimmer 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
              - media_player.torstens_echo_dot
            data:
              type: tts
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
      until:
        - condition: or
          conditions:
            - condition: template
              value_template: "{{ repeat.index == 4 }}"
            - condition: state
              entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_19330507_on_off
              state: 'off'
1 Like

Here’s essentially what everyone has suggested you do except it uses:

alias: Fensterwarnung Arbeitszimmer
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_19330507_on_off
    to: 'on'
    for: '00:00:30'
condition: "{{ states('sensor.moritz_aussentemperature_wrg')|float(0) < 6 }}"
action:
  - variables:
      players: 
        - media_player.arbeitszimmer
        - media_player.eva_s_bose_smart_soundbar_300
        - media_player.bad
        - media_player.terrasse
        - media_player.workstatt
        - media_player.moritz
        - media_player.torstens_echo_dot
  - repeat:
      while: "{{ is_state('binary_sensor.lumi_lumi_sensor_magnet_aq2_19330507_on_off', 'on') and repeat.index <= 4 }}"
      sequence:
        - service: media_player.play_media
          data:
            media_content_id: amzn_sfx_lightning_strike_02
            media_content_type: sound
          target:
            entity_id: '{{ players }}'
        - service: notify.alexa_media
          data:
            message: 'Fenster im Arbeitszimmer sind schon länger geöffnet. Bitte wieder schließen'
            target: '{{ players }}'
            data:
              type: tts
        - delay: '00:00:30'
mode: single
1 Like

Hi there,

Thanks very much. It works great. I used the solution from [Endlichkeit] (Profile - finity - Home Assistant Community) because I can still edit it in the user interface.

I still have a small problem:

I took sounds from this website:
Alexa Skills Kit Sound Library | Alexa Skills Kit

However, the sound amzn_sfx_lightning_strike_02 does not work. However, amzn_sfx_doorbell_chime_01 works.

What can be the reason?

Greetings Werner

Although there are many sound effects, you are limited to using the ones that are listed in the Alexa app. That’s because the Alexa Media Player integration uses the same control interface as the Alexa app.

1 Like

I see. OK. How do I find the names of the available sounds?

Thank you.

Greetings Werner

They are listed in the Alexa Media Player’s documentation:

Known available sounds

1 Like

Thanks so much