Automation Logic Help Needed

I now have an automation that will turn on an outside light when someone returns home if it’s after sunset and the light isn’t already on.

Now I would like to turn this light off after 15mins of it being turned on. I do not want to turn the light off if it was manually turned on or was turned on by another automation.

I know I can use the

  minutes: 15

to cover the if the lights been on for 15 mins.

I’m just not sure how to trigger this automation to run only after the “Return Home” automation ran successfully.

Would this work? I added a Delay action, and then a Call Service Action at the end of my working automation.

alias: Turn on Outside Lights coming home
description: >-
  Turn on the Outside lights after sunset when the lights are off and someone
  returns home.
  - platform: state
    to: home
  - condition: sun
    after: sunset
  - condition: state
    entity_id: light.holiday_wled
    state: 'off'
  - service: light.toggle
      entity_id: light.holiday_wled
      color_name: white
      effect: Solid
      transition: 15
      brightness_pct: 100
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
      entity_id: light.holiday_wled
      transition: 30
mode: single

You might like to have a look at the HACS integration Entity Controller, which is designed to do this.

Your current solution should work, unless HA restarts between the light being turned on and it being turned off, which should be a rare occurrence.

You could also start a timer within your main automation, and then have a separate automation which is triggered by the timer finishing, and turns off the light.

Yes that should work.

You can also control this with an input variable from lovelace if you want.

  - delay:
      seconds: '{{ states(''input_number.fan_runtime'')| int }}'

If your machine dies, you update automations or reboot, the automation will stop.

Thanks for the tip,
I’m using some HACS stuff, most has been great, one or two have been a terrible experience. Enough so that I’m limiting my HACS addons.

Oooooh, that sounds complicated :slight_smile:

Interesting idea,

I have a failsafe automation that turns the light off at 22:30 each night if it’s on so that sould catch any reboots.

If my machine fails, having my outside lights on is the least of my worries :slight_smile:

Timers also suffer from the same limitations as delays, for, etc. They get interrupted on HA restarts.

But to the OP…

You can block the automation from running by turning on an input Boolean with the automation. Then use the state of that Boolean being on ti be a condition to turning the light back off.