None entity_id in script?

sorry, forgot to repond to this.
you are right, that works ok.

I’ve tested with:

          message: >
           {{state_attr(trigger.event.data.entity_id,'name')}} was updated to {{state_attr(trigger.event.data.entity_id,'latest_release_url').split('tag/')[1]}}.
           Visit the release page {{state_attr(trigger.event.data.entity_id,'latest_release_url')}} to download.
           Object is {{trigger.event.data.object_id}}
           Entity is {{trigger.event.data.entity_id}}
           Name is {{state_attr(trigger.event.data.entity_id,'name')}}
           Fake Object is {{trigger.event.data.entity_id.split('.')[1]}}

and the message is clear on all templates, except for the one using object_id, which simply results in an empty field:
Object is

all others show the expected outcome. Why cant we use object_id here? State objects - Home Assistant would suggest otherwise, and in regular jinja templates I do so without issue.

about your format:

{{ trigger.event.data.entity_id.split('.', 1)[1] }}

what does the 1 in split('.', 1) do? I think I get the same result without it?

splits a maximum of 1 time on the first occurrence.

Since it’s a state_changed event you can. You just have to get it from the correct place:

{{ trigger.event.data.new_state.object_id }}
2 Likes

So some additional thoughts…

First, a script (or automation action sequence) calls another script in a blocking fashion, which means if an exception happens during the “subscript” it will also abort the calling script, just like any other service called. However, if the subscript hits a delay step, or a wait_template step that actually waits, then the subscript will “suspend” and “return” to the calling script/automation, which will continue to the next step. In this scenario, if the subscript fails (e.g., causes an exception) after the delay or wait_template step, the script/automation that originally called it will not be affected. This must be what y’all are thinking of.

With that in mind, one way to ensure a calling script/automation will continue even if a called subscript fails is to put a “delay zero” step at the beginning of the subscript:

xyz:
  sequence:
  - delay: 0
  - ...

That will cause the subscript to immediately suspend and return to the calling script, and then start again (in parallel with the calling script, assuming it’s still running) within one second.

And as to the exception caused by the subscript not existing, I realized that shouldn’t be possible, because if you call a script via “service: script.NAME” (or even via a service_template), and that script didn’t exist, a service by its name would not have been registered and, hence, you’d get a “service not found” error (long before the exception would happen.) That reminded me of an issue that was raised about a bug, specifically 25419 " script.reload while script is running". (And @Mariusthvdb you even commented on that issue. :slightly_smiling_face:) I’ve fixed the bug, but haven’t submitted the fix yet because it was going to be part of the larger scripting rewrite which, unfortunately, has been taking a lot longer than I had originally hoped.

With that in mind, don’t reload scripts while any of them are running. If you can’t prevent them from running while you reload them, then restart HA instead.

2 Likes