Script doesn't execute when invoked by 1 triggered automation

I hope I’m just being dumb, I have a couple sequences that start with one of multiple automations that all end up calling one script that calls another script. The whole sequence used to work perfectly, and still does in most case than in one it particular. It works when:

  1. I manually execute the actions of the starting automation that runs the script that runs the final script.
  2. I manually run the intermediate script that runs the final script.
  3. I manually run the final script.
  4. Other automations that call the intermediate script then the final script work automatically and manually through the final script.

However, it doesn’t work when the one automation auto-triggers, which successfully executes the intermediate script and the fails to run the final script.

I’ve been scratching my head and looking through traces and haven’t found anything that could possibly explain why it doesn’t execute in the specific case. Any ideas what could be the case causing this particular scenario not working and how to fix it?

This is the original triggering automation:

alias: Sunset
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition: []
action:
  ...
  - service: script.turn_on
    data: {}
    target:
      entity_id: script.festive_lights
  ...
mode: single

This is the intermediate script it calls successfully:

alias: Festive Lights
sequence:
  - choose:
      ...
    default:
      - service: script.turn_on
        data: {}
        target:
          entity_id: script.flood_lights_default_color
mode: restart
icon: mdi:string-lights

And this is the final script, the one that only fails when the chain starts from the automation above:

alias: Flood Lights Default Color
sequence:
  - service: light.turn_on
    data:
      kelvin: 2700
      brightness_pct: 100
    target:
      entity_id:
        - light.frontyard_flood_lights
        - light.backyard_flood_lights
mode: restart
icon: mdi:light-flood-up

Meanwhile, if the automation that starts it all is this one, it gets to the end successfully:

alias: Home Day Start
trigger:
  - platform: time
    at: "06:00:00"
condition: []
action:
  ...
  - if:
      - condition: state
        entity_id: sun. Sun
        state: below_horizon
    then:
      - service: script.turn_on
        data: {}
        target:
          entity_id: script.festive_lights
mode: single

For some extra context, when the script doesn’t execute, I get “Flood Lights Default Color” trace saying:
running_script: false

The user_id is only there because you have manually triggered it - it is YOUR user id, so that the lockbook can say it was triggered manually, by you.

Automations obviously don’t have a user id.

You need to post the actual code of the automation so we can see if we can spot what is not working.

1 Like

Thank you very much for the information. At least TIL about the user_id. Given my original post doesn’t make sense (thanks to what you explained), I went ahead and edited my post with the information you requested. Thanks again, I hope the new info helps deciphering this.

The YAML you omitted: are there any checks (more choose, if or condition blocks) that checks something regarding previous execution step?

Are you sure the automation modes are what you want? I see some are specified as single, so if some of the other ones restart (as you have it), it may cause race conditions.

Can you post the full JSON trace for the problematic automation?

Lastly, note that scripts can be invoked in two ways. Using the turn on service is a non-blocking call, meaning the automation will not wait for it to finish. This could be problematic given my point on your automation modes above. If you want to block (wait), use service: script.<script_name>.

The parts that I omitted was to simplify reading. They are other paths completely separated from this path. As I mentioned, it starts in the automation, triggers the first script and then doesn’t run the second one.

Given what the script is doing, I intentionally picked the turn on option so it could just trigger and continue. I don’t see how that could be problematic here as the problem seems to be on the receiving end.

The scripts and automation used to be single and working for over a year. When it stopped working suddenly, changing to restart was one of the ways I thought to see if that would work around running_script: false. Even if there was a race condition (which there isn’t, there’s only 1 sunset :slight_smile: ), then the final script should still at least execute once, which it doesn’t.

Here you go with the full untouched automations and scripts:

