How to automate open door notifications?

I have previously done simpler automation, mostly based on examples I found on the internet, like switching lights on or off based on motion in the room or daytime, etc. Now I’m looking to create a bit more complex one, and I’m lost on how to do it.

Goal:

  • Get a notification (via blinking kitchen lights) if the garage door is left open after 22:00 fore more than 10 minutes.
  • The notification should blink the lights 10 times every 5 minutes, up to 7 times, or until the door is closed.
  • Ensure the kitchen lights return to their original state (whether on, off or dimmed) after the automation ends or during the pauses between blinking.

Logical Flow:

  1. Trigger Condition:
  • When the garage door is left open for more than 10 minutes AND the time is after 22:00 (10 PM), initiate the notification.
  1. Initial Action:
  • Save the current state of the kitchen lights (brightness and whether they are on or off).
  • Start the first blinking cycle.
  1. Blinking Cycle:
  • Blink the kitchen lights by dimming up and down 10 times in quick succession.
  • After the 10 blinks, pause for 5 minutes.
  • Set lights to initial state.
  1. Looping:
  • After the 5-minute pause, check if the garage door is still open.
  • If the garage door is still open, repeat the blinking cycle (blink 10 times, pause 5 minutes).
  • Repeat the cycle up to 7 times, or until the garage door is closed.
  1. Stop Condition:
  • If at any point during the blinking cycles, the garage door is closed, stop the automation immediately.
  • Alternatively, if the automation completes all 7 cycles (and the door is still open), stop after the 7th cycle.
  1. Final Action:
  • After the automation ends (either by closing the door or after 7 cycles), return the kitchen lights to their original state (restore the brightness level and on/off state).

I have no idea how I should build this flow using the UI.
Step 1 is simple, and so are steps 3 (except returning the initial state) and 4. But I can’t seem to find the correct way to do everything else, such as saving and returning the light state, and stopping the automation in the middle of it.

Right now, my result is that the lights blink, and the looping continues to the end (which is very annoying). I’m also unable to set the initial state of the bulbs.
If anyone can point me in the right direction, I would be grateful.

I might not be able to solve all your problems, but hopefully I can get you partway there. If you could post your current automation, I’m sure others will be able to help more, rather than having to depend on a description of the symptoms.

To save, use the scene.create service. Docs here.

Adding a delay and/or a wait for trigger with a wait timeout should help with this

That already helped me a lot (at least I think so).
I should start my IF THEN automation with trigger door_open, then save the state with scene.create and start loop with checking trigger door_open, and at the end of the loop restore scene and wait for the trigger door_closed. And if door_closed is triggered then automation stops because of door_open is not detected at the beginning of loop. Is that correct?

Yes, kinda, but you need to set the wait for trigger to the equivalent of door closed. Setting it to door open not detected complicates matters.

Try it out and report back on what works and what doesn’t, but when you do that, please paste your automation here, formatted correctly.
t
Here is a (VERY) simplified rundown of what your automation needs to do:

  1. Trigger: door open for 10m
  2. Condition: time after 22:00
  3. Action: create scene
  4. Wait 5s (good to have so that scene has ample time to be stored)
  5. Start toggling the state of the light for 10 times (I would put this part in a separate script)
  6. Wait for trigger (door closed) with a continue on timeout of 5m set to true
  7. (not 100% sure because I’m not super familiar with it) Use a Repeat with count: 10. If you’re using a script in step 5, you can just copy the last part of the linked example.
  8. When door is closed or repeat count runs out, re-apply the scene you created.

Thanks for the help, I think I got this.
Additionally, I had a bit of trouble with making bulbs blink as I wanted, but that was solved using a script I found here in the forums.

alias: Garage door open. Flash lights.
description: "flashes kitchen table lights when garage door is left open after 22:00"
triggers:
  - type: opened
    device_id: abb6c8868bfd4d2c430c83460a05196e
    entity_id: aaf36359b3e23498fb697b26a234b902
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 15
      seconds: 0
    id: garage_door_open
  - type: not_opened
    device_id: abb6c8868bfd4d2c430c83460a05196e
    entity_id: aaf36359b3e23498fb697b26a234b902
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 0
      seconds: 20
    id: garage_door_closed
conditions:
  - condition: time
    after: "22:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
    before: "23:59:59"
actions:
  - if:
      - condition: trigger
        id:
          - garage_door_open
    then:
      - repeat:
          sequence:
            - action: scene.create
              metadata: {}
              data:
                scene_id: kichen_lights_before
                snapshot_entities:
                  - light.0x6c5cb1fffe609126
                  - light.0x04cd15fffec6c44b
                  - light.0x84b4dbfffe5081ab
                  - switch.luliti_kook_sook_l2
            - delay:
                hours: 0
                minutes: 0
                seconds: 3
                milliseconds: 0
              alias: wait for 3 sek
            - type: turn_on
              device_id: 1b58e104b5b4a188da2348c89dd9af96
              entity_id: 798690e4a2297d0b6b9a3c2aa8343801
              domain: switch
            - delay:
                hours: 0
                minutes: 0
                seconds: 3
                milliseconds: 0
            - action: script.wip_flash_lights
              metadata: {}
              data:
                repetitions: 7
                brightness_pct: 100
                target_lights:
                  - light.0x6c5cb1fffe609126
                  - light.0x04cd15fffec6c44b
                  - light.0x84b4dbfffe5081ab
                delay: 2.1
                color_temp: 153
            - action: scene.turn_on
              metadata: {}
              target:
                entity_id: scene.kichen_lights_before
            - action: scene.delete
              metadata: {}
              data: {}
              target:
                entity_id: scene.kichen_lights_before
            - alias: wait for 7 min
              delay:
                hours: 0
                minutes: 7
                seconds: 0
                milliseconds: 0
          until:
            - type: is_not_open
              condition: device
              device_id: abb6c8868bfd4d2c430c83460a05196e
              entity_id: aaf36359b3e23498fb697b26a234b902
              domain: binary_sensor
mode: single