Can scripts be turned off automatically after triggering?

My question is has anybody added scripts and imported them into HomeKit? Mine show up ok and work but unlike in Homebridge they stay on like a Boolean Switch. I liked the fact that the script would immediately turn off after activating the script via my HomePod. This made it very easy to use my harmony hub and write scripts to change the channels, turn on the tv, adjusting the volume. Now because they stay on it makes the process more difficult. Does anybody know if there’s a line I can add in my script to turn off after activating it?

Thanks everybody

You could try adding:

- service: script.turn_off
  entity_id: script.this_script

I use scripts to turn off other scripts. Haven’t tried turning itself off… worth a shot?

yes, i will try, thank you!!

Did it work (a script stopping itself)?
I have had cause to want to do this but always ended up going down a route I knew would work because I am put off experimenting by the time it takes my HA to restart. (hassio on Pi)

Yes it worked perfectly! Thanks petro! Now it shuts off as soon as it’s activated!

2 Likes

Yes perfect, you can just reload scripts to test it so it doesn’t take so long bro.

I’m using packages so unfortunately nothing can be reloaded.

Packages are brilliant but flawed, if you’re not using them I suggest you look into it. The flaw is that they do not allow you to reload scripts/automations etc. you have to restart.

1 Like

Can you please provide an example,of what you did? I’m trying to create a momentary switch that I can call from Siri. You turn it on, and then it does something and then turns itself off again.

I added the code, but some not working. If i call i script from homekit, it keeps activated. When using homebridge the script turns off again automatically. This behavior is what i want.

the script is stopped in HA but not in homekit

this is what I did.

hdmi2:
  alias: Mirror Apple TV
  sequence:
  - service: remote.send_command
    entity_id: remote.harmony_hub
    data:
      device: '56317158'
      command: 'Select 2'
  - service: script.turn_off
    entity_id: script.hdmi2

It works good for me.

1 Like