Automation stops

Hey guys,
I’m ver new here but I’m using HA for three years now. I have the probem that some of my automation stop without a reason (attached pic). I have no idea where to looke for more information (there isn’t loged anything excapt the starting of the autionation…

Hi, welcome. A good place to start would be to include the automation.

Please read the instructions for posting at the top of each forum and post the YAML code for the automation.

And make sure you post the code in a code block.
And don’t forget to put your phone on charge

1 Like

Hi MetaStack-Exchange,

Without seeing the automation, I can say that has 5 triggers, the first trigger happened, and then control went to the condition statement. The parameters passes the condition statement. It then went to I think a choose statement and got stuck. I would look there for a problem.
If you look at some of the words in the trace you should be able to see what the automation saw, and possibly why it stalled.

Ok, I’ll try to rebuild the conditions of this behavior so that I can post the trace as well.

Now there was the chance to get more information. In this case I was able to get the trace report although it is another automation:

{
  "trace": {
    "last_step": "trigger/0",
    "run_id": "ab79f0577bb6652b6ecb830f37c38aec",
    "state": "stopped",
    "script_execution": "failed_single",
    "timestamp": {
      "start": "2024-08-18T21:02:21.504749+00:00",
      "finish": "2024-08-18T21:02:21.505606+00:00"
    },
    "domain": "automation",
    "item_id": "1660261382890",
    "trigger": "state of input_select.mediainput",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2024-08-18T21:02:21.504979+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.mediaoff",
              "state": "on",
              "attributes": {
                "id": "1660261382890",
                "last_triggered": "2024-08-18T19:39:14.852425+00:00",
                "mode": "single",
                "current": 1,
                "friendly_name": "MediaOff"
              },
              "last_changed": "2024-08-17T00:24:51.276219+00:00",
              "last_reported": "2024-08-18T19:39:14.876301+00:00",
              "last_updated": "2024-08-18T19:39:14.852594+00:00",
              "context": {
                "id": "01J5KG0FH3M4TZ543FY4HV1FVV",
                "parent_id": "01J5KG0FGZ9VSMTDKF0ETQ62B1",
                "user_id": null
              }
            },
            "trigger": {
              "id": "TV-WZ",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "input_select.mediainput",
              "from_state": {
                "entity_id": "input_select.mediainput",
                "state": "TV",
                "attributes": {
                  "options": [
                    "TV",
                    "Bluetooth",
                    "PS4",
                    "Stereoanlage",
                    "Wohnzimmer"
                  ],
                  "editable": true,
                  "icon": "mdi:form-dropdown",
                  "friendly_name": "MediaInput-Wohnzimmer"
                },
                "last_changed": "2024-08-18T19:40:11.454874+00:00",
                "last_reported": "2024-08-18T19:40:11.454874+00:00",
                "last_updated": "2024-08-18T19:40:11.454874+00:00",
                "context": {
                  "id": "01J5KG26SX4MNSEKXZMR7EP8YP",
                  "parent_id": null,
                  "user_id": "30dc538c5d524de8b6d0e74a423a50b3"
                }
              },
              "to_state": {
                "entity_id": "input_select.mediainput",
                "state": "Wohnzimmer",
                "attributes": {
                  "options": [
                    "TV",
                    "Bluetooth",
                    "PS4",
                    "Stereoanlage",
                    "Wohnzimmer"
                  ],
                  "editable": true,
                  "icon": "mdi:form-dropdown",
                  "friendly_name": "MediaInput-Wohnzimmer"
                },
                "last_changed": "2024-08-18T21:02:21.503841+00:00",
                "last_reported": "2024-08-18T21:02:21.503841+00:00",
                "last_updated": "2024-08-18T21:02:21.503841+00:00",
                "context": {
                  "id": "01J5KMRN9ZEE0T03JKVJV7V47V",
                  "parent_id": null,
                  "user_id": "30dc538c5d524de8b6d0e74a423a50b3"
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of input_select.mediainput"
            }
          }
        }
      ]
    },
    "config": {
      "id": "1660261382890",
      "alias": "MediaOff",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": [
            "input_select.mediainput"
          ],
          "to": "Wohnzimmer",
          "id": "TV-WZ",
          "from": "TV"
        },
        {
          "platform": "state",
          "entity_id": [
            "input_select.mediainput"
          ],
          "from": "Bluetooth",
          "to": "Wohnzimmer",
          "id": "BT-WZ"
        },
        {
          "platform": "state",
          "entity_id": [
            "input_select.mediainput"
          ],
          "from": "Stereoanlage",
          "to": "Wohnzimmer",
          "id": "ST-WZ"
        },
        {
          "platform": "state",
          "entity_id": [
            "input_select.mediainput"
          ],
          "id": "PS4-WZ",
          "from": "PS4",
          "to": "Wohnzimmer"
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "TV-WZ"
                }
              ],
              "sequence": [
                {
                  "parallel": [
                    {
                      "data": {},
                      "action": "script.fernsehen"
                    },
                    {
                      "if": [
                        {
                          "condition": "state",
                          "entity_id": "sun.sun",
                          "state": "below_horizon"
                        }
                      ],
                      "then": [
                        {
                          "wait_for_trigger": [
                            {
                              "platform": "device",
                              "device_id": "a8b43b179a81383a38e6049e8149d1aa",
                              "domain": "media_player",
                              "entity_id": "media_player.tv_pini",
                              "type": "turned_off"
                            }
                          ]
                        },
                        {
                          "type": "turn_off",
                          "device_id": "f78164215de1ab644eae29c6de83c29e",
                          "entity_id": "switch.steckdose_03",
                          "domain": "switch"
                        }
                      ],
                      "alias": "Steckdose Fernseher"
                    },
                    {
                      "data": {},
                      "action": "script.stehlampe_toggle_durch_mediainput_wohnzimmer"
                    }
                  ]
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "BT-WZ"
                }
              ],
              "sequence": [
                {
                  "parallel": [
                    {
                      "data": {
                        "device": "74515407",
                        "command": "PowerToggle"
                      },
                      "target": {
                        "entity_id": "remote.harmony_hub"
                      },
                      "action": "remote.send_command"
                    },
                    {
                      "if": [
                        {
                          "condition": "state",
                          "entity_id": "sun.sun",
                          "state": "below_horizon"
                        }
                      ],
                      "then": [
                        {
                          "delay": {
                            "hours": 0,
                            "minutes": 0,
                            "seconds": 2,
                            "milliseconds": 0
                          }
                        },
                        {
                          "type": "turn_off",
                          "device_id": "f78164215de1ab644eae29c6de83c29e",
                          "entity_id": "switch.steckdose_03",
                          "domain": "switch"
                        }
                      ],
                      "alias": "Steckdose Fernseher"
                    },
                    {
                      "data": {},
                      "action": "script.stehlampe_toggle_durch_mediainput_wohnzimmer"
                    }
                  ]
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "ST-WZ"
                }
              ],
              "sequence": [
                {
                  "parallel": [
                    {
                      "data": {},
                      "action": "script.stereoanlage"
                    },
                    {
                      "if": [
                        {
                          "condition": "state",
                          "entity_id": "sun.sun",
                          "state": "below_horizon"
                        }
                      ],
                      "then": [
                        {
                          "delay": {
                            "hours": 0,
                            "minutes": 0,
                            "seconds": 2,
                            "milliseconds": 0
                          }
                        },
                        {
                          "type": "turn_off",
                          "device_id": "f78164215de1ab644eae29c6de83c29e",
                          "entity_id": "switch.steckdose_03",
                          "domain": "switch"
                        }
                      ],
                      "alias": "Steckdose Fernseher"
                    },
                    {
                      "data": {},
                      "action": "script.stehlampe_toggle_durch_mediainput_wohnzimmer"
                    }
                  ]
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "PS4-WZ"
                }
              ],
              "sequence": [
                {
                  "data": {},
                  "action": "script.ps4_herunterfahren"
                },
                {
                  "parallel": [
                    {
                      "data": {},
                      "action": "script.stehlampe_toggle_durch_mediainput_wohnzimmer"
                    },
                    {
                      "if": [
                        {
                          "condition": "state",
                          "entity_id": "sun.sun",
                          "state": "below_horizon"
                        }
                      ],
                      "then": [
                        {
                          "wait_for_trigger": [
                            {
                              "platform": "device",
                              "device_id": "a8b43b179a81383a38e6049e8149d1aa",
                              "domain": "media_player",
                              "entity_id": "media_player.tv_pini",
                              "type": "turned_off"
                            }
                          ]
                        },
                        {
                          "wait_for_trigger": [
                            {
                              "platform": "state",
                              "entity_id": [
                                "media_player.playstation_4"
                              ],
                              "to": "unknown",
                              "for": {
                                "hours": 0,
                                "minutes": 0,
                                "seconds": 3
                              }
                            },
                            {
                              "platform": "state",
                              "entity_id": [
                                "media_player.playstation_4"
                              ],
                              "to": "unavailable",
                              "for": {
                                "hours": 0,
                                "minutes": 0,
                                "seconds": 3
                              }
                            }
                          ]
                        },
                        {
                          "type": "turn_off",
                          "device_id": "f78164215de1ab644eae29c6de83c29e",
                          "entity_id": "switch.steckdose_03",
                          "domain": "switch"
                        }
                      ],
                      "alias": "Steckdose Fernseher"
                    },
                    {
                      "data": {},
                      "action": "script.fernsehen"
                    }
                  ]
                }
              ]
            }
          ],
          "default": []
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01J5KMRNA0H5KDMZ31QSGMGF96",
      "parent_id": "01J5KMRN9ZEE0T03JKVJV7V47V",
      "user_id": null
    }
  },
  "logbookEntries": []
}

