Newbie: How can I start another automation when one completes?

Newbie here. I spent lots of time searching before asking and I can’t find what I need.

I have a working automation. I need to add something at the end of it to run a different working automation.

Would that be an action? Call Service?

Short story. Outside light on at a few percent dusk to dawn. I want it o go to 100% on camera motion for say 5 minutes. When it’s done I want it to call the on at dusk automation. I have everything working as I want but I can’t automate the return to on at dusk automation.

Thanks!

You can use the automation.trigger service. See Automation Services - Home Assistant

What was said above, but to add:

Triggering another automation is really just calling a script (automation actions and scripts are the same thing, feature-wise). Is your second automation a full automation, i.e. with a trigger that can also be triggered by itself?

What might be more readable and semantically better is to put part of your second automation in a script which either automation can then call.

That said, you can also emit a custom event in one automation that another can trigger on.

It also helps to see what you have so far, because for a newbie there could be more suggestions.

1 Like

Thanks everyone for the help. The " automation.trigger service" was exactly what I needed and it works perfectly for what I need.

Thank you all!

If you’re using automation.trigger to make one automation execute another automation, you’ve structured your automations incorrectly.

The two automations should simply call a common script. Or the two automations can be consolidated, it all depends on the application.

Thanks for the reply.

My goal is to have security lights on from dusk to dawn or times that I choose. Some I will want dusk to dawn and some I will want say dusk to 10pm.

I want the lights to come on at say 10% and stay that way until it’s time to go off. If a camera picks up motion and triggers say a cross line detection the lights of my choice will go to 100% for some period of time that I chose.

I also need a way simple way to override the automation and have it or them to stay at 100% as long as I way. Say I am working in the yard or have a gathering and I want the like to stay on. I could see putting something like a simple Zigbee button to toggle an override.

Post all the separate automations you have created that implement these requirements.

So far I have not got to the point of learning how to override.

I am also new and not sure how to share an automation. I will go figure it out and I will be back.

Switch the Automation Editor from visual mode to YAML mode, copy the displayed YAML and paste it here. Then select what you pasted and click the </> icon (in the forum’s menu) to format the YAML code.

alias: Front Porch - On at Dusk
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: 40
    target:
      entity_id: light.front_porch
mode: single
alias: Front Porch - Off at Dawn
description: ""
trigger:
  - platform: sun
    event: sunrise
    offset: 0
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.front_porch
mode: single
alias: Porch Bright
description: 100% on motion
trigger:
  - platform: state
    entity_id:
      - binary_sensor.driveway_dahua_test_cross_line_alarm
    from: "off"
    to: "on"
condition:
  - condition: sun
    after: sunset
  - condition: sun
    before: sunrise
action:
  - service: light.turn_on
    data:
      brightness_pct: 100
    target:
      entity_id: light.front_porch
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: automation.trigger
    data:
      skip_condition: true
    target:
      entity_id: automation.front_porch_on_at_dusk
mode: single

Thanks!!

I assume I should have figured out how to post all of that in one reply?

Having posted this and thinking about it for a bit I may be onto something. I will take a stab at this over the weekend.

Picking up on this thread as I run into the same need and can’t find a clear answer.
I need the exact same thing - do something after an automation has ended.
I think the above from: "off" to: "on" is looking at whether or not the automation itself is active or not, and not whether its running or not.

I tried the following attribute: current without greater success:

...
trigger:
  - platform: state
    entity_id:
      - automation.the_automation_that_should_trigger_this_one_when_it_ends
    from: "1"
    to: "0"
    attribute: current
condition: []
action:
  - action: light.turn_on
...

Something tells me that there’s a more appropriate way to do it. @123 seems to know a better way but I didn’t understand his answer :slight_smile:

Is there a best practice on how to trigger one automation when another ends?

The best practice is to NOT do that.

Use scripts, to make the actions modular, and then call the scripts from the automations.

So if one automation needs to execute actions found in another automation, both should simply refer to the same script.

2 Likes