Using a Pre-Generated Value
The best-est easiest place I found for a unique ID for stuff is to use one generated for you. When HA runs an automation it generates unique ID’s for the execution “this” and “trigger” actions. It is generated for internal use, but if you want to use it for something else not related to that, to you it’s just a random (& guaranteed unique) ID. I use it as a suggested notification ID for my notify BP, No reason it can’t work for a transient scene ID.
this.context.id
or
trigger.from_state.context.id
or
trigger.to_state.context.id
are 3 that are available on nearly every automation BP execution. Others are available depending on the original automation or script code. (You need to pull up a trace to see.)
enter_action:
- parallel:
- service: script.personalert_notify
data:
person: '{{ trigger.to_state.attributes.friendly_name }}'
place_to: '{{ trigger.to_state.state }}'
place_from: '{{ trigger.from_state.state }}'
notify_id: '{{ trigger.to_state.context.id | lower }}'
phase: enter
- service: script.personalert_audio
data:
mess: '{{ trigger.to_state.attributes.friendly_name + '' has arrived at
'' + trigger.to_state.state }}'
lang: en-GB
Is how I use in, See the notify_id variable.
From a trace:
this:
~~...~~
context:
id: 01H14T8SPTHE3CNSN8P5VRS4HR
parent_id: null
user_id: null
NOTE:
If you are plugging this into a scene as the ID, you must to pipe it to lower because scene_id is lower_case_chase nomenclature…
{{ trigger.to_state.context.id | lower }}
Just putting this out there in case it will help someone.
Here’s an alternative method of generating a unique string:
{{ now() | string | slugify }}