Switch script off

I have a script that I want to run in an automation and want to turn it off as soon as the script is done.

I tried doing so inside the automation (script.turn_on then script.turn_off) and in a seperate test at the end of the script (script.turn_off at the end of the script itself)

Neither of the two options is working. How can I switch a script to turn itself off?

I think you should turn the automation off after it gets triggered, not the script.
Do you mind sharing your code?

Have you tried homeassistant.turn_on and homeassistant.turn_off ?

The script will turn off as soon as it has completed the last action in the sequence

Of course! See below:
Automation:

  - data:
      entity_id: script.1521449290108
    service: script.turn_on
  - data:
      entity_id: switch.deurbel
    service: switch.turn_off
  - data:
      entity_id: script.1521449290108
    service: script.turn_off
  alias: Deurbel licht automation
  condition:
  - after: sunrise
    before: sunset
    condition: sun
  id: '1521449002518'
  trigger:
  - entity_id: switch.deurbel
    platform: state
    to: 'on'

The script:

'1521449290108':
  alias: Deurbel licht script
  sequence:
  - data:
      message: Er staat iemand voor de deur
    service: notify.pushbullet
  - data:
      entity_id: media_player.homef_2
      language: nl
      message: Er staat iemand voor de deur. Ga eens snel kijken wie het is!
    service: tts.google_say
  - data:
      entity_id: light.tradfri_bulb_e27_w_opal_1000lm
    service: light.turn_on
  - wait_template: 1s
  - data:
      entity_id: light.tradfri_bulb_e27_w_opal_1000lm
    service: light.turn_off
  - data:
      entitity_id: script.deurbel
    service: switch.turn_off
  - data:
      entity_id: script.1521449290108
    service: homeassistant.turn_off