Cannot figure out how to combine 2 automations

I have the following pair of automations that I would love to combine to streamline and eliminate an automation. For the life of me, I cannot figure out how to trigger the process. The conditions to decide actions could stay the same.

The first automation boots my Unraid backup server at a set time on a set day of the week and turns on a helper switch. Once booted unraid fires up a script to trigger the backup process.

Start automation:

alias: Unraid Backup trigger Start backup
description: Turn Backup on and end
triggers:
  - at: "02:00:00"
    trigger: time
conditions:
  - condition: time
    weekday:
      - mon
      - fri
      - sat
      - wed
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: switch.backup
            state: "off"
        sequence:
          - data: {}
            target:
              entity_id: switch.backup
            action: switch.turn_on
          - data: {}
            target:
              entity_id: input_boolean.switch_unraid_backup_auto
            action: input_boolean.turn_on
  - data:
      message: Unraid backup triggered
      title: Unraid backup started
    action: notify.mobile_app_matt_s10
mode: single

Once this process is completed, the backup has run and the drives have spun down and the power draw has dropped below 71 watts for 4 minutes on my monitored power switch the following happens… A call to the server shuts down the system via the Unraid API, the input_boolean is turned off and a notification is sent that the process is completed.

Process complete automation:

alias: Backup Unraid Backup Complete
description: Determine backups complete and shutdown
triggers:
  - entity_id:
      - sensor.tg_04_energy_power_2
    for:
      hours: 0
      minutes: 4
      seconds: 0
    below: 71
    trigger: numeric_state
conditions:
  - condition: state
    entity_id: input_boolean.switch_unraid_backup_auto
    state: "on"
actions:
  - action: button.press
    metadata: {}
    target:
      entity_id: button.backup_shutdown_system
    data: {}
  - data:
      message: Backup run completed
      title: Backup server shutdown
    action: notify.mobile_app_matt_s10
  - action: input_boolean.turn_off
    metadata: {}
    target:
      entity_id: input_boolean.switch_unraid_backup_auto
    data: {}
mode: single

So, I can still trigger on start time and day, but what I am worried about is the power draw trigger. Sometimes I have the server booted and if the drives spin down the power off criteria could be met… I could maybe use the input_boolean being off as a condition to not shut the server down, but I think the automation would still try to trigger when ever the power level is low whether it does anything or not? Am I overthinking this? Looking for suggestions.

Thanks Matt

Those look like fundamentally different automations.

If they work as expected now what would be the benefit of combining them?

Firstly, a bit of cleanup, in your first script you can combine the conditions and remove the choose so it would read:

conditions:
  - condition: time
    weekday:
      - mon
      - fri
      - sat
      - wed
  - condition: state
    entity_id: switch.backup
    state: "off"
actions:
  - data: {}
    target:
      entity_id: switch.backup
    action: switch.turn_on
...

This is because the default is to combine all of the conditions using “and” hence all conditions must be true to allow the automation to start.


When you reach the bottom of the first script you can add an additional “wait for trigger” step:

Something like this:

- wait_for_trigger:
    - entity_id:
        - sensor.tg_04_energy_power_2
      for:
        hours: 0
        minutes: 4
        seconds: 0
      below: 71
      trigger: numeric_state

You probably don’t need the “conditions” block from your second script, so you can just turn off the backup server and send the message.

PS You may also want to read the next section “Wait timeout” for details on how to handle the case that the power doesn’t drop in a set amount of time.

PPS Using a wait like this keeps the automation “active”, if you edit this automation (or reboot HA) the active automations are cancelled hence the wait_for_trigger will not be triggered (after an edit or reboot).

They do work as expected, they are also very closely related as the only control one system and walk that system through one process, a backup.

I am just trying to organize a little better as I have 145 automations and would love to combine ones that I can combine just to make the system a little leaner.

1 Like

