Door sensor activated light

I’ve been playing around with ha for about 4 months now and this is probably the most involved over complicated (likely unnecessarily haha) automation I’ve made to date.

Our house is a default toilet door closed scenario but we do have the odd issue with not knowing if it is currently occupied before trying the door handle and freaking out occupants (or is that just me heh)

I wanted to add a zigbee battery light to the door that turns on when the door is triggered twice and turns off once exited. I haven’t got a light yet, haven’t been shopping for it so at this point I was just testing the automation with the toilet button boolean

I made a counter helper with max of 2 step of 1
toilet button boolean(which would normally be the light that turns on) that the toilet occupied boolean helper turns on

So when the closed door gets opened it increases the counter, when closed, increases the counter, counter hits 2 and turns on the occupied boolean which then turns on the light and when exiting if the light is on then instead of increasing the counter, it decreases and when it hits 0 it turns off the occupied boolean which turns off the light (button)

Vid for any interested

alias: Toilet Light
description: ""
triggers:
  - trigger: state
    entity_id:
      - counter.toilet_door_counter
    to: "2"
    id: counter
  - trigger: state
    entity_id:
      - input_boolean.toilet_occupied
    to: "on"
    id: occupiedon
  - type: opened
    device_id: 625eab6c43541a7f5d62ea0000000000
    entity_id: 9764fa91e429100d87cff80000000000
    domain: binary_sensor
    trigger: device
    id: dooropen
  - type: not_opened
    device_id: 625eab6c43541a7f5d620000000000
    entity_id: 9764fa91e429100d87cf0000000000
    domain: binary_sensor
    trigger: device
    id: doorclose
  - trigger: state
    entity_id:
      - counter.toilet_door_counter
    to: "0"
    id: occupiedoff
  - trigger: state
    entity_id:
      - input_boolean.toilet_occupied
    to: "off"
    id: toiletoccupiedoff
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - dooropen
              - doorclose
          - condition: state
            entity_id: input_boolean.toilet_occupied
            state: "off"
        sequence:
          - action: counter.increment
            metadata: {}
            data: {}
            target:
              entity_id: counter.toilet_door_counter
      - conditions:
          - condition: trigger
            id:
              - counter
        sequence:
          - action: input_boolean.turn_on
            target:
              entity_id:
                - input_boolean.toilet_occupied
            data: {}
      - conditions:
          - condition: trigger
            id:
              - occupiedon
        sequence:
          - action: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.toiletbutton
      - conditions:
          - condition: trigger
            id:
              - occupiedoff
        sequence:
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.toilet_occupied
      - conditions:
          - condition: trigger
            id:
              - dooropen
              - doorclose
          - condition: state
            entity_id: input_boolean.toilet_occupied
            state: "on"
        sequence:
          - action: counter.decrement
            target:
              entity_id:
                - counter.toilet_door_counter
            data: {}
      - conditions:
          - condition: trigger
            id:
              - toiletoccupiedoff
        sequence:
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.toiletbutton
mode: single

Just get a presence sensor for the bathroom and you’ll know if it’s occupied. In the scenario that someone (my son) just half-closes the door the light will still turn off after a time.

We don’t have any half door shutters but a couple of tin foil hat wearers in the extended family so none in the bathroom :laughing:

It is possible to make a presence sensor that nobody can see. I have quite a few hidden around that discreetly inform my automations and nobody ever knows as long as everything works as it is supposed to.

Got a link to one, I would be interested in small ones but in the meantime this works fine.

This tiny project is very discreet.

Ohh yeah, I was hoping for tiny camera like small, yeah the tinfoil hat wearer won’t deal with that haha. But appreciate the link for other projects!!

I have one of these in each of our bathrooms for the purpose you were wanting.

In case it didn’t make sense, I have extended family that do not like any electronics in private areas that they do not know what/how they do things. It is easier to not have objects unknown to them in there : )

Hopefully no one doubles back while exiting :joy:

Shhh lol

I may try a fp2 from another room later xD