How to set up a script that only can be restarted when the pending script is finished?

Hi there,

The script I have is restarting right away despite the single modus.

Anyone a suggestion how to solve this?

alias: douchen
sequence:
  - service: scene.turn_on
    target:
      entity_id: scene.lampen_badkamer_aan
    metadata: {}
  - type: turn_on
    device_id: 514ab9068757e04c06eac53ec2e04ea2
    entity_id: switch.sonoff_1001661da3
    domain: switch
  - delay:
      hours: 0
      minutes: 8
      seconds: 0
      milliseconds: 0
  - service: scene.turn_on
    target:
      entity_id: scene.lampen_badkamer_knipperen
    metadata: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 8
      milliseconds: 0
  - service: scene.turn_on
    target:
      entity_id: scene.lampen_badkamer_aan
    metadata: {}
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 514ab9068757e04c06eac53ec2e04ea2
    entity_id: switch.sonoff_1001661da3
    domain: switch
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - service: scene.turn_on
    target:
      entity_id: scene.lampen_badkamer_uit
    metadata: {}
mode: single

What is calling the script?

That is a button.

So why would it run more than once for every time you press the button?

Perhaps you should explain what you mean by this:

It’s a script which limits the showertime (watersupply valve, controlled by IOT). To avoid starting the script after the water stops running, I included a delay of 10 minutes with the assumption that a script in single modus can not start when it’s not finished yet.

I notice that the script starts again when the button is pushed.

That is odd. Have you checked the script trace?

I will check it tonight. haven’t done yet.

Can you clarify this? There’s 3 things this could mean and all work a bit different:

  1. Button card (or some other UI component) with an action to call the script
  2. Template button with press set to call the script
  3. Input button with an automation that calls the script when the button is pressed.

Which one do you mean?

This is what I use. Button card?

show_name: true
show_icon: true
type: button
icon: mdi:shower-head
show_state: true
entity: script.douchen_script
hold_action:
  action: none
tap_action:
  action: toggle
name: Douchen
1 Like

Strange. It should work like you describe (existing run blocks new runs while its going). There should actually be an error in the log telling you that a new run of the script couldn’t be started because there was an existing one.

Only thing I can think of, is there an error in the trace? An error could stop it from continuing. Maybe its not actually getting to most of the steps?

If I read the documentation correctly, automation modes are, as the name implies, described only for automations. Could it be scripts in themselves do not implement the feature? It was not how I interpreted it, and the script editor does generate the setting in each script, so personally I’d expect scripts to respedt it too.

No, scripts implement this feature. They do respect it as well. I use single, parallel, and restart all the time throughout my configuration for scripts. I’m willing to bet something else is going on here.

thanks for sharing your thoughts. I will check the logs after I use the shower again. To be continued…

I did run the script from the settings and not via a button. It works. A new script can’t start because there is a pending script (single modus).

Sometimes the script does not proceed. I suspect a wifi issue which I am going to adress first. I have an other issue concerning updating of sensors (other topic).When this is solved I can rule out connection issues.

I have a situation that the script is being interrupted because the script is started again by an user. That shoudn’t be possible when on single mode. Processing: trace script.douchen_script 2023-01-31T19_47_53.625599+00_00.json…

I enclosed the trace. Anyone a idea?

