Prioritize one automation over another with same trigger

Hi (I’m new here!),

i am a bit lost right now. Basically i am looking for a option to stop automation A from running if automation B starts running - or in other words an Option to prioritize automations that have the same triggers.

In my case i have automation A which toggles light based on movement between sunset and sunrise. That base is always on. Now automation B (i want optional) fires my nightlight and some other stuff at 1 % if motion is detected and it’s really late (23:00 - 05:00). So if B ist toggled than A should not start in the first place.

How do i achieve this? a condition?

I read a bit of a script that calls automation.turn_off but i don’t think that solves my problem because then Automation A is off forever and i want this just for the time Automation B triggers…

Sorry for the noobish question…
Thanks in advance!

So the literal answer to your question (how do I prioritize the trigger of A over B) is you can’t. That being said, that’s not the way to look at this problem.

What you have here is two automations that both trigger off of motion but each only fires when a specific other condition is met. In your case it sounds like that other condition is time of day. So add a mutually exclusive condition to each like this:

A

trigger:
  ...
condition:
  condition: time
  after: '04:59'
  before: '23:00'

B

trigger:
  ...
condition:
  condition: time
  after: '10:59'
  before: '05:00'

Now B and A don’t care what the other is doing. They just each do their thing when it’s their time.

1 Like

The other option would be to use a single automation with a choose block.

automation:
  - trigger:
      - platform: state
        entity_id: binary_sensor.motion
        to: 'on'
    action:
      - choose:
          # IF late
          - alias: "Late"
            conditions:
              - condition: time
                after: "23:00"
                before: "05:00"
            sequence:
              - service: light.turn_on
                target:
                  entity_id: light.whale
                data:
                  brightness: 5
        # ELSE (i.e., daytime)
        default:
          - service: light.turn_on
            target:
              entity_id: light.whale
            data:
              brightness: 255

Thank you for the very fast reply. Ok, i thought about that, but i failed to combine the sun condition with a time condition. So that is the code:

condition:
- condition: or
  conditions:
  - condition: sun
    after: sunset
    after_offset: !input 'sunset_offset'
  - condition: sun
    before: sunrise
    before_offset: !input 'sunrise_offset'

how do i add the time condition to this?

Conditions listed under condition are combined with and by default, so just add it like this:

condition:
- condition: or
  conditions:
  - condition: sun
    after: sunset
    after_offset: !input 'sunset_offset'
  - condition: sun
    before: sunrise
    before_offset: !input 'sunrise_offset'
- condition: time
  after: '04:59'
  before: '23:00'

This would also work in the choose block like tinkerer showed if you prefer. Although you’d need to add another choose section:

choose:
  - alias: is late
    conditions: #from 23-5 from above
    sequence: # dim lights
  - alias: is evening
    conditions: # after sunrise or before sunset
    sequence: # bright lights
default:
  # do nothing. It's daytime

Thank you very much - to both of you. Will try this out tonight!