Do I need 9 automations for 9 windows?

I’d like to get a reminder to close a window / door if its been left open for x minutes.
I feel like creating 9 duplicate automations for my 9 windows/doors is not the right way to go. how can I get notifications for a specific window while only having a single automation?

Edit: here is my final configuration:

alias: Windows Open
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.window
#     - all other windows
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 7
      seconds: 5
  - platform: state
    entity_id:
      - sensor.door
#     - all other doors
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 3
      seconds: 0
condition: []
action:
  - service: notify.mobile_app_phone
    data:
      title: {{ state_attr(trigger.entity_id , 'friendly_name') }}
      message: opened {{relative_time(states[trigger.entity_id].last_changed)}} ago
mode: parallel
max: 10

I do have one automation for this with multiple triggers for multiple windows. It just does not tell, which window is open. Only that one of the windows is open. Enough for me.

Looks like this:

alias: Raam open
description: ""
trigger:
  - type: opened
    platform: device
    device_id: 0bff8293fb429569b4a9e11e9288055c
    entity_id: binary_sensor.raamraafcave_access_control_window_door_is_open
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: opened
    platform: device
    device_id: 98c50ecbd359ff66c7eab9c7a16561c1
    entity_id: binary_sensor.raamslaapkamer_access_control_window_door_is_open
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: opened
    platform: device
    device_id: 9bd1ce4f54ab3fe7c323ebb2c9bf31c8
    entity_id: binary_sensor.raamwoonlinks_access_control_window_door_is_open
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: opened
    platform: device
    device_id: b516e6e2666302fd2ad55ddf53607ef1
    entity_id: binary_sensor.raamterraslinks_access_control_window_door_is_open
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: opened
    platform: device
    device_id: 0cb45fda1484be7257a83dfe3e331847
    entity_id: binary_sensor.raamterrasrechts_access_control_window_door_is_open
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
condition:
  - condition: numeric_state
    entity_id: sensor.openweathermap_temperature
    below: "10"
action:
  - service: notify.mobile_app_in2013
    data:
      message: >-
        Hallo, een van de ramen staat open. Buiten is het minder, dan tien
        graden. Ik heb de verwarming uitgeschakeld. Ik zet het pas weer aan, als
        het raam weer dicht is.
  - service: notify.mobile_app_mischa_op6t
    data:
      message: >-
        Hallo, een van de ramen staat open. Buiten is het minder, dan tien
        graden. Ik heb de verwarming uitgeschakeld. Ik zet het pas weer aan, als
        het raam weer dicht is.
  - service: media_player.play_media
    target:
      entity_id: media_player.vlc_telnet
    data:
      media_content_id: http://192.168.178.79:8123/local/ns-ding-dong.mp3
      media_content_type: music
  - scene: scene.alarm_lampen
  - delay: "00:00:01"
  - scene: scene.lamp_keuken_tafel_normaal
  - delay: "00:00:01"
  - scene: scene.alarm_lampen
  - delay: "00:00:01"
  - scene: scene.lamp_keuken_tafel_normaal
  - service: notify.vlctelnetha
    data:
      message: >-
        Hallo, een van de ramen staat open. Buiten is het minder, dan tien
        graden. Ik heb de verwarming uitgeschakeld. Ik zet het pas weer aan, als
        het raam weer dicht is.
  - service: climate.set_temperature
    target:
      entity_id: climate.thermostat
    data:
      temperature: 10
mode: single
1 Like

Use trigger id, then you can do one automation with your 9 windows/doors. Example is my automation for our two garage doors.