The one started at 19:47h is stopped at 20.01h. The script cannot be finished at that time so it must be cancelled by start over the script.

  "trace": {
    "last_step": "sequence/8",
    "run_id": "09bb5a5afad1b81a0590a2013777832c",
    "state": "stopped",
    "script_execution": "cancelled",
    "timestamp": {
      "start": "2023-01-31T19:47:53.625599+00:00",
      "finish": "2023-01-31T20:01:06.803930+00:00"
    },
    "domain": "script",
    "item_id": "douchen_script",
    "trace": {
      "sequence/0": [
        {
          "path": "sequence/0",
          "timestamp": "2023-01-31T19:47:53.631154+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "script.douchen_script",
              "state": "off",
              "attributes": {
                "last_triggered": "2023-01-30T19:39:41.333777+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Badkamer kinderen"
              },
              "last_changed": "2023-01-30T19:56:49.796320+00:00",
              "last_updated": "2023-01-30T19:56:49.796320+00:00",
              "context": {
                "id": "01GR241VR4ENMDZB8ZWQM1D89A",
                "parent_id": null,
                "user_id": null
              }
            },
            "context": {
              "id": "01GR4NY74NEHM807VHG4PBHX46",
              "parent_id": null,
              "user_id": "b9dfeffb64f541429d24d4695eed507b"
            }
          },
          "result": {
            "params": {
              "domain": "scene",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "scene.lampen_badkamer_aan"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "sequence/1": [
        {
          "path": "sequence/1",
          "timestamp": "2023-01-31T19:47:53.739146+00:00"
        }
      ],
      "sequence/2": [
        {
          "path": "sequence/2",
          "timestamp": "2023-01-31T19:47:53.768866+00:00",
          "result": {
            "delay": 360,
            "done": true
          }
        }
      ],
      "sequence/3": [
        {
          "path": "sequence/3",
          "timestamp": "2023-01-31T19:53:53.772274+00:00",
          "result": {
            "params": {
              "domain": "scene",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "scene.lampen_badkamer_knipperen"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "sequence/4": [
        {
          "path": "sequence/4",
          "timestamp": "2023-01-31T19:53:53.883210+00:00",
          "result": {
            "delay": 8,
            "done": true
          }
        }
      ],
      "sequence/5": [
        {
          "path": "sequence/5",
          "timestamp": "2023-01-31T19:54:01.885924+00:00",
          "result": {
            "params": {
              "domain": "scene",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "scene.lampen_badkamer_aan"
                ]
              }
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "sequence/6": [
        {
          "path": "sequence/6",
          "timestamp": "2023-01-31T19:54:01.970814+00:00",
          "result": {
            "delay": 60,
            "done": true
          }
        }
      ],
      "sequence/7": [
        {
          "path": "sequence/7",
          "timestamp": "2023-01-31T19:55:01.973100+00:00"
        }
      ],
      "sequence/8": [
        {
          "path": "sequence/8",
          "timestamp": "2023-01-31T19:55:02.004885+00:00",
          "result": {
            "delay": 600,
            "done": false
          }
        }
      ]
    },
    "config": {
      "alias": "Badkamer kinderen",
      "sequence": [
        {
          "service": "scene.turn_on",
          "target": {
            "entity_id": "scene.lampen_badkamer_aan"
          },
          "metadata": {}
        },
        {
          "type": "turn_on",
          "device_id": "514ab9068757e04c06eac53ec2e04ea2",
          "entity_id": "switch.sonoff_1001661da3",
          "domain": "switch"
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 6,
            "seconds": 0,
            "milliseconds": 0
          }
        },
        {
          "service": "scene.turn_on",
          "target": {
            "entity_id": "scene.lampen_badkamer_knipperen"
          },
          "metadata": {}
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 0,
            "seconds": 8,
            "milliseconds": 0
          }
        },
        {
          "service": "scene.turn_on",
          "target": {
            "entity_id": "scene.lampen_badkamer_aan"
          },
          "metadata": {}
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 1,
            "seconds": 0,
            "milliseconds": 0
          }
        },
        {
          "type": "turn_off",
          "device_id": "514ab9068757e04c06eac53ec2e04ea2",
          "entity_id": "switch.sonoff_1001661da3",
          "domain": "switch"
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 10,
            "seconds": 0,
            "milliseconds": 0
          }
        },
        {
          "service": "scene.turn_on",
          "target": {
            "entity_id": "scene.lampen_badkamer_uit"
          },
          "metadata": {}
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01GR4NY74NEHM807VHG4PBHX46",
      "parent_id": null,
      "user_id": "b9dfeffb64f541429d24d4695eed507b"
    }
  },
  "logbookEntries": [
    {
      "when": 1675194473.626026,
      "state": "on",
      "entity_id": "script.douchen_script",
      "context_user_id": "b9dfeffb64f541429d24d4695eed507b"
    },
    {
      "when": 1675194473.63599,
      "state": "2023-01-31T19:47:53.635811+00:00",
      "entity_id": "scene.lampen_badkamer_aan",
      "context_user_id": "b9dfeffb64f541429d24d4695eed507b",
      "context_state": "on",
      "context_entity_id": "script.douchen_script"
    },
    {
      "when": 1675194473.782596,
      "state": "on",
      "entity_id": "switch.sonoff_1001661da3",
      "context_user_id": "b9dfeffb64f541429d24d4695eed507b",
      "context_state": "on",
      "context_entity_id": "script.douchen_script"
    },
    {
      "when": 1675194833.775828,
      "state": "2023-01-31T19:53:53.775548+00:00",
      "entity_id": "scene.lampen_badkamer_knipperen",
      "context_user_id": "b9dfeffb64f541429d24d4695eed507b",
      "context_state": "on",
      "context_entity_id": "script.douchen_script"
    },
    {
      "when": 1675194841.888828,
      "state": "2023-01-31T19:54:01.888585+00:00",
      "entity_id": "scene.lampen_badkamer_aan",
      "context_user_id": "b9dfeffb64f541429d24d4695eed507b",
      "context_state": "on",
      "context_entity_id": "script.douchen_script"
    },
    {
      "when": 1675194902.017816,
      "state": "off",
      "entity_id": "switch.sonoff_1001661da3",
      "context_user_id": "b9dfeffb64f541429d24d4695eed507b",
      "context_state": "on",
      "context_entity_id": "script.douchen_script"
    }
  ]
}

Thanks for your effort!