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
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_trigger
s, 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
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
.