alias: Sunset
description: Run at sunset
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition: []
action:
  - service: scene.turn_on
    data: {}
    target:
      entity_id: scene.shades_privacy
  - service: script.turn_on
    data: {}
    target:
      entity_id: script.festive_lights
  - service: light.turn_on
    data: {}
    target:
      entity_id:
        - light.foyer_light
        - light.arcade_light
        - light.pac_man_light
        - light.lego_light
        - light.desk_light
  - service: media_player.volume_set
    data:
      volume_level: 0.3
    target:
      entity_id: media_player.bathroom_echo
  - service: media_player.play_media
    data:
      media_content_type: custom
      media_content_id: Set brightness to 5
    target:
      entity_id: media_player.bathroom_echo
mode: single
alias: Home Day Start
description: What happens in the house regularly in the mornings independently from sunrise
trigger:
  - platform: time
    at: "06:00:00"
condition: []
action:
  - service: script.turn_on
    data: {}
    target:
      entity_id: script.shower_time
  - service: zwave_js.set_config_parameter
    data:
      parameter: "3"
      value: "0"
    target:
      device_id: "{{ device_id('light.bedroom_light') }}"
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.bedroom_tablet_motion_detection
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id: media_player.bathroom_echo
  - if:
      - condition: state
        entity_id: sun. Sun
        state: below_horizon
    then:
      - service: script.turn_on
        data: {}
        target:
          entity_id: script.festive_lights
mode: single
alias: Festive Lights
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: calendar.united_states_wa
            state: "on"
          - condition: or
            conditions:
              - condition: state
                entity_id: calendar.united_states_wa
                attribute: message
                state: New Year's Day
              - condition: state
                entity_id: calendar.united_states_wa
                attribute: message
                state: Memorial Day
              - condition: state
                entity_id: calendar.united_states_wa
                attribute: message
                state: Independence Day
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.usa
            metadata: {}
      - conditions:
          - condition: template
            value_template: "{{ now().month == 3 and now().day == 17 }}"
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.saint_patrick_s_day
            metadata: {}
      - conditions:
          - condition: template
            value_template: "{{ now().month == 10 }}"
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.halloween
            metadata: {}
      - conditions:
          - condition: template
            value_template: "{{ now().month == 12 }}"
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.christmas
            metadata: {}
    default:
      - service: script.turn_on
        data: {}
        target:
          entity_id: script.flood_lights_default_color
mode: restart
icon: mdi:string-lights
alias: Flood Lights Default Color
sequence:
  - service: light.turn_on
    data:
      kelvin: 2700
      brightness_pct: 100
    target:
      entity_id:
        - light.frontyard_flood_lights
        - light.backyard_flood_lights
mode: restart
icon: mdi:light-flood-up

I like the idea of different morning scenes on specific days. Think I will implement this.

You mention other automations. To eliminate a race condition, try queue mode on the scripts and examine the log afterwards. This will show double triggering

Sure, but we here don’t know whether you might be calling the same scripts from elsewhere. Often, things would be in scripts for reuse.

I had to ask, since often we ommit things that doesn’t seem important, but could be.

That wasn’t evident from your first post, but good to know this is intentional.

Did you upgrade HA in between? From which version to which? There was the 2023.8 release that had some changes regarding the restart mode: 2023.8: (Some) Automations stopped working · Issue #97721.

Can we also see the full trace for the problematic automation/script?

Thank you for helping here Pieter, I’m not judging, just trying to clarify as much as possible. Your suggestions are some good points to troubleshoot.

I just confirmed that the 2 automations mentioned previously are the only 2 that call festive lights script, which is the only source that calls flood lights default color (the not executing script). Given one is around sunrise and the other one around sunset, and none of the scripts has either a loop or a queue mode (they were all originally “single” mode when the issue started happening), I really don’t think mutiple calls are at play here.

I upgraded HA indeed. I usually upgrade within a couple days of release. So I was all good down to 2023.12 (and I’d evcen say 2024.1) given I only started having this issue a week or so ago.

About the traces, I confirmed that Sunset automation successfully ran yesterday and today at expected times, no other executions; same for festive lights, only this morning triggered by the home day start automation and this sunset… So all as expected and without multiple execution attempts. Finally, the flood lights default color script was also only triggered once this morning and once this sunset, as expected… However, as reported, the one from sunset just didn’t work.