which includes the code, doesn’t?

No. Open the automation, click three dots top right, Edit in YAML. Copy-paste the code into the post and format it.

Ok, than this should be the missing part:

alias: MediaOff
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.mediainput
    to: Wohnzimmer
    id: TV-WZ
    from: TV
  - platform: state
    entity_id:
      - input_select.mediainput
    from: Bluetooth
    to: Wohnzimmer
    id: BT-WZ
  - platform: state
    entity_id:
      - input_select.mediainput
    from: Stereoanlage
    to: Wohnzimmer
    id: ST-WZ
  - platform: state
    entity_id:
      - input_select.mediainput
    id: PS4-WZ
    from: PS4
    to: Wohnzimmer
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: TV-WZ
        sequence:
          - parallel:
              - data: {}
                action: script.fernsehen
              - if:
                  - condition: state
                    entity_id: sun.sun
                    state: below_horizon
                then:
                  - wait_for_trigger:
                      - platform: device
                        device_id: a8b43b179a81383a38e6049e8149d1aa
                        domain: media_player
                        entity_id: media_player.tv_pini
                        type: turned_off
                  - type: turn_off
                    device_id: f78164215de1ab644eae29c6de83c29e
                    entity_id: switch.steckdose_03
                    domain: switch
                alias: Steckdose Fernseher
              - data: {}
                action: script.stehlampe_toggle_durch_mediainput_wohnzimmer
      - conditions:
          - condition: trigger
            id: BT-WZ
        sequence:
          - parallel:
              - data:
                  device: "74515407"
                  command: PowerToggle
                target:
                  entity_id: remote.harmony_hub
                action: remote.send_command
              - if:
                  - condition: state
                    entity_id: sun.sun
                    state: below_horizon
                then:
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 2
                      milliseconds: 0
                  - type: turn_off
                    device_id: f78164215de1ab644eae29c6de83c29e
                    entity_id: switch.steckdose_03
                    domain: switch
                alias: Steckdose Fernseher
              - data: {}
                action: script.stehlampe_toggle_durch_mediainput_wohnzimmer
      - conditions:
          - condition: trigger
            id: ST-WZ
        sequence:
          - parallel:
              - data: {}
                action: script.stereoanlage
              - if:
                  - condition: state
                    entity_id: sun.sun
                    state: below_horizon
                then:
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 2
                      milliseconds: 0
                  - type: turn_off
                    device_id: f78164215de1ab644eae29c6de83c29e
                    entity_id: switch.steckdose_03
                    domain: switch
                alias: Steckdose Fernseher
              - data: {}
                action: script.stehlampe_toggle_durch_mediainput_wohnzimmer
      - conditions:
          - condition: trigger
            id: PS4-WZ
        sequence:
          - data: {}
            action: script.ps4_herunterfahren
          - parallel:
              - data: {}
                action: script.stehlampe_toggle_durch_mediainput_wohnzimmer
              - if:
                  - condition: state
                    entity_id: sun.sun
                    state: below_horizon
                then:
                  - wait_for_trigger:
                      - platform: device
                        device_id: a8b43b179a81383a38e6049e8149d1aa
                        domain: media_player
                        entity_id: media_player.tv_pini
                        type: turned_off
                  - wait_for_trigger:
                      - platform: state
                        entity_id:
                          - media_player.playstation_4
                        to: unknown
                        for:
                          hours: 0
                          minutes: 0
                          seconds: 3
                      - platform: state
                        entity_id:
                          - media_player.playstation_4
                        to: unavailable
                        for:
                          hours: 0
                          minutes: 0
                          seconds: 3
                  - type: turn_off
                    device_id: f78164215de1ab644eae29c6de83c29e
                    entity_id: switch.steckdose_03
                    domain: switch
                alias: Steckdose Fernseher
              - data: {}
                action: script.fernsehen
    default: []