What would you think of the idea of a time trigger and the power monitor trigger with conditions being day of week and state of boolean and then using choose actions based on the boolean condition to determine the course of action to take? I really only have 2 courses of action that need to be taken in a certain order, but the shutdown has to be taken when I am sure that the backup process has completed (drives spinning down causing lower power consumption)?

I do not like the idea of using the wait state in the automation, it feels like using the old delay, but worse to me.

I think I could work through the conditions by “and ing” the conditions required for startup and then “or ing” the conditions for shutdown?

Maybe I am just hoping for to much magic here… just looked to me like a good low hanging fruit for a combined process.

Thanks Matt

They may be related but they have completely different triggers, completely different conditions and completely different actions. So they aren’t really that related.

Sometimes people try to shoehorn automations into one big automation which becomes way more complicated to code due to all of the totally different requirements (in your case everything) requiring many different conditional branches in the actions which then it makes it way more complicated to maintain and troubleshoot.

the number of automations in your system should never be a factor in combining automations.

Automations typically have the 3 sections (Triggers, Conditions and Actions).

Ignoring conditions for a moment you can combine as many scripts as you want by:

  • Merging all the Triggers into one automation.
  • Assigning an ID to each Trigger.
  • Then using a choose to split execution (by id).
  • Taking the Actions from each script and placing them in the relevant section of the choose.

Finally you can take the original conditions and add them alongside the id condition.

It not a perfect match, but for most use cases it will work.

At the end of the day, you are always tracking state in Home Assistant, that may be:

  • The state of real devices.
  • Some external state such as time of day, current weather, …
  • Historical automation state - when a trigger last fired.
  • Explicit state such as an input boolean.
  • Derived state such as groups of sensors.
  • The state encapsulated in a running automation, including:
    • Any (captured) variables.
    • Waiting for a time period or another state change.
    • Simply the fact that the automation is running (can be considered a boolean).

In all cases, it is necessary to think about what could cause the state to change and if you care/need to handle that.

I don’t see waiting in automation as “good” or “bad” it just brings it’s own set of pro’s and con’s, that you have to be aware of and handle correctly.

Probably the most significant issue both for merging automations and waiting inside of them, is what happens if they “keep running” you have to think about what mode (Single, Queued, Restart, Parallel) would be most appropriate for your use case.

Note: Having separate automations typically has the same concern, it’s just you don’t have a choice - two separate automations can always run in parallel to each other.

The core argument you are making is KISS (Keep it simple …) which is a good principal that I agree with.

However there isn’t a single strategy that works in all cases, having a ton of almost identical automations increases the cognitive load of understanding how they all interact with each other. Pulling functionality out into blueprints or scripts buries the details of exactly what is happening. As you say making one “uber” automation results in a convoluted flow.

My rule of thumb is to merge as much as I can - as long as I can do that without introducing branching constructs (if or choose), it’s not a hard rule - sometimes having a branch is the only reasonable option **.

However for me, reducing the number of automations I need to consider does help my comprehension of whats going on.

** - I think all of my automations currently have a maximum of of one if and/or one choose - again not a hard rule, it’s just worked out that way.

This is an interesting automation build concept… A few of my automations would make you cringe! I have a couple with somewhere around 8 choose statements. For some reason they fit my old brain better that a bunch of tiny automations.

Give everything said here… maybe I will just leave this pair alone, until it makes my brain hurt again.

alias: Unraid Backup
description: Start/End Backup
triggers:
  - alias: Scheduled Start Time
    trigger: time
    at: "02:00:00"
    variables:
      is_true: "{{ now().isoweekday() in [1, 3, 5, 6] }}"
  - alias: Detected Stop Time
    trigger: numeric_state
    entity_id: sensor.tg_04_energy_power_2
    below: 71
    for:
      minutes: 4
    variables:
      is_true: "{{ is_state('input_boolean.switch_unraid_backup_auto', 'on') }}"
conditions:
  - condition: template
    value_template: "{{ is_true }}"
