My toilet light automation: help with improvement

Hello all,

i have a toiletlight automation where a philips huw doorsensor is the trigger, the first version had the flaw that sometimes the light was immediatly switched off again. To overcome this I came up with this automation, the subparts where added later, if you remove these 2 subparts, you seen the original automation:
can You guys help me with improving this automation?
.

alias: Toilet_automaat_lamp
description: >-
  Binnenkomen toilet triggert lamp ikea aan, wacht op trigger deur weer dicht.
  Na toiletbezoek, trigger deur van gesloten naar open en dan weer van open naar
  dicht, lamp uitzetten
triggers:
  - type: turned_on
    device_id: e410424c5acc9fa683a5336ab3bfe59b
    entity_id: ce000fc758ec5b29bfb1dc057849aa21
    domain: light
    trigger: device
conditions: []
actions:
  - device_id: e410424c5acc9fa683a5336ab3bfe59b
    domain: light
    entity_id: ce000fc758ec5b29bfb1dc057849aa21
    type: brightness_increase
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - if:
      - condition: state
        entity_id: light.tuinlamp_linksmidden
        state: "off"
    then:
      - type: turn_on
        device_id: e410424c5acc9fa683a5336ab3bfe59b
        entity_id: ce000fc758ec5b29bfb1dc057849aa21
        domain: light
        brightness_pct: 100
      - wait_for_trigger:
          - trigger: state
            entity_id:
              - binary_sensor.hue_secure_contact_sensor_2_openen
            from: "off"
            to: "on"
        continue_on_timeout: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
      - type: turn_off
        device_id: e410424c5acc9fa683a5336ab3bfe59b
        entity_id: ce000fc758ec5b29bfb1dc057849aa21
        domain: light
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - if:
      - condition: state
        entity_id: light.tuinlamp_linksmidden
        state: "off"
    then:
      - type: turn_on
        device_id: e410424c5acc9fa683a5336ab3bfe59b
        entity_id: ce000fc758ec5b29bfb1dc057849aa21
        domain: light
        brightness_pct: 100
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
      - wait_for_trigger:
          - trigger: state
            entity_id:
              - binary_sensor.hue_secure_contact_sensor_2_openen
            from: "off"
            to: "on"
        continue_on_timeout: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
      - type: turn_off
        device_id: e410424c5acc9fa683a5336ab3bfe59b
        entity_id: ce000fc758ec5b29bfb1dc057849aa21
        domain: light
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - binary_sensor.hue_secure_contact_sensor_2_openen
        from: "off"
        to: "on"
    continue_on_timeout: false
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
  - type: turn_off
    device_id: e410424c5acc9fa683a5336ab3bfe59b
    entity_id: ce000fc758ec5b29bfb1dc057849aa21
    domain: light
mode: single

As a minority, will understand your dutch:

Entering toilet triggers ikea lamp on, wait for trigger door to close again.
After toilet visit, trigger door from closed to open and then again from open to
closed, turn lamp off

  • Your only trigger is the door switch.
  • The automation should wait between the trigger events 20 seconds.
  • Let Home Assistant figure out the state from on or off and change it up on a trigger event.

Sounds almost like a prompt for CoPilot :smiley: