Kitchen Light Automation Help


I am trying to setup this kitchen light where it turn on when motion is detected and it will stay turn on until the Kitchen sensor occupancy and toilet presence sensor is not occupied.

How do I keep the sequence of

  • checking that both the kitchen and toilet sensor on human presence is cleared then it turn off the light and start a new run?

Thank you in advance

Try using helper group helper for those two sensors you want to be off.

Hello Profile - Roong - Home Assistant Community,
Welcome to the Home Assistant Forum.

Could you possibly show us your YAML so we can get a better idea what is happening?

  1. 3 dots
  2. edit in yaml
  3. copy
  4. paste here using the</> key in the post editor.

How to format code or use the</> key in the post editor.

alias: Kitchen light night auto v02
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.kitchen_sensor_occupancy
    from:
      - "off"
    to:
      - "on"
    id: sensor clear to detected
  - trigger: state
    entity_id:
      - binary_sensor.kitchen_sensor_occupancy
    id: sensor detected to clear
    from:
      - "on"
      - "off"
conditions:
  - condition: and
    conditions:
      - condition: time
        after: "00:00:00"
        before: "06:00:00"
        enabled: true
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - sensor clear to detected
        sequence:
          - type: turn_on
            device_id: 935710cd27f707d28ded0460abf523ed
            entity_id: ae545b1c0ba50f1cd920b7b7710dc9fc
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - sensor detected to clear
          - type: is_not_occupied
            condition: device
            device_id: 5534a9ffa7dde8c555aa96d9ae4e9dad
            entity_id: 8247bb7cab8c454186172b8404b481c2
            domain: binary_sensor
          - type: is_not_occupied
            condition: device
            device_id: 4595b29f3da3d808f31b4045e4bca4f9
            entity_id: 59ddc6a7ae07825d0e9d010da8690773
            domain: binary_sensor
            for:
              hours: 0
              minutes: 0
              seconds: 30
        sequence:
          - type: turn_off
            device_id: 935710cd27f707d28ded0460abf523ed
            entity_id: ae545b1c0ba50f1cd920b7b7710dc9fc
            domain: switch
mode: restart

Not sure what I wrote earlier confusing.
My idea is that when I walk into the kitchen. Light auto on. Walk into the toilet and the toilet presence sensor will trigger the toilet light to be on.

When the toilet presence sensor detect human around, the kitchen light will remain on.

When the toilet presence sensor detect no human and there is no motion in kitchen sensor, the kitchen light will turn off. I am having issues making sure the automation run a full cycle.

I think you need to break it down into more simple options and add some more triggers.

Option 1 - kitchen motion detected = kitchen light on
Option 2 - kitchen presence clear for x minutes = kitchen light off
Option 3 - toilet motion detected = toilet light on
Option 4 - toilet presence clear for x minutes = toilet light off

For Option 2, add a second condition for ‘toilet presence clear for x minutes’.

Change the mode to ‘single’.

Your “sensor detected to clear” trigger is set up incorrectly. It’s triggering both when it’s detected & when it’s clear

Instead of this:

  - trigger: state
    entity_id:
      - binary_sensor.kitchen_sensor_occupancy
    id: sensor detected to clear
    from:
      - "on"
      - "off"

It should be:

  - trigger: state
    entity_id:
      - binary_sensor.kitchen_sensor_occupancy
    id: sensor detected to clear
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 30

I also added the 30s timeout to your trigger, because you were checking that in your conditions, but conditions don’t wait for a timeout once the trigger fires.

sorry i am quite new so i not sure where to add this part in?

can you give me a full re edit of my original script?
I know maybe i am asking too much but i am really thankful and happy new year!

No, I would rather help you to figure it out by yourself so you’ll learn something new today.

  • Open up your automation and look at the top triggers part.
  • Your second trigger states: When Kitchen Sensor Occupancy changes from Detected OR Clear. Click on that.
  • Delete the “off” in that part. It’s in the wrong section (from instead of to)
  • In the TO section, select off, then set the 30s timeout there.
    You should be looking at something like this:

okay okay thank you very much


I would think this is correct?

It is indeed. Congrats on learning something new :slight_smile:

thank you so much but can i ask is the 30 sec act as a cooldown and also for a human to have a action inbetween so it will only re trigger the whole automation if it goes clear and for 30 sec?

Indeed it is.

Your previous automation was triggering immediately when it went from detected to clear. It was then checking the conditions that it was clear for 30s.

That is not how conditions work in HA. Once a trigger fires, a condition is evaluated immediately, so your condition was never met (because your sensor had only been clear for less than 1s at the time) and your automation stopped there.

Read this to learn more Automation conditions - Home Assistant

okay thank you so much for the explaination. will read thru the guide!!

1 Like