mode: single

Thanks for your help!

Your automation’s mode is single. That means if it is triggered while it is busy processing actions, if will ignore the trigger. In other words, it must finish its actions first before it can be triggered to run its actions again.

Your automation’s actions consist of a choose statement that executes scripts and wait_for_triggers, etc. Your trace indicates “failed_single” which means it was triggered while it was still busy executing its actions.

That’s why the trace’s flowchart is so short. It refused to proceed because it was still busy.

There are other modes such as restart, queued, and parallel. Which one you should choose depends on how you want your automation to behave when it’s triggered but hasn’t finished executing its actions from the last time it was triggered.

Reference

Modes

Ok,
but why does the automation start at all? And much more important: why isn’t the last running finish. I mean most part of the automation are commands. There is just one step where the automation must wait for the tv to turn off. But sometimes the automation doesn’t even start when I trigger it the first time of the day.

That would be because it’s still waiting.
Days is a human reference, computers don’t care about days so it just knows it’s waiting since some time ago.

I can’t think of any other reason why it would fail.
But the trace will explain why it failed.

Edit:

This is probably one of the things it’s waiting for.

                  - wait_for_trigger:
                      - platform: state
                        entity_id:
                          - media_player.playstation_4
                        to: unknown
                        for:
                          hours: 0
                          minutes: 0
                          seconds: 3
                      - platform: state
                        entity_id:
                          - media_player.playstation_4
                        to: unavailable
                        for:
                          hours: 0
                          minutes: 0
                          seconds: 3

