Help with complex automation

Hello, I hope I will explain its good but I have smart light on backyard and I have motion sensor , I made automation with the motion sensor , when I go out the light turn on and after 2 min the light turn off, so until here its easy but I have aqara button in back yard and I want to to do when I push the the button the
light off automation will not run , when I go out without push the button so light turn off auto, and if I push the button dont turn off the light until I push the button double click (I did this automation, its work).

this is the codes of my automations

this is the turn on after detect a motion

  alias: ' turn on the light auto'
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: a418e0b11233b04a399e69b1000daee3
    entity_id: binary_sensor.presence_6
    domain: binary_sensor
  condition:
  - condition: state
    entity_id: switch.sonoff_1000cabc2a
    state: 'off'
    for: 00:00
  - condition: time
    after: '16:00:00'
    before: 06:00
  action:
  - service: switch.turn_on
    target:
      entity_id:
      - switch.sonoff_1000cabc2a
      - switch.sonoff_1000c79de7
    data: {}
  mode: single

this code its turn off the light after 2 min

- id: '1644149524081'
  alias: auto turn off lights
  description: ''
  trigger:
  - platform: state
    entity_id: switch.sonoff_1000c79de7
    to: 'on'
    for:
      hours: 0
      minutes: 2
      seconds: 0
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.sonoff_1000c79de7
  mode: single

this one the code of turn on the light with push the button

- id: '1613132943329'
  alias: turn on the light button
  description: ''
  trigger:
  - device_id: d2ef117eb8b6a405e63bc0fecf5c9787
    domain: deconz
    platform: device
    type: remote_button_short_press
    subtype: turn_on
  condition: []
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.sonoff_1000c79de7
    data: {}
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.smart_led_strip
  mode: single

and this code the turn off the light with double click on button

  alias: turn off the light button
  description: ''
  trigger:
  - device_id: d2ef117eb8b6a405e63bc0fecf5c9787
    domain: deconz
    platform: device
    type: remote_button_double_press
    subtype: turn_on
  condition: []
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.sonoff_1000c79de7
    data: {}
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.smart_led_strip
  mode: single

so if someone there is a creative solution I will be happy
thank you very much!

It seems like all you need is an Input Boolean helper. Your “turn on the light auto” automation doesn’t need to be changed, but the rest need a minor modification after you create the helper.

- id: '1644149524081'
  alias: auto turn off lights
  description: ''
  trigger:
  - platform: state
    entity_id: switch.sonoff_1000c79de7
    to: 'on'
    for:
      hours: 0
      minutes: 2
      seconds: 0
  condition:
  - condition: state
    entity_id: input_boolean.allow_motion_backyard
    state: 'on'
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.sonoff_1000c79de7
  mode: single


- id: '1613132943329'
  alias: turn on the light button and disable motion
  description: ''
  trigger:
  - device_id: d2ef117eb8b6a405e63bc0fecf5c9787
    domain: deconz
    platform: device
    type: remote_button_short_press
    subtype: turn_on
  condition: []
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.sonoff_1000c79de7
    data: {}
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.smart_led_strip
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.allow_motion_backyard
  mode: single

  alias: turn off the light button and reset motion
  description: ''
  trigger:
  - device_id: d2ef117eb8b6a405e63bc0fecf5c9787
    domain: deconz
    platform: device
    type: remote_button_double_press
    subtype: turn_on
  condition: []
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.sonoff_1000c79de7
    data: {}
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.allow_motion_backyard
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.smart_led_strip
  mode: single

FWIW, often it’s a good idea to create an automation that will reset booleans you use as conditional flags just in case someone forgets to do it manually. You can do it at a specific time of day or an event such as when everyone leaves home.

1 Like

Thank you!!
I did it now and I will check it after the work.
thank you man!

its working! thank you!!

1 Like