BTW, the one extra thing that I meant to report from my initial post (but I got it wrong as I focused on the item_id) is that whenever the script executes correctly, there’s a child_id section, while whenever it doesn’t (when it comes automatically triggered from sunset/festive lights) then it has no child_id.

Here are the full traces for the sunset automation => festive lights script => flood lights default color script sequence:

1 Like

trace automation.sunset 2024-01-28T01_02_11.514111+00_00.json

{
  "trace": {
    "last_step": "action/4",
    "run_id": "ed3949728c8df0563ae0b908b5bb80d4",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-01-28T01:02:11.514111+00:00",
      "finish": "2024-01-28T01:02:22.389679+00:00"
    },
    "domain": "automation",
    "item_id": "1632206235644",
    "trigger": "sunset",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2024-01-28T01:02:11.514160+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.sunset",
              "state": "on",
              "attributes": {
                "id": "1632206235644",
                "last_triggered": "2024-01-27T01:00:39.085595+00:00",
                "mode": "single",
                "current": 0,
                "icon": "hass:weather-sunset-down",
                "friendly_name": "Sunset"
              },
              "last_changed": "2024-01-24T05:33:09.328619+00:00",
              "last_updated": "2024-01-27T01:00:40.383554+00:00",
              "context": {
                "id": "01HN46XMSDQGR1VRC6W13QVTQM",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "sun",
              "event": "sunset",
              "offset": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 0
              },
              "description": "sunset"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-01-28T01:02:11.514792+00:00",
          "changed_variables": {
            "context": {
              "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "scene",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "scene.shades_privacy"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/0/0": [
        {
          "path": "action/0/0",
          "timestamp": "2024-01-28T01:02:11.516901+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "cover.bedroom_back_bottom_shade",
              "state": "closed",
              "attributes": {
                "current_position": 0,
                "device_class": "shade",
                "friendly_name": "Bedroom Back Bottom Shade",
                "supported_features": 7
              },
              "last_changed": "2024-01-28T01:02:11.518486+00:00",
              "last_updated": "2024-01-28T01:02:11.518486+00:00",
              "context": {
                "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
                "parent_id": null,
                "user_id": null
              }
            }
          },
          "result": {
            "params": {
              "domain": "input_number",
              "service": "set_value",
              "service_data": {
                "value": 0,
                "entity_id": [
                  "input_number.bedroom_back_bottom_shade"
                ]
              },
              "target": {
                "entity_id": [
                  "input_number.bedroom_back_bottom_shade"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/0/0/0": [
        {
          "path": "action/0/0/0",
          "timestamp": "2024-01-28T01:02:11.517061+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "cover.bedroom_back_top_shade",
              "state": "open",
              "attributes": {
                "current_position": 45,
                "device_class": "shade",
                "friendly_name": "Bedroom Back Top Shade",
                "supported_features": 7
              },
              "last_changed": "2024-01-28T09:20:13.937282+00:00",
              "last_updated": "2024-01-28T09:20:13.937282+00:00",
              "context": {
                "id": "01HN7NX4396FMDP9K5WXXXFC95",
                "parent_id": null,
                "user_id": "94bead1a9bc84841b1a30aecee97c504"
              }
            },
            "position": 45
          },
          "result": {
            "params": {
              "domain": "input_number",
              "service": "set_value",
              "service_data": {
                "value": 45,
                "entity_id": [
                  "input_number.bedroom_back_top_shade"
                ]
              },
              "target": {
                "entity_id": [
                  "input_number.bedroom_back_top_shade"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/0/0/0/0": [
        {
          "path": "action/0/0/0/0",
          "timestamp": "2024-01-28T01:02:11.517223+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "cover.bathroom_bottom_shade",
              "state": "closed",
              "attributes": {
                "current_position": 0,
                "device_class": "shade",
                "friendly_name": "Bathroom Bottom Shade",
                "supported_features": 7
              },
              "last_changed": "2024-01-28T01:02:11.518784+00:00",
              "last_updated": "2024-01-28T01:02:11.518784+00:00",
              "context": {
                "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
                "parent_id": null,
                "user_id": null
              }
            }
          },
          "result": {
            "params": {
              "domain": "input_number",
              "service": "set_value",
              "service_data": {
                "value": 0,
                "entity_id": [
                  "input_number.bathroom_bottom_shade"
                ]
              },
              "target": {
                "entity_id": [
                  "input_number.bathroom_bottom_shade"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/0/0/0/0/0": [
        {
          "path": "action/0/0/0/0/0",
          "timestamp": "2024-01-28T01:02:11.517332+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "cover.bathroom_top_shade",
              "state": "open",
              "attributes": {
                "current_position": 55,
                "device_class": "shade",
                "friendly_name": "Bathroom Top Shade",
                "supported_features": 7
              },
              "last_changed": "2024-01-28T09:20:13.937481+00:00",
              "last_updated": "2024-01-28T09:20:13.937481+00:00",
              "context": {
                "id": "01HN7NX4396FMDP9K5WXXXFC95",
                "parent_id": null,
                "user_id": "94bead1a9bc84841b1a30aecee97c504"
              }
            },
            "position": 55
          },
          "result": {
            "params": {
              "domain": "input_number",
              "service": "set_value",
              "service_data": {
                "value": 55,
                "entity_id": [
                  "input_number.bathroom_top_shade"
                ]
              },
              "target": {
                "entity_id": [
                  "input_number.bathroom_top_shade"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2024-01-28T01:02:11.519741+00:00",
          "child_id": {
            "domain": "script",
            "item_id": "festive_lights",
            "run_id": "975c171b56298dc3f64b1c504e9ef059"
          },
          "result": {
            "params": {
              "domain": "script",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "script.festive_lights"
                ]
              }
            },
            "running_script": true
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2024-01-28T01:02:11.520558+00:00",
          "result": {
            "params": {
              "domain": "light",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "light.foyer_light",
                  "light.arcade_light",
                  "light.pac_man_light",
                  "light.lego_light",
                  "light.desk_light"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2024-01-28T01:02:22.178573+00:00",
          "result": {
            "params": {
              "domain": "media_player",
              "service": "volume_set",
              "service_data": {
                "volume_level": 0.3,
                "entity_id": [
                  "media_player.bathroom_echo"
                ]
              },
              "target": {
                "entity_id": [
                  "media_player.bathroom_echo"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/4": [
        {
          "path": "action/4",
          "timestamp": "2024-01-28T01:02:22.388052+00:00",
          "result": {
            "params": {
              "domain": "media_player",
              "service": "play_media",
              "service_data": {
                "media_content_type": "custom",
                "media_content_id": "Set brightness to 5",
                "entity_id": [
                  "media_player.bathroom_echo"
                ]
              },
              "target": {
                "entity_id": [
                  "media_player.bathroom_echo"
                ]
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1632206235644",
      "alias": "Sunset",
      "description": "Run at sunset",
      "trigger": [
        {
          "platform": "sun",
          "event": "sunset",
          "offset": 0
        }
      ],
      "condition": [],
      "action": [
        {
          "service": "scene.turn_on",
          "data": {},
          "target": {
            "entity_id": "scene.shades_privacy"
          }
        },
        {
          "service": "script.turn_on",
          "data": {},
          "target": {
            "entity_id": "script.festive_lights"
          }
        },
        {
          "service": "light.turn_on",
          "data": {},
          "target": {
            "entity_id": [
              "light.foyer_light",
              "light.arcade_light",
              "light.pac_man_light",
              "light.lego_light",
              "light.desk_light"
            ]
          }
        },
        {
          "service": "media_player.volume_set",
          "data": {
            "volume_level": 0.3
          },
          "target": {
            "entity_id": "media_player.bathroom_echo"
          }
        },
        {
          "service": "media_player.play_media",
          "data": {
            "media_content_type": "custom",
            "media_content_id": "Set brightness to 5"
          },
          "target": {
            "entity_id": "media_player.bathroom_echo"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Sunset",
      "message": "triggered by sunset",
      "source": "sunset",
      "entity_id": "automation.sunset",
      "context_id": "01HN6SD61T6KC7WGKBQPT8CSCF",
      "when": 1706403731.514198,
      "domain": "automation"
    },
    {
      "when": 1706403731.515313,
      "state": "2024-01-28T01:02:11.515288+00:00",
      "entity_id": "scene.shades_privacy",
      "icon": "mdi:roller-shade-closed",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.517835,
      "state": "Privacy",
      "entity_id": "input_select.shades_scene",
      "icon": "mdi:roller-shade",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.517957,
      "state": "0.0",
      "entity_id": "input_number.bedroom_back_bottom_shade",
      "icon": "mdi:roller-shade-closed",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.518033,
      "state": "45.0",
      "entity_id": "input_number.bedroom_back_top_shade",
      "icon": "mdi:roller-shade",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.518086,
      "state": "0.0",
      "entity_id": "input_number.bathroom_bottom_shade",
      "icon": "mdi:roller-shade-closed",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.518136,
      "state": "55.0",
      "entity_id": "input_number.bathroom_top_shade",
      "icon": "mdi:roller-shade",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.518486,
      "state": "closed",
      "entity_id": "cover.bedroom_back_bottom_shade",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.51865,
      "state": "open",
      "entity_id": "cover.bedroom_back_top_shade",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.518784,
      "state": "closed",
      "entity_id": "cover.bathroom_bottom_shade",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.518906,
      "state": "open",
      "entity_id": "cover.bathroom_top_shade",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "name": "Festive Lights",
      "message": "started",
      "entity_id": "script.festive_lights",
      "context_id": "01HN6SD61T6KC7WGKBQPT8CSCF",
      "when": 1706403731.519933,
      "domain": "script",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.520087,
      "state": "on",
      "entity_id": "script.festive_lights",
      "icon": "mdi:string-lights",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "name": "Flood Lights Default Color",
      "message": "started",
      "entity_id": "script.flood_lights_default_color",
      "context_id": "01HN6SD61T6KC7WGKBQPT8CSCF",
      "when": 1706403731.52095,
      "domain": "script",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.521092,
      "state": "on",
      "entity_id": "script.flood_lights_default_color",
      "icon": "mdi:light-flood-up",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.526204,
      "state": "off",
      "entity_id": "script.festive_lights",
      "icon": "mdi:string-lights",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.649734,
      "state": "on",
      "entity_id": "light.foyer_light",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.650409,
      "state": "on",
      "entity_id": "light.first_floor_lights",
      "icon": "mdi:lightbulb-group",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.650924,
      "state": "on",
      "entity_id": "light.indoor_lights",
      "icon": "mdi:lightbulb-group",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403731.651569,
      "state": "on",
      "entity_id": "light.all_lights",
      "icon": "mdi:lightbulb-group",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    },
    {
      "when": 1706403732.003142,
      "state": "off",
      "entity_id": "script.flood_lights_default_color",
      "icon": "mdi:light-flood-up",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Sunset",
      "context_message": "triggered by sunset",
      "context_source": "sunset",
      "context_entity_id": "automation.sunset"
    }
  ]
}

trace script.festive_lights 2024-01-28T01_02_11.519978+00_00.json

{
  "trace": {
    "last_step": "sequence/0/default/0",
    "run_id": "975c171b56298dc3f64b1c504e9ef059",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-01-28T01:02:11.519978+00:00",
      "finish": "2024-01-28T01:02:11.526591+00:00"
    },
    "domain": "script",
    "item_id": "festive_lights",
    "trace": {
      "sequence/0": [
        {
          "path": "sequence/0",
          "timestamp": "2024-01-28T01:02:11.520226+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "script.festive_lights",
              "state": "off",
              "attributes": {
                "last_triggered": "2024-01-27T14:00:09.242236+00:00",
                "mode": "restart",
                "current": 0,
                "icon": "mdi:string-lights",
                "friendly_name": "Festive Lights"
              },
              "last_changed": "2024-01-27T14:00:09.247923+00:00",
              "last_updated": "2024-01-27T14:00:09.247923+00:00",
              "context": {
                "id": "01HN5KGP3A8T7PDPYZVSYN56F9",
                "parent_id": null,
                "user_id": null
              }
            },
            "context": {
              "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "choice": "default"
          }
        }
      ],
      "sequence/0/choose/0": [
        {
          "path": "sequence/0/choose/0",
          "timestamp": "2024-01-28T01:02:11.520249+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "sequence/0/choose/0/conditions/0": [
        {
          "path": "sequence/0/choose/0/conditions/0",
          "timestamp": "2024-01-28T01:02:11.520258+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "sequence/0/choose/0/conditions/0/entity_id/0": [
        {
          "path": "sequence/0/choose/0/conditions/0/entity_id/0",
          "timestamp": "2024-01-28T01:02:11.520266+00:00",
          "result": {
            "result": false,
            "state": "off",
            "wanted_state": "on"
          }
        }
      ],
      "sequence/0/choose/1": [
        {
          "path": "sequence/0/choose/1",
          "timestamp": "2024-01-28T01:02:11.520288+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "sequence/0/choose/1/conditions/0": [
        {
          "path": "sequence/0/choose/1/conditions/0",
          "timestamp": "2024-01-28T01:02:11.520294+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "sequence/0/choose/2": [
        {
          "path": "sequence/0/choose/2",
          "timestamp": "2024-01-28T01:02:11.520353+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "sequence/0/choose/2/conditions/0": [
        {
          "path": "sequence/0/choose/2/conditions/0",
          "timestamp": "2024-01-28T01:02:11.520359+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "sequence/0/choose/3": [
        {
          "path": "sequence/0/choose/3",
          "timestamp": "2024-01-28T01:02:11.520391+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "sequence/0/choose/3/conditions/0": [
        {
          "path": "sequence/0/choose/3/conditions/0",
          "timestamp": "2024-01-28T01:02:11.520397+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "sequence/0/default/0": [
        {
          "path": "sequence/0/default/0",
          "timestamp": "2024-01-28T01:02:11.520687+00:00",
          "child_id": {
            "domain": "script",
            "item_id": "flood_lights_default_color",
            "run_id": "bb42411939fbc26d7fbf4b4911603bab"
          },
          "result": {
            "params": {
              "domain": "script",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "script.flood_lights_default_color"
                ]
              }
            },
            "running_script": true
          }
        }
      ]
    },
    "config": {
      "alias": "Festive Lights",
      "sequence": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "calendar.united_states_wa",
                  "state": "on"
                },
                {
                  "condition": "or",
                  "conditions": [
                    {
                      "condition": "state",
                      "entity_id": "calendar.united_states_wa",
                      "attribute": "message",
                      "state": "New Year's Day"
                    },
                    {
                      "condition": "state",
                      "entity_id": "calendar.united_states_wa",
                      "attribute": "message",
                      "state": "Memorial Day"
                    },
                    {
                      "condition": "state",
                      "entity_id": "calendar.united_states_wa",
                      "attribute": "message",
                      "state": "Independence Day"
                    }
                  ]
                }
              ],
              "sequence": [
                {
                  "service": "scene.turn_on",
                  "target": {
                    "entity_id": "scene.usa"
                  },
                  "metadata": {}
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "template",
                  "value_template": "{{ now().month == 3 and now().day == 17 }}"
                }
              ],
              "sequence": [
                {
                  "service": "scene.turn_on",
                  "target": {
                    "entity_id": "scene.saint_patrick_s_day"
                  },
                  "metadata": {}
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "template",
                  "value_template": "{{ now().month == 10 }}"
                }
              ],
              "sequence": [
                {
                  "service": "scene.turn_on",
                  "target": {
                    "entity_id": "scene.halloween"
                  },
                  "metadata": {}
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "template",
                  "value_template": "{{ now().month == 12 }}"
                }
              ],
              "sequence": [
                {
                  "service": "scene.turn_on",
                  "target": {
                    "entity_id": "scene.christmas"
                  },
                  "metadata": {}
                }
              ]
            }
          ],
          "default": [
            {
              "service": "script.turn_on",
              "data": {},
              "target": {
                "entity_id": "script.flood_lights_default_color"
              }
            }
          ]
        }
      ],
      "mode": "restart",
      "icon": "mdi:string-lights"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "when": 1706403731.520087,
      "state": "on",
      "entity_id": "script.festive_lights",
      "icon": "mdi:string-lights"
    },
    {
      "name": "Flood Lights Default Color",
      "message": "started",
      "entity_id": "script.flood_lights_default_color",
      "context_id": "01HN6SD61T6KC7WGKBQPT8CSCF",
      "when": 1706403731.52095,
      "domain": "script",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    },
    {
      "when": 1706403731.521092,
      "state": "on",
      "entity_id": "script.flood_lights_default_color",
      "icon": "mdi:light-flood-up",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    },
    {
      "when": 1706403731.526204,
      "state": "off",
      "entity_id": "script.festive_lights",
      "icon": "mdi:string-lights",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    },
    {
      "when": 1706403731.649734,
      "state": "on",
      "entity_id": "light.foyer_light",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    },
    {
      "when": 1706403731.650409,
      "state": "on",
      "entity_id": "light.first_floor_lights",
      "icon": "mdi:lightbulb-group",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    },
    {
      "when": 1706403731.650924,
      "state": "on",
      "entity_id": "light.indoor_lights",
      "icon": "mdi:lightbulb-group",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    },
    {
      "when": 1706403731.651569,
      "state": "on",
      "entity_id": "light.all_lights",
      "icon": "mdi:lightbulb-group",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    },
    {
      "when": 1706403732.003142,
      "state": "off",
      "entity_id": "script.flood_lights_default_color",
      "icon": "mdi:light-flood-up",
      "context_state": "on",
      "context_entity_id": "script.festive_lights"
    }
  ]
}

trace script.flood_lights_default_color 2024-01-28T01_02_11.521009+00_00.json

{
  "trace": {
    "last_step": "sequence/0",
    "run_id": "bb42411939fbc26d7fbf4b4911603bab",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-01-28T01:02:11.521009+00:00",
      "finish": "2024-01-28T01:02:12.003653+00:00"
    },
    "domain": "script",
    "item_id": "flood_lights_default_color",
    "trace": {
      "sequence/0": [
        {
          "path": "sequence/0",
          "timestamp": "2024-01-28T01:02:11.521716+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "script.flood_lights_default_color",
              "state": "off",
              "attributes": {
                "last_triggered": "2024-01-27T14:00:09.244479+00:00",
                "mode": "restart",
                "current": 0,
                "icon": "mdi:light-flood-up",
                "friendly_name": "Flood Lights Default Color"
              },
              "last_changed": "2024-01-27T14:00:10.823448+00:00",
              "last_updated": "2024-01-27T14:00:10.823448+00:00",
              "context": {
                "id": "01HN5KGP3A8T7PDPYZVSYN56F9",
                "parent_id": null,
                "user_id": null
              }
            },
            "context": {
              "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "light",
              "service": "turn_on",
              "service_data": {
                "kelvin": 2700,
                "brightness_pct": 100,
                "entity_id": [
                  "light.frontyard_flood_lights",
                  "light.backyard_flood_lights"
                ]
              },
              "target": {
                "entity_id": [
                  "light.frontyard_flood_lights",
                  "light.backyard_flood_lights"
                ]
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "alias": "Flood Lights Default Color",
      "sequence": [
        {
          "service": "light.turn_on",
          "data": {
            "kelvin": 2700,
            "brightness_pct": 100
          },
          "target": {
            "entity_id": [
              "light.frontyard_flood_lights",
              "light.backyard_flood_lights"
            ]
          }
        }
      ],
      "mode": "restart",
      "icon": "mdi:light-flood-up"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HN6SD61T6KC7WGKBQPT8CSCF",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "when": 1706403731.521092,
      "state": "on",
      "entity_id": "script.flood_lights_default_color",
      "icon": "mdi:light-flood-up"
    },
    {
      "when": 1706403731.526204,
      "state": "off",
      "entity_id": "script.festive_lights",
      "icon": "mdi:string-lights",
      "context_state": "on",
      "context_entity_id": "script.flood_lights_default_color"
    },
    {
      "when": 1706403731.649734,
      "state": "on",
      "entity_id": "light.foyer_light",
      "context_state": "on",
      "context_entity_id": "script.flood_lights_default_color"
    },
    {
      "when": 1706403731.650409,
      "state": "on",
      "entity_id": "light.first_floor_lights",
      "icon": "mdi:lightbulb-group",
      "context_state": "on",
      "context_entity_id": "script.flood_lights_default_color"
    },
    {
      "when": 1706403731.650924,
      "state": "on",
      "entity_id": "light.indoor_lights",
      "icon": "mdi:lightbulb-group",
      "context_state": "on",
      "context_entity_id": "script.flood_lights_default_color"
    },
    {
      "when": 1706403731.651569,
      "state": "on",
      "entity_id": "light.all_lights",
      "icon": "mdi:lightbulb-group",
      "context_state": "on",
      "context_entity_id": "script.flood_lights_default_color"
    },
    {
      "when": 1706403732.003142,
      "state": "off",
      "entity_id": "script.flood_lights_default_color",
      "icon": "mdi:light-flood-up",
      "context_state": "on",
      "context_entity_id": "script.flood_lights_default_color"
    }
  ]
}

Thre second script that does not run is in the default of the first script. If any other condition in there happens to be true, the default is never reached.

Yes, thank you. It that isn’t the case here. What I’m reporting is when the second script goes to the default choice, then the third scripts even reports having been called… but it doesn’t execute.

Thanks for all the info.

Could you change your script invocations to be blocking (as a test)? First change only the festive lights one to be called directly via script.. Then change only the flood lights one. Then change both.

As another test, can you replace the sunset trigger with a time trigger?

I got it working today. As I had mentioned, it was working perfectly and then suddenly it wasn’t but still tt would work when manually triggered or if the initiating automation was a different one.

I had one last suspicion and it was that the automation had somehow gotten corrupted. I suspected that given one day I was checking things out and HA said I couldn’t edit it on the UI because it something (I don’t remember) and it needed to be migrated. I then click migrate and it was all good looking afterwards. The interesting thing here is that I had the automation working from UI for a long time now (can’t remember if many months ago I had migrated it or if I had created in the UI from the beginning). I honestly didn’t think much about that “hiccup”.

Given I really couldn’t think that there was anything wrong with the code of the automation (once again, it was working until it wasn’t), I thought that maybe it was that it was corrupted somehow. So I simply went to edit it in the UI, went to YAML mode, copied the code, created a new one, deleted the old one, and renamed the new entity to match the old entity. That was it, no other changes at all. Fixed!

I can’t really think anything else other than something corrupted a part of it. Either way, fixed now, it’s good. Thanks Parautenbach for the suggestions, and all others for the help.

1 Like

Glad you got it working!

Is this perhaps the message you got?

YES!

I got it with more than a couple of them. I don’t remember on which I did what, but I did do migrate on one or two, and manually edited another couple until I realized it made no sense because ALL were available before. So I restarted HA and it was “all good” at least apparently.