Prevent automations from triggering each other

Is there a simple way to prevent automations from triggering each other?

I have a mixer and speakers and it is crucial that the speakers is turned off before the the mixer is started and that the speaker is only started when the mixer has fully booted which takes around 10 seconds, otherwise the mixer might blow out the speakers.

So I set up 2 automations.

  • The first one triggers when the mixer is turned on (It ensures the speakers are turned off, waits fro 10 seconds, then turns the speakers on)
  • The second one triggers when the mixer is turned off (It immediately turns the mixer on in an attempt to prevent it from turning off, then turns off the speakers, waits 2 seconds (which is how long the speakers need to turn off) and finally turns off the mixer.)

My issues:

  1. My second automation triggers too late. I need it to actually trigger before the mixer’s power is cut and prevent the power from cutting, then turn off the speakers, wait 2 seconds and only then the mixer should turn off.
  2. The second automation triggers itself and the first automation which would then cause an infinite loop of automations triggering each other.

Any ideas how I could solve this?

I suppose I could write scripts that take care of everything and never toggle the individual devices themselves, but that would seem like a dirty workaround.

1 Like

Can you post up the 2 automations yaml that you already have?

1 Like
alias: Speaker Crack Prevention (Turn on)
description: ''
trigger:
  - platform: device
    type: turned_on
    device_id: cc7dbeb2bfd2911db0ff5e2340aa23ac
    entity_id: switch.tasmota # MIXER
    domain: switch
condition: []
action:
  - type: turn_off
    device_id: e29e92b354f017ac4c3b181cbc899fd5
    entity_id: switch.tasmota_2 # SPEAKERS
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - type: turn_on
    device_id: e29e92b354f017ac4c3b181cbc899fd5
    entity_id: switch.tasmota_2 # SPEAKERS
    domain: switch
mode: restart

alias: Speaker Crack Prevention (Turn off)
description: ''
trigger:
  - platform: device
    type: turned_off
    device_id: cc7dbeb2bfd2911db0ff5e2340aa23ac
    entity_id: switch.tasmota # MIXER
    domain: switch
condition: []
action:
  - type: turn_on
    device_id: cc7dbeb2bfd2911db0ff5e2340aa23ac
    entity_id: switch.tasmota # MIXER
    domain: switch
  - type: turn_off
    device_id: e29e92b354f017ac4c3b181cbc899fd5
    entity_id: switch.tasmota_2 # SPEAKERS
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - type: turn_off
    device_id: cc7dbeb2bfd2911db0ff5e2340aa23ac
    entity_id: switch.tasmota # MIXER
    domain: switch
mode: restart

Ok, so would I be right in assuming the above automations are predominately used for when you manually switch these devices, ie, via the devices themselves as apposed to via home assistant?

At the moment I only turn these devices on/off manually through the UI in HA, but I will also create additional automations in the near future that turn these devices on when playing music for instance.
I don’t ever manually turn the speakers or mixer on by walking to their smart outlets and pushing their buttons.

You could set a condition in the automations to not run when the other is running.

If always controlled via HA, why not always control via a script to execute actions in the proper order.

Set it in one automation. This way you don’t have to worry about the other automation. :wink:

alias: Speaker Crack Prevention
id: Speaker Crack Prevention
trigger:
  - platform: state
    entity_id: switch.tasmota # MIXER
    to:
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: switch.tasmota
            state: 'on'
        sequence:
          - service: switch.turn_off
            entity_id: switch.tasmota_2 # SPEAKERS
          - delay: '00:00:10'
          - service: switch.turn_on
            entity_id: switch.tasmota_2 # SPEAKERS
    default:
      - service: switch.turn_on
        entity_id: switch.tasmota # MIXER
      - service: switch.turn_off
        entity_id: switch.tasmota_2 # SPEAKERS
      - delay: '00:00:02'
      - service: switch.turn_off
        entity_id: switch.tasmota # MIXER

I changed some things, if you have questions why, please let me know.

This is set with choose and default, as it seems to me, your second automation is the more important one. If this is not the case, you can set it in two other ways:

  • change the default to another choose and leave default empty
  • interchange both (choose to default and vice versa)

Thank you, but this causes an infinite loop of the mixer turning off and on again, until I disable the automation again. (All other automations have been disabled in advance.)

Your automation basically only works one time and only if speakers and mixer are turned off initially. I can then turn the mixer on, causing the speaker to turn on 10 seconds later. But when I turn the mixer off again afterwards, it just turns on and off forever.

@calisro The automation doesn’t just trigger the other automation, it also triggers itself.

@jerrm As already mentioned in the first post, it just seems like a dirty workaround. Everything in HA that may trigger the mixer in the future would have to use that script otherwise it might accidentally blow out my speakers.

That’s right, I haven’t thought of that… :rofl: As I said in another thread already, I’m not up to my game today, sorry! :slight_smile:

So we need to add the trigger state, that should work. I’ll try to come up with a change. :wink:

Whatever makes sense for you, but catching events and layering in actions seems like more trouble than just doing it in the correct order.

If you want a simple entity to turn on/off, then wrap it up into a Template Switch - Home Assistant

I was going to suggest something similar to be honest, if you have particular needs then it makes perfect sense to wrap them up in a script and simply call the script to turn them on and off in your required order.

I personally would create an input boolean (or maybe button) assuming you only ever use the mixer and speakers together then a single Boolean to replace both switches, I would even hide the two original switches and simply have one input Boolean.

Then simply create a single automation that triggers two choose actions based on the Boolean being toggled. That way you have complete control and don’t have to be turning things instantly back on which to me seems to be a little dirty!