Scenes on the fly - same automation doesn`t work

Hello, community! I’m new to Home Assistant, I just started my smart home automation project about a month ago. So far I’ve managed to accomplish a few interesting things by doing research, following tutorials, and thanks to this community. However, I recently encountered a problem that exceeds my understanding (I should mention that I’ve tried looking for solutions to this issue here, but it hasn’t been successful).

In short, I have installed ambient LED strips in the bathroom and in the entrance hallway of the house. For these I created two automations that turn on the LED strips at 60% brightness only at night (based on sunset/sunrise) and only when motion is detected (motion sensor in the hallway and presence sensor in the bathroom). Everything works perfectly.

In addition, I created two more automations, one for each room, where, if someone turns on the main light (separate from the LED strip), the LED strip turns off, and when the main light is turned off, the LED strip returns to its previous setting. I achieved this using “Scene Create” and “Scene Activate”.

In the bathroom, this last automation using Scene Create/Activate works perfectly. However, in the hallway, it only works partially. When I turn on the main light, the LED strip turns off. When I turn off the main light, the LED strip remains off (in the logs, I can see that Scene Activate has been triggered, but nothing happens). I should mention that the two automations are identical (I only changed the switch, sensor and LED strip entities). I can’t understand why the same automation works in one place but not in the other. Below, I’ll share the YAML code for the two automations.

alias: Bathroom Main/Night Light
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.bathroom
conditions: []
actions:
  - if:
      - condition: state
        entity_id: switch.bathroom
        state: "on"
    then:
      - action: scene.create
        data:
          scene_id: bathroomwhled2
          snapshot_entities:
            - light.wh_led_controller
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.wh_led_controller
    else:
      - action: scene.turn_on
        target:
          entity_id: scene.bathroomwhled2
        data: {}
mode: single
alias: Entrance Main//Night Light
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.entrance
conditions: []
actions:
  - if:
      - condition: state
        entity_id: switch.entrance
        state: "on"
    then:
      - action: scene.create
        data:
          scene_id: entrancewhled
          snapshot_entities:
            - light.wh_led_controller_2
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.wh_led_controller_2
    else:
      - action: scene.turn_on
        data: {}
        target:
          entity_id: scene.entrancewhled
mode: single

If you need any additional details, please let me know. Thank you so much!

I can’t see any error, so my only guess would be that the scene create takes longer to do in the entrance and the lights then might succeed to be turned off before the scene is created.

Could you as a test try to add a delay between the scene create and the light off action.
Set it to something long, like 10 seconds, for the test.

I added a 10-second delay as you suggested, and it seems to work. I’ll now try to reduce this delay as much as possible while keeping the automation functional. But still, why does this issue occur with two automations that are identical? Is there any chance I can eliminate this delay?

My guess is the scene create takes longer for one setup than the other and the scene create does not hold back the further execution of the rest of the actions.
I was just a guess though and someone with more understanding of the actual code behind must explain this in more details.