Syntax to call a script from an automation

Is this the right format to run a script from an automation?

actions:
  - action: script.turn_on_growatt_battery_first

I keep getting an error that it can’t find the script.
When I’m editing the line in the yaml editor it comes up with the option when I get to “script.” so I can just select it so I can’t figure why it can’t find it.
The scripts I’m using work fine if I run them manually.
Any pointers appreciated.

Where/how do you get the error?

This is one way, done like this it waits for the script to terminate and returns an error if the script fails.

You can also use the homeassistant.turn_on service with the script as entity. That will not wait for the result.

But I doubt the way of calling is is the issue here. Did you by any chance edit the entity id of the script? If the entry in the script.yaml file is no longer the same as the enity id in the ui, you can run into problems in some places. I reported this as a bug.

Renaming the entity id back, or renaming the entry of the script in script.yaml to match should fix it if this is indeed the problem.

1 Like

It was a log error found in the morning (these run overnight).
The entity id could well be the problem as I did edit it/them.
I have now deleted the scripts and recreated them from scratch without editing the entity id. As I say, when coding it the editor picks it up when I type “script.” now so I’m hopeful of a successful outcome tonight :crossed_fingers:

Just checked script.yaml and the first lines of each script looks identical to what I am calling from the automations. Confidence getting higher. Thanks for the help.

1 Like

Hi Clive Reynolds,

Are you using home assistant 2024.10.0 or newer?

syntax requires it.

1 Like

2024.10.1

It seems to have worked fine overnight :slight_smile:

If one of the suggestions listed solves your problem, please consider clicking the solution button to close the thread. (even your own…)

1 Like