Alexa reminds you to shut the door if it is cold outside (with repetition)

Premises:

  1. thermometer outside
  2. door sensor
  3. echo device
  4. alexa media player

automation

alias: Arbeitszimmertüre schließen
description: Erinnert via Alexa die Türe zu schließen
trigger:
  - platform: state
    entity_id: binary_sensor.arbeitszimmerture_oben_iaszone
    from: "off"
    to: "on"
action:
  - service: script.shut_the_door_please
    data:
      below: 12
      outside: sensor.kuechenbalkon_temperature
      door: binary_sensor.arbeitszimmerture_oben_iaszone
      echo: media_player.beta
      wait: 5
mode: single

service “Shut the door please”

alias: Shut the door please
description: Remind to close the door if it is open using an Echo device
fields:
  below:
    description: remind to close the door when the outside temperature is below
    example: 12
    required: true
  outside:
    description: thermometer outside
    example: sensor.kuechenbalkon_temperature
    required: true
  door:
    description: the door to observe
    example: binary_sensor.arbeitszimmerture_oben_iaszone
    required: true
  echo:
    description: the Alexa media player
    example: media_player.beta
    required: true
  wait:
    description: time to close the door before remainder in seconds
    example: 6
    required: true
sequence:
  - condition: template
    value_template: "{{ states(outside) | round <= below | round }}"
  - delay:
      hours: 0
      minutes: 0
      seconds: "{{ wait | float }}"
      milliseconds: 0
  - condition: template
    value_template: "{{ is_state(door, 'on') }}"
  - service: script.alexa_say
    data:
      type: announce
      message: >-
        <say-as interpret-as="interjection">Es ist <emphasis
        level="reduced">kalt</emphasis>!</say-as> <p>Draußen hat es <say-as
        interpret-as="unit"> {{ states(outside) | round }} Grad.</say-as></p>
      target: "{{ echo }}"
      volume: 0.7
      duration: 3.8
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - repeat:
      count: "3"
      sequence:
        - if:
            - condition: template
              value_template: "{{ is_state(door, 'on') }}"
          then:
            - service: script.alexa_say
              data:
                type: tts
                message: >-
                  <p><amazon:effect name="whispered">Bitte die Türe
                  schließen!</amazon:effect></p>
                target: "{{ echo }}"
                volume: 0.9
                duration: 2.3
            - delay:
                hours: 0
                minutes: 0
                seconds: 10
                milliseconds: 0
mode: single
icon: mdi:door-open

service “Alexa say”

alias: Alexa say
description: Say something with an Alexa device (tts or announce)
variables:
  pause: "{{ 1.7 if type == 'tts' else 0.0 | float }}"
  gong: "{{ 0.0 if type == 'tts' else 1.7 | float }}"
  reset: "{{ state_attr(target, 'volume_level') | default(0.5, true) | float }}"
fields:
  message:
    description: the message (SSML)
    example: <amazon:effect name="whispered">Please close the door.</amazon:effect>
    required: true
  type:
    description: tts or announce
    example: tts
    required: true
  target:
    description: the target devise as a string
    example: media_player.beta
    required: true
  volume:
    description: the volume of the speach
    example: 0.7
    required: true
  duration:
    description: the length of the speach in seconds
    example: 3.3
    required: true
sequence:
  - service: notify.alexa_media
    data:
      target: "{{ target }}"
      message: >-
        <break time='{{ pause + 0.2 | float }}s'/> {{ message }} <break
        time='1s'/>
      data:
        type: "{{ type }}"
  - delay:
      hours: 0
      minutes: 0
      seconds: "{{ pause | float }}"
      milliseconds: 0
  - service: media_player.volume_set
    data:
      volume_level: "{{ volume }}"
    target:
      entity_id: "{{ target }}"
  - delay:
      hours: 0
      minutes: 0
      seconds: "{{ gong + duration | float }}"
      milliseconds: 0
  - service: media_player.volume_set
    data:
      volume_level: "{{ reset | float }}"
    target:
      entity_id: "{{ target }}"
  - repeat:
      while:
        - condition: template
          value_template: >-
            {{ (reset | float) != (state_attr(target, 'volume_level') | float)
            }}
      sequence:
        - delay:
            hours: 0
            minutes: 0
            seconds: 1.5
            milliseconds: 0
mode: queued
icon: mdi:bullhorn
max: 10