Script stops without complete the entire sequence when it has a delay

Hello,

I have the following script:

alias: 1.DM roll initial-raise
sequence:
  - service: script.1dm_roll_up
    metadata: {}
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
  - service: script.1dm_roll_stop
    data: {}
mode: single

The idea is as follows:
I have roller shades that work with a remote, and I copied the signal for up, stop & down.
In the morning, I want to let my dog go outside, but I do not want to raise the shades completely, so when I want to let the dog outside, I will click a button and execute this script.
Now the issue is that the script starts executing and it stops, when I check the traces I see:

(script.1_dm_roll_initial_raise) turned on
Script '1.DM roll-up' on
1.DM roll-up (script.1dm_roll_up) started
(script.1dm_roll_up) turned on
(script.1dm_roll_up) turned off
Delay for 20 seconds

2 seconds later

(script.1_dm_roll_initial_raise) turned off
Cancelled at May 29, 2024 at 10:04:23 AM (runtime: 1.61 seconds) 

I searched the documentation and forum …, but nowhere did I find something about why the script would stop by itself.
If I execute this script inside an automation, then it works, but that is not enough for me. I want to push a button and execute it whenever I press it.
What I found is a bug report from a couple of years back without being fixed or anything helpful Script toggle turns off before script has finished executing · Issue #4722 · home-assistant/frontend · GitHub

Is there something that I’m missing?
Should I do something different?
Should I delete the script and create the same sequence as part of an automation (and button press to trigger the automation)?

How are you calling the script? Are you calling it directly or are you using script.turn_on? If it works in automation then it should, in theory, also work in a script since the execution is almost identical. Is it possible that script.1dm_roll_up is doing something to cancel it?

I know right? I would expect the same if it works in automation and at a button click.

Sequence from button click:

            sequence:
              - service: script.1_dm_roll_initial_raise
                data: {}

and the same sequence is in the automation…

I even tried the following:

sequence:
          - service: script.1_dm_roll_initial_raise
            metadata: {}
            data: {}

see the extra “metadata:{}”

I noticed that if it has the metadata, it sais “Script ‘1.DM roll initial-raise’ on”
while if it doesn’t, it sais “Call a service ‘Script: 1.DM roll initial-raise’ on”

Complete automation for the button:

alias: 1.DM button
description: ""
use_blueprint:
  path: homeassistant/_aqara_t1_mini_button.yaml
  input:
    button_action_topic: zigbee2mqtt/1.DM button/action
    double_press:
      - if:
          - condition: state
            entity_id: light.1_dm_lamp
            state: "on"
        then:
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.1_dm_lamp
        else:
          - service: light.turn_on
            target:
              entity_id:
                - light.1_dm_lamp
            data: {}
    single_press:
      - service: input_datetime.set_datetime
        target:
          entity_id: input_datetime.breastfeeding_time
        data:
          datetime: "{{ now() }}"
    hold:
      - choose:
          - conditions:
              - condition: state
                entity_id: binary_sensor.1_dm_roll_down_contact
                state: "off"
            sequence:
              - service: script.1_dm_roll_initial_raise
                data: {}
          - conditions:
              - condition: state
                entity_id: binary_sensor.1_dm_roll_up_contact
                state: "off"
            sequence:
              - service: script.1_dm_roll_initial_descent
                data: {}

the blueprint _aqara_t1_mini_button.yaml is:

blueprint:
  name: Z2M - Aqara T1 (WXKG11LM) - wireless mini button
  description: Scene & device control using Aqara T1 mini button
  author: pauldcomanici
  domain: automation
  input:
    button_action_topic:
      name: zigbee2mqtt topic with action for aqara button
      description: "zigbee2mqtt topic with action for aqara button (example: zigbee2mqtt/0.LV1 button/action)"
      selector:
        text:
    single_press:
      name: single press
      description: action to run on a single press
      default: []
      selector:
        action: {}
    double_press:
      name: double press
      description: action to run on a double press
      default: []
      selector:
        action: {}
    hold:
      name: hold
      description: action to run when button is held
      default: []
      selector:
        action: {}
    release:
      name: release
      description: action to run when button is released after a hold
      default: []
      selector:
        action: {}