actions:
  - if: "{{ trigger.platform == 'numeric_state' }}"
    then:
      - action: button.press
        target:
          entity_id: button.backup_shutdown_system
      - action: notify.mobile_app_matt_s10
        data:
          message: Backup run completed
          title: Backup server shutdown
      - action: input_boolean.turn_off
        target:
          entity_id: input_boolean.switch_unraid_backup_auto
    else:
      - if: "{{ is_state('switch.backup', 'on') }}"
        then:
          - action: homeassistant.turn_on
            target:
              entity_id:
                - switch.backup
                - input_boolean.switch_unraid_backup_auto
          - action: notify.mobile_app_matt_s10
            data:
              message: Unraid backup triggered
              title: Unraid backup started
mode: single

I will try to test this in the morning… You did a couple of things in there that I would not have thought of.

I never think of testing this way…

  - if: "{{ trigger.platform == 'numeric_state' }}"

I also do not really understand using an alias. I have been with HA since around the .21 days and have not adjusted some of my ways and really need to. It always seems like life never slows down, 60 years old with a disabled wife and daughter just seems like there never is enough time to spend thinking about anything other than work and family.

I really appreciate seeing something that gives me new ideas to learn and research.

Matt

You may want to look into using variables in your scripts, cutting to the chase you can eliminate branching and many automations simply by listing everything in variables, as an example 3 automations handle my lights:

  1. Read presence sensors
  2. Read buttons (scene switches)
  3. Apply scenes

I simply update those automations to add more lights (and add scenes).

Here is an example of doing that:

Thanks for the feedback… You are more than likely correct! I think the root of all evil is that I am not a programmer. I am an optical engineer and only have minimal coding skills, most of which have been picked up on my long journey with HA. I have done a small amount of perl, bash shell, ansible and finally python. But, over a so far 36 year career that is about it. which pretty much makes me a relic and I understand that. I have very limited exposure outside of HA yaml files to lists, dictionaries and other programming constructs.

This forum and the ability to read examples of code has really improved my skills over the years here, but I may have gone an odd way in my progression.

I would love to see you examples above, I have a very complex multiple sensor, multiple button single automation to control each room that has motion sensors and operation of associated controlled outlets and bulbs… guess what it is controlled by a couple of triggers and choose with some having 7 or 8 choose statements.

What was the result of your test?

It did not work… I tested today. It appears that it does not turn on the boolean, therefore it never powers up the remote machine.

If the automation was triggered then it will produce a trace containing detailed information. Please post the contents of the automation’s trace file using the instructions in the following post.

How to download and post an automation’s trace file.

I will examine the trace file and explain why it didn’t turn on the input_boolean.

If there’s no trace file, then it means the automation never triggered.

I just set it up to trigger today at a set time and it triggered, but according to the trace graphic it did nothing…

Trace file:

