home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.85k stars 29.54k forks source link

Renaming script entity id fails #115334

Open rrooggiieerr opened 4 months ago

rrooggiieerr commented 4 months ago

The problem

When renaming the Entity ID of a script things go wonky.

The Entity ID is renamed in the entities and scripts overview, but when calling the script from an automation, the frontend or Developer Tools > Services the new Entity ID does not work, but the old one still needs to be used.

Example:

I renamed the Entity ID of my script from script.boiler_45_min to script.prepare_shower

Screenshot 2024-04-10 at 07 00 17

Using the new Entity ID from the frontend gives an error:

  - type: tile
    entity: binary_sensor.boiler_heating
    icon_tap_action:
      action: call-service
      service: script.prepare_shower
      data: {}
      target: {}
    name: Prepare Shower

https://github.com/home-assistant/core/assets/18603534/a9b2f8d0-c4ca-4f87-83d9-da809a8287b8

Calling my script in Developer Tools > Services still shows the old Entity ID:

Screenshot 2024-04-10 at 06 58 09

The new id does not work in Developer Tools > Services even though in YAML mode command completion suggests the new Entity ID:

Screenshot 2024-04-10 at 07 10 59 Screenshot 2024-04-10 at 07 10 20

Running the script from the Scripts overview does work.

Workaround: Duplicate the automation, give the duplicate the name you want and delete the original

What version of Home Assistant Core has the issue?

core-2024.4.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Scripts

Link to integration documentation on our website

https://www.home-assistant.io/integrations/script/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

When calling the new _Entity ID_ from Developer Tools > Services:

2024-04-10 07:19:22.129 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Service not found for call_service at pos 1: Service script.prepare_shower not found
2024-04-10 07:19:22.130 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547616179136] Error handling message: Service script.prepare_shower not found (home_assistant_error) Rogier from 77.249.240.188 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36)

Additional information

No response

home-assistant[bot] commented 4 months ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (script) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `script` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign script` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


script documentation script source (message by IssueLinks)

joostlek commented 4 months ago

I think script.something isn't a valid service. Don't you have to run script.turn_on and pass the script as parameter?

rrooggiieerr commented 4 months ago

@joostlek script.something is valid, give it a try.

It's actually different behaviour. Using script.something in an automation waits for the script to be finished while script.turn_on starts the script and then immediately continues the automation.

https://www.home-assistant.io/integrations/script/#waiting-for-script-to-complete "When calling a script “directly” (e.g., script.NAME) the calling script will wait for the called script to finish. If any errors occur that cause the called script to abort, the calling script will be aborted as well."

Opontios commented 4 months ago

Confirm exactly what the OP describes. And it raises serious issues. The use of "service: script.something" becomes impossible, though it is widely used in dashboards, for example.

BT643 commented 4 months ago

I noticed this issue a few days ago and raised it in the community before I found this Github issue: https://community.home-assistant.io/t/rename-service-script/717374/3

There's a temporary "solution" for this until it gets resolved, you can fix the name in the scripts.yaml file directly. To access and edit the file, I used the VSCode web addon to edit the file from within the Home Assistant web UI: https://github.com/hassio-addons/addon-vscode/blob/main/vscode/DOCS.md

When you open the scripts.yaml file you'll see the OLD name in there, you can just update it to the new name, save the file, and then restart Home Assistant (check the config first to make sure it's all ok!).

Now the "service' shows correctly for me everywhere.

I found a while after that this caused some issues where the script wasn't recognised in some places, I've changed it back to how it was before for now.

rrooggiieerr commented 4 months ago

Instead of editing the scripts.yaml just duplicate the automation, give the duplicate the name you want and delete the original

Opontios commented 4 months ago

The problem is not in how to find a workaround, I believe everybody found something for the their particular case. The problem is that there was a particular algorithm for naming scripts that was working perfectly and now it is broken with an update.

masi commented 2 months ago

A script is also a service. And from the UI only the id of the entity is changed.

What I would expect is that for scripts the service id changes with the entity id. I assume that the UI will need a dedicated rename dialogue to perform this behaviour.

Jeppedy commented 3 weeks ago

Is no one looking to fix the "Rename" issue? I'm now stuck trying to find where the old scripts are defined, as it keeps NUMBERING my script every time I recreate it.

rrooggiieerr commented 2 weeks ago

I think @home-assistant/core should be involved

masi commented 1 week ago

I think @home-assistant/core should be involved

How can the core devs be reached? For some integrations a bot pings some of them. Apparently not for scripts.