For those who are interested, I got it to work:
I created a group in the groups.yaml for all window sensors:
all_windows:
entities:
- binary_sensor.openclose_20
- binary_sensor.openclose_21
- binary_sensor.openclose_19
- binary_sensor.openclose_15
- binary_sensor.openclose_23
- binary_sensor.openclose_24
- binary_sensor.openclose_16
- binary_sensor.openclose_22
I created a timer in the configuration.yaml:
timer:
timer_window:
duration: "00:10:00"
I created an automation stat starts the timer, when any window is open.
- alias: Windows Open
description: ''
trigger:
- platform: state
entity_id: group.all_windows
to: 'on'
condition: []
action:
- service: timer.start
data: {}
entity_id: timer.timer_window
mode: single
Another animation cancels the timer:
- id: '1614244148124'
alias: Windows Close
description: ''
trigger:
- platform: state
entity_id: group.all_windows
to: 'off'
condition: []
action:
- service: timer.cancel
data: {}
entity_id: timer.timer_window
mode: single
I created a script, that handles the notification:
notify_window_open:
alias: Notify Window Open
sequence:
- service: media_player.volume_set
data:
volume_level: "0.9"
entity_id: media_player.bathroom, media_player.sleeping_room, media_player.kitchen
- service: notify.alexa_media_bathroom
data:
data:
type: tts
message: "Window {% if is_state(\"binary_sensor.openclose_15\", \"on\") -%}\n\
\ Office 1,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_16\"\
, \"on\") -%}\n Bedroom,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_19\"\
, \"on\") -%}\n Office 2,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_20\"\
, \"on\") -%}\n Bathroom,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_21\"\
, \"on\") -%}\n Bathroom Guest,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_22\"\
, \"on\") -%}\n Living Room,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_23\"\
, \"on\") -%}\n Kitchen 1,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_24\"\
, \"on\") -%}\n Kitchen 2\n{%- endif %} open since 10 minutes..\n"
- service: notify.alexa_media_sleeping_room
data:
data:
type: tts
message: "Window {% if is_state(\"binary_sensor.openclose_15\", \"on\") -%}\n\
\ Office 1,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_16\"\
, \"on\") -%}\n Bedroom,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_19\"\
, \"on\") -%}\n Office 2,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_20\"\
, \"on\") -%}\n Bathroom,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_21\"\
, \"on\") -%}\n Bathroom Guest,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_22\"\
, \"on\") -%}\n Living Room,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_23\"\
, \"on\") -%}\n Kitchen 1,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_24\"\
, \"on\") -%}\n Kitchen 2\n{%- endif %} open since 10 minutes..\n"
- service: notify.alexa_media_kitchen
data:
data:
type: tts
message: "Window {% if is_state(\"binary_sensor.openclose_15\", \"on\") -%}\n\
\ Office 1,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_16\"\
, \"on\") -%}\n Bedroom,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_19\"\
, \"on\") -%}\n Office 2,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_20\"\
, \"on\") -%}\n Bathroom,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_21\"\
, \"on\") -%}\n Bathroom Guest,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_22\"\
, \"on\") -%}\n Living Room,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_23\"\
, \"on\") -%}\n Kitchen 1,\n{%- endif %} {% if is_state(\"binary_sensor.openclose_24\"\
, \"on\") -%}\n Kitchen 2\n{%- endif %} open since 10 minutes..\n"
- service: media_player.volume_set
data:
volume_level: "0.5"
entity_id: media_player.bathroom, media_player.sleeping_room, media_player.kitchen
mode: single
Then there is the automation that fires, when the timer finishes:
alias: Fenster-Erinnerung
description: ''
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_window
condition:
- condition: state
entity_id: group.all_windows
state: 'on'
action:
- service: script.notify_window_open
data: {}
entity_id: media_player.bathroom
- service: timer.start
entity_id: timer.timer_window
data: {}
mode: single
How is it working? When the timer starts and all windows close before the timer finishes, it gets canceled and no notification will be send.
When the timer finishes, and windows are still open. the notification will be fired and the timer will be restarted and this will happen until every window is close.
I am looking forward for your ideas and improvements.
What I will implement next, is a boolean switch “Window Check” as second condition for the notification. Thus I am able to disable the window check. I will add a second timer, that will enable the disable function after 2 hours, so that I don’t forget to re-enable the check.