Your asking HA to wait untill one entity has two different states at the same time for three seconds.

Edit again

I just remembered wait for trigger doesn’t have conditions, so they are or .

There is the same issue with an automation which just sends commands to my mobile phone - there is no wait-command,

Since some days I have another issue. Error: All connection attempts failed

What does this mean? - why does a connection to a script fail. The device “harmony hub” is shown as online - why can’t the automation use it?

script:

> sequence:
>   - if:
>       - condition: state
>         entity_id: input_boolean.harmonyhub_tv_wohnzimmer
>         state: "off"
>     then:
>       - device_id: ba0d5c6827f49928de3cbf896851bc9e
>         domain: select
>         entity_id: 90e7ad939e9a2915e39391fdfb845bd6
>         type: select_option
>         option: Fernsehen
>       - target:
>           entity_id: input_boolean.harmonyhub_tv_wohnzimmer
>         data: {}
>         action: input_boolean.turn_on
>     else:
>       - device_id: ba0d5c6827f49928de3cbf896851bc9e
>         domain: select
>         entity_id: 90e7ad939e9a2915e39391fdfb845bd6
>         type: select_option
>         option: power_off
>       - target:
>           entity_id: input_boolean.harmonyhub_tv_wohnzimmer
>         data: {}
>         action: input_boolean.turn_off
>   - wait_for_trigger:
>       - platform: state
>         entity_id:
>           - switch.tv_pini_screen_state
>         to: "on"
>         enabled: false
>     timeout:
>       hours: 0
>       minutes: 0
>       seconds: 5
>       milliseconds: 0
>   - data:
>       device: "74515407"
>       command:
>         - WatchTV
>     enabled: true
>     target:
>       entity_id: remote.tv_pini_remote
>     action: remote.send_command
> mode: restart
> alias: Fernsehen
> icon: mdi:television-classic