{
  "trace": {
    "last_step": "action/0/if/condition/0",
    "run_id": "f8a8331ecd9e024e5851ce3397344634",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2026-02-16T22:08:00.227992+00:00",
      "finish": "2026-02-16T22:08:00.229439+00:00"
    },
    "domain": "automation",
    "item_id": "1771094498545",
    "trigger": "time",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2026-02-16T22:08:00.228048+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.unraid_backup",
              "state": "on",
              "attributes": {
                "id": "1771094498545",
                "last_triggered": "2026-02-14T18:47:03.946596+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Unraid Backup"
              },
              "last_changed": "2026-02-16T22:06:45.290075+00:00",
              "last_reported": "2026-02-16T22:06:45.290075+00:00",
              "last_updated": "2026-02-16T22:06:45.290075+00:00",
              "context": {
                "id": "01KHM7VQH99BCFVP23DBZBQJKG",
                "parent_id": null,
                "user_id": "27f8ae16b4f6454fb307be89afadb409"
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": "Scheduled Start Time",
              "platform": "time",
              "now": "2026-02-16T16:08:00.227465-06:00",
              "description": "time",
              "entity_id": null
            },
            "is_true": true
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2026-02-16T22:08:00.228093+00:00",
          "result": {
            "result": true,
            "entities": []
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2026-02-16T22:08:00.228672+00:00",
          "changed_variables": {
            "context": {
              "id": "01KHM7Y0Q360P23ET39QYT7E31",
              "parent_id": null,
              "user_id": null
            }
          }
        }
      ],
      "action/0/if": [
        {
          "path": "action/0/if",
          "timestamp": "2026-02-16T22:08:00.228900+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/if/condition/0": [
        {
          "path": "action/0/if/condition/0",
          "timestamp": "2026-02-16T22:08:00.228988+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ]
    },
    "config": {
      "id": "1771094498545",
      "alias": "Unraid Backup",
      "description": "Start/End Backup",
      "triggers": [
        {
          "alias": "Scheduled Start Time",
          "trigger": "time",
          "at": "16:08:00",
          "variables": {
            "is_true": "{{ now().isoweekday() in [0, 1, 3, 5, 6] }}"
          }
        },
        {
          "alias": "Detected Stop Time",
          "trigger": "numeric_state",
          "entity_id": "sensor.tg_04_energy_power_2",
          "below": 71,
          "for": {
            "minutes": 4
          },
          "variables": {
            "is_true": "{{ is_state('input_boolean.switch_unraid_backup_auto', 'on') }}"
          }
        }
      ],
      "conditions": [
        {
          "condition": "template",
          "value_template": "{{ is_true }}"
        }
      ],
      "actions": [
        {
          "if": [
            {
              "condition": "template",
              "value_template": "{{ trigger.platform == 'numeric_state' }}"
            }
          ],
          "then": [
            {
              "action": "button.press",
              "target": {
                "entity_id": "button.backup_shutdown_system"
              }
            },
            {
              "action": "notify.mobile_app_matt_s10",
              "data": {
                "message": "Backup run completed"
              }
            }
          ]
        }
      ]
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01KHM7Y0Q360P23ET39QYT7E31",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Unraid Backup",
      "message": "triggered by time",
      "source": "time",
      "entity_id": "automation.unraid_backup",
      "context_id": "01KHM7Y0Q360P23ET39QYT7E31",
      "domain": "automation",
      "when": 1771279680.2283454
    }
  ]
}
'''

According to the trace you posted, the actions section of your automation contains an if with a then section but it has no else section.

      "actions": [
        {
          "if": [
            {
              "condition": "template",
              "value_template": "{{ trigger.platform == 'numeric_state' }}"
            }
          ],
          "then": [
            {
              "action": "button.press",
              "target": {
                "entity_id": "button.backup_shutdown_system"
              }
            },
            {
              "action": "notify.mobile_app_matt_s10",
              "data": {
                "message": "Backup run completed"
              }
            }
          ]
        }
      ]

In the example I posted above, the if has an else section and it is responsible for turning on the switch and input_boolean. If this section is missing then it would explain why the automation did not turn them on when the Time Trigger fired.

Can you double-check your version of the automation and confirm the if contains an else section? Because the trace indicates it does not.

OMG you are correct, I highlight copied and did not use the copy button on the window and missed a section. I will give it a test asap and reply!

So, again I set it up to frigger at 2am this morning. It did trigger, but it appears to have decided the the power draw was to low on the plug and bailed… if I am reading it correctly. The second server never saw a WOL packet, thus never booted.

Trace log:

{
  "trace": {
    "last_step": "action/0/else/0/if/condition/0",
    "run_id": "86ec585bee5d5a6a1e1918cb0b77dd5a",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2026-02-17T08:00:00.098657+00:00",
      "finish": "2026-02-17T08:00:00.100335+00:00"
    },
    "domain": "automation",
    "item_id": "1771094498545",
    "trigger": "time",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2026-02-17T08:00:00.098700+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.unraid_backup",
              "state": "on",
              "attributes": {
                "id": "1771094498545",
                "last_triggered": "2026-02-16T22:08:00.228370+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Unraid Backup"
              },
              "last_changed": "2026-02-17T05:08:41.435870+00:00",
              "last_reported": "2026-02-17T05:08:41.435870+00:00",
              "last_updated": "2026-02-17T05:08:41.435870+00:00",
              "context": {
                "id": "01KHN00AAVEX9NCP5SBQS9ZDQV",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": "Scheduled Start Time",
              "platform": "time",
              "now": "2026-02-17T02:00:00.098203-06:00",
              "description": "time",
              "entity_id": null
            },
            "is_true": true
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2026-02-17T08:00:00.098735+00:00",
          "result": {
            "result": true,
            "entities": []
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2026-02-17T08:00:00.099121+00:00",
          "changed_variables": {
            "context": {
              "id": "01KHN9T032HEBXQQGH4S5BKDDW",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "choice": "else"
          }
        }
      ],
      "action/0/if": [
        {
          "path": "action/0/if",
          "timestamp": "2026-02-17T08:00:00.099324+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/if/condition/0": [
        {
          "path": "action/0/if/condition/0",
          "timestamp": "2026-02-17T08:00:00.099392+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "action/0/else/0": [
        {
          "path": "action/0/else/0",
          "timestamp": "2026-02-17T08:00:00.099728+00:00"
        }
      ],
      "action/0/else/0/if": [
        {
          "path": "action/0/else/0/if",
          "timestamp": "2026-02-17T08:00:00.099863+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/else/0/if/condition/0": [
        {
          "path": "action/0/else/0/if/condition/0",
          "timestamp": "2026-02-17T08:00:00.099920+00:00",
          "result": {
            "result": false,
            "entities": [
              "switch.backup"
            ]
          }
        }
      ]
    },
    "config": {
      "id": "1771094498545",
      "alias": "Unraid Backup",
      "description": "Start/End Backup",
      "triggers": [
        {
          "alias": "Scheduled Start Time",
          "trigger": "time",
          "at": "02:00:00",
          "variables": {
            "is_true": "{{ now().isoweekday() in [1, 2, 3, 5, 6] }}"
          }
        },
        {
          "alias": "Detected Stop Time",
          "trigger": "numeric_state",
          "entity_id": "sensor.tg_04_energy_power_2",
          "below": 71,
          "for": {
            "minutes": 4
          },
          "variables": {
            "is_true": "{{ is_state('input_boolean.switch_unraid_backup_auto', 'on') }}"
          }
        }
      ],
      "conditions": [
        {
          "condition": "template",
          "value_template": "{{ is_true }}"
        }
      ],
      "actions": [
        {
          "if": [
            {
              "condition": "template",
              "value_template": "{{ trigger.platform == 'numeric_state' }}"
            }
          ],
          "then": [
            {
              "action": "button.press",
              "target": {
                "entity_id": "button.backup_shutdown_system"
              }
            },
            {
              "action": "notify.mobile_app_matt_s10",
              "data": {
                "message": "Backup run completed",
                "title": "Backup server shutdown"
              }
            },
            {
              "action": "input_boolean.turn_off",
              "target": {
                "entity_id": "input_boolean.switch_unraid_backup_auto"
              }
            }
          ],
          "else": [
            {
              "if": [
                {
                  "condition": "template",
                  "value_template": "{{ is_state('switch.backup', 'on') }}"
                }
              ],
              "then": [
                {
                  "action": "homeassistant.turn_on",
                  "target": {
                    "entity_id": [
                      "switch.backup",
                      "input_boolean.switch_unraid_backup_auto"
                    ]
                  }
                },
                {
                  "action": "notify.mobile_app_matt_s10",
                  "data": {
                    "message": "Unraid backup triggered",
                    "title": "Unraid backup started"
                  }
                }
              ]
            }
          ]
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01KHN9T032HEBXQQGH4S5BKDDW",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Unraid Backup",
      "message": "triggered by time",
      "source": "time",
      "entity_id": "automation.unraid_backup",
      "context_id": "01KHN9T032HEBXQQGH4S5BKDDW",
      "domain": "automation",
      "when": 1771315200.0989394
    }
  ]
}