How to generalise automation for notification?

Hello everyone!

I am currently still using the FHEM system, but would like to switch to HA and am still a beginner here. In FHEM, I have written auxiliary functions in Perl to generate a notification for open windows.
Specifically, I first check whether the outside temperature (queried by an internet service) is above 16 degrees. If this is the case, nothing else happens.
If the temperature is 16 degrees or less, a trigger is set so that an announcement is made after 5 minutes: ‘Please close window XYZ.’
XYZ is a placeholder and is replaced by the name of the sensor that triggered the event. E.g. ‘Living room’. After 5 minutes, the text is then spoken on my Alexa.
If the window for which the trigger was created is closed in the meantime, the trigger created is closed.

I have already successfully implemented something like this via an automation in HA:

alias: Notification - Window opened
description: ""
mode: single
triggers:
  - type: opened
    device_id: ...........
    entity_id: ...........
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 20
    trigger: device
conditions: []
actions:
  - repeat:
      sequence:
        - device_id: ...........
          domain: mobile_app
          type: notify
          title: "Window"
          message: Was opened
        - delay:
            hours: 0
            minutes: 0
            seconds: 10
            milliseconds: 0
        - data:
            data:
              type: tts
            message: This is a test
          action: notify.alexa_media_firetv_wohnzimmer
      while:
        - type: is_open
          condition: device
          device_id: ...........
          entity_id: ...........
          domain: binary_sensor

Now I would like to generalise this automation. In other words, I would like to have an automation that works for all window sensors. And the name should be embedded in the announcement. How would this work in HA?

I do something a bit like this with TTS announcements - the code that makes the announcement is is a script called by several different automations. The automations send the text of the announcement in a “field”:

A simple way to handle this in a single automation would be with multiple triggers (one for each window). Give each one a trigger ID, then use the “choose” action to select the announcement with the right name.

May be the blueprint Contact Sensor (Door or Window) Left Open Notification helps.
You can simply add additonal conditions (like the temperature) for your notifications and it works out of the box.

Thanks @jackjourneyman :slight_smile: I actually want to avoid setting multiple triggers. For the sake of clarity but also to get to know HA better, I think the blueprints that @curzon01 suggests are the better approach. I’ll have to have a look at what blueprints are and how they work.