alias: Garasjeporter
description: ""
trigger:
  - type: opened
    platform: device
    device_id: c947892c432731acca8fb3c8533af149
    entity_id: binary_sensor.door_garasje_annika_contact
    domain: binary_sensor
    id: garasje-a-open
  - type: opened
    platform: device
    device_id: 39cbd1a4357ba89820a7069e5adc049f
    entity_id: binary_sensor.door_garasje_marius_contact
    domain: binary_sensor
    id: garasje-m-open
  - type: not_opened
    platform: device
    device_id: c947892c432731acca8fb3c8533af149
    entity_id: binary_sensor.door_garasje_annika_contact
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 10
    id: garasje-a-closed
  - type: not_opened
    platform: device
    device_id: 39cbd1a4357ba89820a7069e5adc049f
    entity_id: binary_sensor.door_garasje_marius_contact
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 10
    id: garasje-m-closed
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: garasje-a-open
        sequence:
          - service: notify.mobile_app_marius_iphone_13
            data:
              message: Garasje Annika
              title: Garasjeport er åpnet
      - conditions:
          - condition: trigger
            id: garasje-m-open
        sequence:
          - service: notify.mobile_app_marius_iphone_13
            data:
              message: Garasje Marius
              title: Garasjeport er åpnet
      - conditions:
          - condition: trigger
            id: garasje-a-closed
        sequence:
          - service: notify.mobile_app_marius_iphone_13
            data:
              message: Garasje Annika
              title: Garasjeport er lukket
      - conditions:
          - condition: trigger
            id: garasje-m-closed
        sequence:
          - service: notify.mobile_app_marius_iphone_13
            data:
              message: Garasje Marius
              title: Garasjeport er lukket
mode: single
2 Likes

Create a blueprint and use it with 9 automations.

1 Like

Can one make a blueprint that would use trigger id as in @fleskefjes’s example?

probably easier to edit in yaml, do a copy / paste and change sensor/trigger id.

You can have multiple entities in a state trigger:

platform: state
entity_id:
  - binary_sensor.guest_room_windows
  - binary_sensor.kitchen_windows
to: 'on'
for:
  hours: 0
  minutes: 1
  seconds: 0

Try something like this:

alias: Raam open
description: ""
trigger:
  - platform: device
    entity_id: 
      - binary_sensor.raamraafcave_access_control_window_door_is_open
      - binary_sensor.raamslaapkamer_access_control_window_door_is_open
      - binary_sensor.raamterraslinks_access_control_window_door_is_open
      - binary_sensor.raamwoonlinks_access_control_window_door_is_open
      - binary_sensor.raamterraslinks_access_control_window_door_is_open
      - binary_sensor.raamterrasrechts_access_control_window_door_is_open
    to: 'on'
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
condition:
  - condition: numeric_state
    entity_id: sensor.openweathermap_temperature
    below: "10"
action:
  - service: notify.mobile_app_in2013
    data:
      message: >-
        Hallo, een van de ramen staat open. Buiten is het minder, dan tien
        graden. Ik heb de verwarming uitgeschakeld. Ik zet het pas weer aan, als
        het raam weer dicht is.
  - service: notify.mobile_app_mischa_op6t
    data:
      message: >-
        Hallo, een van de ramen staat open. Buiten is het minder, dan tien
        graden. Ik heb de verwarming uitgeschakeld. Ik zet het pas weer aan, als
        het raam weer dicht is.
  - service: media_player.play_media
    target:
      entity_id: media_player.vlc_telnet
    data:
      media_content_id: http://192.168.178.79:8123/local/ns-ding-dong.mp3
      media_content_type: music
  - scene: scene.alarm_lampen
  - delay: "00:00:01"
  - scene: scene.lamp_keuken_tafel_normaal
  - delay: "00:00:01"
  - scene: scene.alarm_lampen
  - delay: "00:00:01"
  - scene: scene.lamp_keuken_tafel_normaal
  - service: notify.vlctelnetha
    data:
      message: >-
        Hallo, een van de ramen staat open. Buiten is het minder, dan tien
        graden. Ik heb de verwarming uitgeschakeld. Ik zet het pas weer aan, als
        het raam weer dicht is.
  - service: climate.set_temperature
    target:
      entity_id: climate.thermostat
    data:
      temperature: 10
mode: single
1 Like

You can reference trigger.entity_id in your templates.

3 Likes

Awesome! this works:

service: notify.mobile_app
data:
  title: Fenster auf
  message: {{ state_attr(trigger.entity_id , 'friendly_name') }} is open
4 Likes