Weird issue with "swapped" entities in scripting

I have a weird issue with two door covers / blinds that are “swapped” when addressed in automation:

Current status:

  • I have two door covers, one at terrace and on at the balcony
  • I have two scripts, one for closing all covers at first floor (incl. balcony) and one for closing all covers in the basement (incl. terrace)
  • I have two automation rules for closing covers at first floor or basement depending on time and sunset.

The issue that I am facing is:

  • when the scripts for closing are called directly (using HA UI), everything works as expected: All covers at the selected floor level close
  • when the scripts are called by automation, all window covers at floor level close as expected, but the door cover on that floor remains open and the door cover at the other floor closes instead.

Example:
At 8:30pm latest the covers on the basement are to be closed. All windows covers (kitchen, living-room, etc.) close, but the terrace door remains set. Instead the balcony door closes.

How can I track down this really annoying issue?

Configuration

Automation

close covers at basement 2h after sun-set
but not before 7:00 pm
but latest at 8:30h pm

alias: autom. Schliessen Jalousie Erdgeschoss
trigger:
  - platform: sun
    event: sunset
    offset: '02:00:00'
  - platform: time
    at: '20:30:00'
condition:
  condition: time
  after: '19:00:00'
action:
  - service: script.turn_on
    entity_id: script.close_covers_groundfloor

Scripts

script.close_covers_groundfloor:

cover.neqXXXX281 is the terrace’s door cover entity id

alias: Close overs basement
sequence:
  - service: script.close_door_cover
    data:
      entity_id: cover.neqXXXX281 
  - service: script.close_window_cover
    data:
      entity_id: cover.neqXXX092
  - service: script.close_window_cover
    data:
      entity_id: cover.neqXXX021
  - service: script.close_window_cover
    data:
      entity_id: cover.neqXXX025
  - service: script.close_window_cover
    data:
      entity_id: cover.neqXXX975

script.close_door_cover:

only close if fully open
close to 10% first, then wait one minute (for manual change)
if after one minute, still at 10%, close fully

alias: close door cover
sequence:
  - condition: template
    value_template: "{{ is_state_attr(entity_id,'current_position',100) }}"
  - service: cover.set_cover_position
    data_template:
      entity_id: "{{ entity_id }}"
      position: 90
  - delay: '00:01:00'
  - condition: template
    value_template: "{{ is_state_attr(entity_id,'current_position',90) }}"
  - service: cover.close_cover
    data_template:
      entity_id: "{{ entity_id }}"

script.close_window_cover:

only close cover, if fully open

alias: close window cover, if open
sequence:
  - condition: template
    value_template: "{{ is_state_attr(entity_id,'current_position',100) }}"
  - service: cover.close_cover
    data_template:
      entity_id: "{{ entity_id }}"

Btw: It dissapeared after a recent update (I think 57.1). Maybe a glitch in the matrix …