Option to leave light on after motion detected

I use the below to turn on a light if there’s motion and then to turn it back off.

This light is in my office and there are times that I’m in the office and would like it to stay on. Is there some type of setup I could use where there’s an option to leave light on? My first/only thought is to create another automation that enables/disables a specific variable and when the below fires to check if that variable is set on/off. Thoughts?

- alias: Office Motion Light On
  trigger:
  - platform: state
    entity_id: binary_sensor.office_motion_detector_motion
    to: 'on'
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - service: homeassistant.turn_on
    entity_id: light.office_floor_lamp
    data:
      brightness_pct: 90
      transition: 2
  id: b20e6030d71c4fc2a0c77a539d0818ed
- alias: Office Motion Light Off
  trigger:
  - platform: state
    entity_id: binary_sensor.office_motion_detector_motion
    to: 'off'
  action:
  - service: homeassistant.turn_off
    entity_id: light.office_floor_lamp
    data:
      transition: 5
  id: 47e8feb202994f92b773a8d08295ae76

You could just ‘turn off’ the ‘switch off’ between certain times.

Or you could have the delay ‘adjusted’ form 5 minutes in one part of the day to 3 hours in another

I tend to have mine turn off if motion isn’t seen for a certain period of time:

- alias: Turn off sitting_room lights after movement
  initial_state: "on"
  trigger:
    - platform: state
      entity_id: binary_sensor.sitting_room_motion
      to: "off"
      for:
        minutes: 10

where I pick the duration depending on the room and how likely the sensor is not to see me when I’m actually in there…

How long does your motion sensor stay in the ‘on’ position? Most of them seem to report ‘on’ only when there is actual motion…then a lot of them go to sleep for a while then might report ‘on’ again at a later time.

If your motion detector is turning off the lights while you’re still in the office, you could change it to require it be ‘off’ for X minutes.

  trigger:
  - platform: state
    entity_id: binary_sensor.office_motion_detector_motion
    to: 'off'
    for:  
      minutes: 5

Thus, everytime it picks up movement, it will reset the 5 minute timer. It will only turn them off after 5 continuous minutes of no movement.

But even this will have its own issues. Sitting at a desk, you could easily not trigger it for X minutes. So, to answer your question:

  1. There is already a button that you have to do this. Just disable the automation.office_motion_light_off from lovelace. You can do this manually, or via other automations. Create an automation that re-enables the automation every night in case you forget to turn it back on even.

  2. Create a new input_boolean to override the ‘off’.

input_boolean:
  office_light_override:
    name: Disables auto off of motion lights while active
    icon: mdi:lightbulb

Now in your ‘off’ automation, add this as a condition

- alias: Office Motion Light Off
  trigger:
  - platform: state
    entity_id: binary_sensor.office_motion_detector_motion
    to: 'off'
  condition:
    # Will only turn off lights when this is disabled.
    condition: state
    entity_id: input_boolean.office_light_override:
    state: 'off'
  action:
  - service: homeassistant.turn_off
    entity_id: light.office_floor_lamp
    data:
      transition: 5
  id: 47e8feb202994f92b773a8d08295ae76

Then if you wanted, put an automation that checks when that turns off and have it turn of the lights.

Now you can toggle this boolean from lovelace, or from any other automation if you want to override this. But if this is all you’re going to do with the boolean, just turn off the automation when you don’t want the lights off…

1 Like

Thanks. I already have it not trigger the light during the day. I could adjust the delay at night, but it would be on longer than it needs to most often.

Thanks, though adjusting the time wouldn’t really be more effective.

Thank you. Using the boolean approach sounds the best, and kind of what I thought when mentioning a ‘variable’. Your disable the automation also gave me another idea; I use Tasker on my phone to turn on lights and PC monitors. In the same instance, I could simply disable the motion automation. I’ll work on this and report back.

So it seems you need to define what you need to happen in what circumstances so that it can be coded

I have a similar setup I my garage using a shelly. The wall switch off… 5min timeout. Wall switch on, 1hr timeout. Timeouts reset upon any switch toggle or motion active.

As I always say regarding automation… easy in nodered… not sure about the yamls.

This is good setup; unfortunately, I don’t have this particular light connected to a switch.

In the end, I decided to have the functionality integrated into my Tasker app Task I have for connecting to my computer. The Task turns off the Office Motion associated automations, and back on when I leave the office.