trace:

> {
>   "trace": {
>     "last_step": "sequence/2",
>     "run_id": "880325ff8cf2c0f2073006cf87ef741a",
>     "state": "stopped",
>     "script_execution": "error",
>     "timestamp": {
>       "start": "2024-09-19T19:56:48.830951+00:00",
>       "finish": "2024-09-19T19:56:56.893905+00:00"
>     },
>     "domain": "script",
>     "item_id": "fernsehen",
>     "error": "All connection attempts failed",
>     "trace": {
>       "sequence/0": [
>         {
>           "path": "sequence/0",
>           "timestamp": "2024-09-19T19:56:48.832963+00:00",
>           "changed_variables": {
>             "this": {
>               "entity_id": "script.fernsehen",
>               "state": "off",
>               "attributes": {
>                 "last_triggered": "2024-09-19T12:47:04.084031+00:00",
>                 "mode": "restart",
>                 "current": 0,
>                 "icon": "mdi:television-classic",
>                 "friendly_name": "Fernsehen"
>               },
>               "last_changed": "2024-09-19T12:47:06.038835+00:00",
>               "last_reported": "2024-09-19T12:47:06.038835+00:00",
>               "last_updated": "2024-09-19T12:47:06.038835+00:00",
>               "context": {
>                 "id": "01J8554RCFSCVK7MAC11MW28D5",
>                 "parent_id": "01J8554RCCA8NSJ5WQK0XYX9AP",
>                 "user_id": null
>               }
>             },
>             "context": {
>               "id": "01J85XP06NR02RAVGFWBARW9KP",
>               "parent_id": "01J85XP06M1H0AVNJ262EE6SF5",
>               "user_id": null
>             }
>           },
>           "result": {
>             "choice": "then"
>           }
>         }
>       ],
>       "sequence/0/if": [
>         {
>           "path": "sequence/0/if",
>           "timestamp": "2024-09-19T19:56:48.833373+00:00",
>           "result": {
>             "result": true
>           }
>         }
>       ],
>       "sequence/0/if/condition/0": [
>         {
>           "path": "sequence/0/if/condition/0",
>           "timestamp": "2024-09-19T19:56:48.833633+00:00",
>           "result": {
>             "result": true
>           }
>         }
>       ],
>       "sequence/0/if/condition/0/entity_id/0": [
>         {
>           "path": "sequence/0/if/condition/0/entity_id/0",
>           "timestamp": "2024-09-19T19:56:48.833848+00:00",
>           "result": {
>             "result": true,
>             "state": "off",
>             "wanted_state": "off"
>           }
>         }
>       ],
>       "sequence/0/then/0": [
>         {
>           "path": "sequence/0/then/0",
>           "timestamp": "2024-09-19T19:56:48.835228+00:00"
>         }
>       ],
>       "sequence/0/then/1": [
>         {
>           "path": "sequence/0/then/1",
>           "timestamp": "2024-09-19T19:56:53.777873+00:00",
>           "result": {
>             "params": {
>               "domain": "input_boolean",
>               "service": "turn_on",
>               "service_data": {},
>               "target": {
>                 "entity_id": [
>                   "input_boolean.harmonyhub_tv_wohnzimmer"
>                 ]
>               }
>             },
>             "running_script": false
>           }
>         }
>       ],
>       "sequence/1": [
>         {
>           "path": "sequence/1",
>           "timestamp": "2024-09-19T19:56:53.789388+00:00",
>           "changed_variables": {
>             "wait": {
>               "remaining": 5,
>               "trigger": null
>             }
>           },
>           "result": {
>             "wait": {
>               "remaining": 5,
>               "trigger": null
>             }
>           }
>         }
>       ],
>       "sequence/2": [
>         {
>           "path": "sequence/2",
>           "timestamp": "2024-09-19T19:56:53.790854+00:00",
>           "error": "All connection attempts failed",
>           "result": {
>             "params": {
>               "domain": "remote",
>               "service": "send_command",
>               "service_data": {
>                 "device": "74515407",
>                 "command": [
>                   "WatchTV"
>                 ],
>                 "entity_id": [
>                   "remote.tv_pini_remote"
>                 ]
>               },
>               "target": {
>                 "entity_id": [
>                   "remote.tv_pini_remote"
>                 ]
>               }
>             },
>             "running_script": false
>           }
>         }
>       ]
>     },
>     "config": {
>       "sequence": [
>         {
>           "if": [
>             {
>               "condition": "state",
>               "entity_id": "input_boolean.harmonyhub_tv_wohnzimmer",
>               "state": "off"
>             }
>           ],
>           "then": [
>             {
>               "device_id": "ba0d5c6827f49928de3cbf896851bc9e",
>               "domain": "select",
>               "entity_id": "90e7ad939e9a2915e39391fdfb845bd6",
>               "type": "select_option",
>               "option": "Fernsehen"
>             },
>             {
>               "target": {
>                 "entity_id": "input_boolean.harmonyhub_tv_wohnzimmer"
>               },
>               "data": {},
>               "action": "input_boolean.turn_on"
>             }
>           ],
>           "else": [
>             {
>               "device_id": "ba0d5c6827f49928de3cbf896851bc9e",
>               "domain": "select",
>               "entity_id": "90e7ad939e9a2915e39391fdfb845bd6",
>               "type": "select_option",
>               "option": "power_off"
>             },
>             {
>               "target": {
>                 "entity_id": "input_boolean.harmonyhub_tv_wohnzimmer"
>               },
>               "data": {},
>               "action": "input_boolean.turn_off"
>             }
>           ]
>         },
>         {
>           "wait_for_trigger": [
>             {
>               "platform": "state",
>               "entity_id": [
>                 "switch.tv_pini_screen_state"
>               ],
>               "to": "on",
>               "enabled": false
>             }
>           ],
>           "timeout": {
>             "hours": 0,
>             "minutes": 0,
>             "seconds": 5,
>             "milliseconds": 0
>           }
>         },
>         {
>           "data": {
>             "device": "74515407",
>             "command": [
>               "WatchTV"
>             ]
>           },
>           "enabled": true,
>           "target": {
>             "entity_id": "remote.tv_pini_remote"
>           },
>           "action": "remote.send_command"
>         }
>       ],
>       "mode": "restart",
>       "alias": "Fernsehen",
>       "icon": "mdi:television-classic"
>     },
>     "blueprint_inputs": null,
>     "context": {
>       "id": "01J85XP06NR02RAVGFWBARW9KP",
>       "parent_id": "01J85XP06M1H0AVNJ262EE6SF5",
>       "user_id": null
>     }
>   },
>   "logbookEntries": [
>     {
>       "state": "on",
>       "entity_id": "script.fernsehen",
>       "icon": "mdi:television-classic",
>       "when": 1726775808.8315504
>     },
>     {
>       "state": "Fernsehen",
>       "entity_id": "select.harmony_hub_activities",
>       "when": 1726775809.1076956,
>       "context_state": "on",
>       "context_entity_id": "script.fernsehen"
>     },
>     {
>       "state": "on",
>       "entity_id": "input_boolean.harmonyhub_tv_wohnzimmer",
>       "icon": "mdi:television",
>       "when": 1726775813.7806349,
>       "context_state": "on",
>       "context_entity_id": "script.fernsehen"
>     }
>   ]
> }