mode: restart
max_exceeded: silent

trigger:
  - platform: mqtt
    topic: !input "button_action_topic"

condition:
  - condition: state
    entity_id: input_boolean.manual_override_enabled
    state: "off"
  - condition: template
    value_template: "{{ states('sensor.home_human_presence')=='on' }}"

action:
  - variables:
      command: "{{ trigger.payload }}"
  - choose:
      - conditions:
        - condition: template
          value_template: "{{ command == 'single' }}"
        sequence: !input "single_press"
      - conditions:
        - condition: template
          value_template: "{{ command == 'double' }}"
        sequence: !input "double_press"
      - conditions:
        - condition: template
          value_template: "{{ command == 'hold' }}"
        sequence: !input "hold"
      - conditions:
        - condition: template
          value_template: "{{ command == 'release' }}"
        sequence: !input "release"

while the automation that does automatic blinds control:

alias: 1.DM roll-actions
description: ""
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.home_alarm
    to: armed_away
    from: disarmed
    id: armed_away
  - platform: state
    entity_id:
      - alarm_control_panel.home_alarm
    to: armed_night
    from: disarmed
    id: armed_night
  - platform: state
    entity_id:
      - alarm_control_panel.home_alarm
    to: armed_home
    from: disarmed
    id: armed_home
  - platform: state
    entity_id:
      - alarm_control_panel.home_alarm
    to: disarmed
    from: armed_night
    id: disarmed
  - platform: state
    entity_id:
      - binary_sensor.1_dm_roll_initial_descent
    to: "on"
    id: initial_descent
  - platform: state
    entity_id:
      - binary_sensor.1_dm_roll_complete_raise
    to: "on"
    id: complete_raise
condition:
  - condition: state
    entity_id: input_boolean.manual_override_enabled
    state: "off"
  - condition: state
    entity_id: input_boolean.roll_1_dm_enabled
    state: "on"
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - disarmed
          - condition: state
            entity_id: binary_sensor.1_dm_roll_initial_raise
            state: "on"
          - condition: state
            entity_id: binary_sensor.1_dm_roll_down_contact
            state: "off"
        sequence:
          - service: script.1_dm_roll_initial_raise
            data: {}
        alias: initial_raise
      - conditions:
          - condition: trigger
            id:
              - complete_raise
          - condition: state
            entity_id: binary_sensor.1_dm_roll_up_contact
            state: "on"
        sequence:
          - service: script.1dm_roll_up
            data: {}
        alias: complete_raise
      - conditions:
          - condition: trigger
            id:
              - initial_descent
          - condition: state
            entity_id: binary_sensor.1_dm_roll_up_contact
            state: "off"
        sequence:
          - service: script.1_dm_roll_initial_descent
            data: {}
        alias: initial_descent
      - conditions:
          - condition: trigger
            id:
              - armed_away
              - armed_home
              - armed_night
          - condition: state
            entity_id: binary_sensor.1_dm_roll_complete_descent
            state: "on"
          - condition: state
            entity_id: binary_sensor.1_dm_door_outside_contact
            state: "off"
          - condition: state
            entity_id: binary_sensor.1_dm_roll_down_contact
            state: "on"
        sequence:
          - service: script.1dm_roll_down
            data: {}
        alias: complete_descent
mode: single

For context binary_sensor.1_dm_roll_down_contact → is the contact sensor that I added at the bottom of the blinds

Later edit: After posting this, I noticed that my blueprint was with “mode: restart”, and that was the problem … as the aqara button emits the hold event, and when you release the button, it emits the release event … resulting in my automation to restart … changed the mode to “mode: queued” … and yey it works.

That was precisely what I was looking for, I’m glad you found it!

It’s solved, fantastic!

Now, before you go… please take the time to mark the solution as the answer, you do that by selecting the three dots under the post:

image

Then select the check box:

image