Prevent Motion Trigger to turn off light - but how?

Hi all,

How can I prevent my motion triggers to start the timer before the light gets turned off?
Few of my lights get turned on by a motion detector and then turned off after 5 minutes if no activity.

Before (in openHAB) I had a dummy switch I could use as a measurement, if the value was ON, then the turn off command could not run.
I don’t know if it makes sense, but I used the switch to turn on the light and when turned on, even if the motion got triggered, then after 5 minutes the if statement wasn’t true because the light switch was still ON and not OFF.

- alias: '[Hobbyroom] Motion/Lux Turn On Gateway LED'
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_xxxxxxxxxxxxx
    from: 'off'
    to: 'on'
  condition:
    condition: numeric_state
    entity_id: sensor.illumination_xxxxxxxxxxxxxxxxxx
    below: 100
  action:
  - service: light.turn_on
    entity_id: light.gateway_light_34ce0088ed14
    data:
      brightness: 5
      color_name: red

- alias: '[Hobbyroom] Motion/Lux Tun Off Gateway LED'
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_xxxxxxxxxxxxxxxx
    from: 'on'
    to: 'off'
    for:
      minutes: 5
  action:
  - service: light.turn_off
    entity_id: light.gateway_light_xxxxxxxxxxxxxxxxxxxxxxxxxx

Is this somehow doable?

You could define an input_boolean, which would look like a switch in the UI, and use that as a condition for your automation.

1 Like

Sounds like an idea yes!
Can you perhaps show me a few more lines of code (noob here :blush:) ?

I’m just on my phone now, so forgive me if this isn’t the exact syntax.

input_boolean:
  disable_motionsensor_automation:
    name: Disable motion sensor automation

And in your automation:

condition:
  - condition: state
    entity_id: input_boolean.disable_motionsensor_automation
    state: 'off'

Then add that input boolean to your UI somewhere.

Argh yes! Looks good.

Correct me if I’m wrong, but if I need more boolean (switches), will I just add those beneath like this?

input_boolean:
  disable_motionsensor_automation:
    name: Disable motion sensor automation
  disable_montionsensor_outdoor_automation:
    name: Disable motion sensor outdoor automation

… and so on?

I guess if you have seperate automations that you want to be able to control seperately, then yes. Otherwise you can use the same boolean to disable them all.

Hmm that will give me some small problems, because I would need more than one switch. I was hoping that I could create more booleans. One for each room where I would need it.

So both to prevent the motion trigger but also to just turn on the light on or off if manually pressed.

Sorry, I thought that’s what I was saying. You can have as many booleans as you want. However, I’m not sure if there’s a good way to tell if the light was manually switched on or turned on by your automation. It would be very dependent on your setup.

Well it was… My bad :blush:.
But was my code correct if I wanted to have more than one or does it get build up in another way?

To me it’s fine, as long as it is doable!

Thanks man!

I would look at the official documentation for it just to make sure I used the correct format: