Make sure single execution of script

I’d like to know if there is any way to create a script and make sure that it is “static”?

For example:
I have my script where I am lowering a IKEA blind to a specified value and then wait for x seconds and then raise the blind again…
Now I want it to be like if I start the script and it executes to the delay and I then executes the same script again, I want the old runtime to just be terminated and the new runtime to continue as normal…

How would I accomplish such a feat? :smiley:

Use a timer instead of a delay.

- service: script.turn_off
  entity_id: script.xyz
- service: script.xyz
1 Like

I changed my automation to:

- id: '15852....'
  alias: Close bathroom blind short
  description: ''
  trigger:
  - device_id: 57e2.....
    domain: deconz
    platform: device
    subtype: close
    type: remote_button_short_press
  condition: []
  action:
  - data:
      hours: 00
      minutes: 06
      seconds: 30
    service: script.bathroom_blind

and my script to:

bathroom_blind:
  description: Open or close the blind for x minutes
  sequence:
  - data:
      position: 57
    entity_id: cover.blind
    service: cover.set_cover_position
  - data:
      duration: '{{ hours }}:{{ minutes }}:{{ seconds }}'
    entity_id: timer.bathroom_timer
    service: timer.start
  - data:
      position: 100
    entity_id: cover.blind
    service: cover.set_cover_position

But now I get error in the developer log…

Close bathroom blind short: Error executing script. Invalid data for call_service at pos 1: offset {{ hours }}:{{ minutes }}:{{ seconds }} should be format ‘HH:MM’ or ‘HH:MM:SS’ for dictionary value @ data[‘duration’

But the format should be correct… shouldn’t it? :open_mouth:

duration: contains a template so change data: to data_template:

If you leave it as data: then it doesn’t attempt to evaluate the template and simply passes it verbatim which is what the error message is complaining about:

Invalid data for call_service at pos 1: offset {{ hours }}:{{ minutes }}:{{ seconds }}

1 Like

There are two problems with this. First, it doesn’t solve the original problem. If the automation is triggered while the script is running it won’t start over. Second, starting a timer doesn’t cause a delay in the script between the two cover operations. Basically it will lower the cover, start a timer, and then immediately raise the cover. I don’t think that’s what you want. Try this:

- id: '15852....'
  alias: Close bathroom blind short
  description: ''
  trigger:
  - device_id: 57e2.....
    domain: deconz
    platform: device
    subtype: close
    type: remote_button_short_press
  condition: []
  action:
  - entity_id: script.bathroom_blind
    service: script.turn_off
  - data:
      hours: 00
      minutes: 06
      seconds: 30
    service: script.bathroom_blind

and…

bathroom_blind:
  description: Open or close the blind for x minutes
  sequence:
  - data:
      position: 57
    entity_id: cover.blind
    service: cover.set_cover_position
  - delay: '{{ hours }}:{{ minutes }}:{{ seconds }}'
  - data:
      position: 100
    entity_id: cover.blind
    service: cover.set_cover_position