Toggle automation on/off with a Tag

I have a contact switch on my door to the garage. I created an automation that once the contact opens that it turns on my lights, waits 2 then turns the lights back off.
Problem is when I need to work in the garage and my family keeps going in and out of the door, it keeps turning the lights out on my.
My thought was to use an NFC tag, if I scan it once it would disable to automation, then if I scanned it again it would enable it, or if say 4 hours pass also enable it.

Thanks for the help.

It’s better to use conditional logic options to control when automations execute their actions instead of enabling or disabling the entire automation through other automations. You should reserve the option to disable automations for when you need to debug them or make large changes to how things work.

Have your scan event switch a boolean helper or set a timer through an automation or change the state of a trigger-based binary sensor. Use the state of the helper, timer, or sensor in your original automation’s conditions.

Ok so how to do go about using a condition then.
Currently I have my automation like this:
Trigger: Door sensor (State) Opened
Action:
Turn on lights
Delay: 2 minutes
Turn off lights

So I want this to be how it normally runs, what condition do I add for it to not turn off if I scan NFC tag.
Sorry still very new at this.

Create an helper switch “garage workin” And an automation that when you scan the NFC tag, it will commutare that virtual switch.

Then in your main automation in actions section add an if-then action
If “garage office” switch state is off then do the wait 2 and the switch off of the light, else do nothing.

Something like this?

description: “”
mode: single
trigger:

  • type: opened
    platform: device
    device_id: 345169dd5a3ce4032a89e9f2c81ff349
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_ad4def07_on_off
    domain: binary_sensor
    condition: []
    action:
  • type: turn_on
    device_id: 8200c0c154a334806c8e879922f68f10
    entity_id: light.sonoff_a4800296dd
    domain: light
  • if:
    • condition: state
      entity_id: input_boolean.garage_working
      attribute: “off”
      state: “”
      then:
    • delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
    • type: turn_off
      device_id: 8200c0c154a334806c8e879922f68f10
      entity_id: light.sonoff_a4800296dd
      domain: light

Create an automation to turn on when garage door is open and another one to when light is turned on for 2 minutes.
Then add the condition you created.
The second automation will execute only if the condition is true.

Avoid using delay.

I probably could have done it better, but being new to this, I’m going to count it as a win since I got it to work. Thanks for the advice about the boolean helper, that is how I got it.

Here is what I did:
I created a boolean helper
I created 1 automation to scan NFC Tab, if boolean helper was off, turn state to on.
I created a second automation to scan NFC Tag, if boolean helper was on, turn state to off.
Last automation was for my contact sensor, only work if condition boolean helper state off.

I’m sure I could make it cleaner, but it works. Thanks for the boolean helper direction, learned quite a bit about those.