Automation": define entity_id explicitly

Observed this a long time ago, have not asked yet.

Consider this automation in yaml:

  - alias: "test: super automation"
    id: "test_super_super_automation"
    description: ''
    trigger: []
    condition: []
    action:
    - service: notify.persistent_notification
      data:
        message: hello
    mode: single

The “id” option stands for (Docs):

It is not said here that “id” becomes “entity_id”.
So, the automation becomes “automation.test_super automation”:

image

image

Seems that “entity_id” is only generated from “alias”.
(yes, yes, a modern trend to use UI only… no need to know “entity_id”…)

Is there any YAML-way to define entity_id?
Or is it can only be done by composing the “alias”?

(I do know about a possibility to change entity_id in UI)

The value of alias is converted to a slug and used to create the automation’s entity_id.

- alias: "test: super automation"
  id: "supercalifragilisticexpialidocious"
  description: ''
  trigger: []
  condition: []
  action:
    - service: notify.persistent_notification
      data:
        message: hello
  mode: single

Thank you, I see it, the same way is used for many other platforms.
But I was interested to define “entity_id” explicitly.
Seems there is no way to do it w/o UI.

Usually I define “id” equal (like slugified) to alias like here:

  - alias: "tracker: Traccar check alert (iPhone 999S+)"
    id: "tracker_traccar_check_alert_iphone_999s_plus"

but in some cases like this one it creates “automation.tracker_traccar_check_alert_iphone_999s” which is undesired. Have to edit entity_id manually in UI then.

My reply was merely meant to correct this false statement:

It’s “not said” because that’s not how it works. The automation’s entity_id is initially derived from its alias not its id.

Yes, I understood you, thanks again!

My issue was:

  1. Created automation with alias “XYZ xyz: xxx xxx”.
  2. It has “automation.xyz_xyz_xxx_xxx” entity_id.
  3. I am using this entity_id in a code.
  4. One day I decide to rename the automation to “XYZ xyz: xxx xxx YYY” in yaml.
  5. But I forgot to fix it’s entity_id → PROBLEM.

When I change this (in the example I posted above):

- alias: "test: super automation"

to this:

- alias: "test: super duper automation"

the result (after Reload Automations) is this:

The automation’s entity_id remains unchanged. Its friendly_name is changed.

If you modify the an existing automation’s alias in YAML, it serves to modify its friendly_name (its original entity_id is preserved). Try it and see if you get the same result as I did.

In my case I observed these:

  • the current automation became “restored”,
  • a new automation with changed “friendly_name” and with added “_2” was created.

I cannot say exactly a sequence of my actions which lead to these “_2” replacements.

Finally, I ended up with:

  • fix alias in yaml;
  • rename the “.yaml" file to ".dis”;
  • reload automations → the old automation is removed;
  • rename back to “*.yaml”;
  • reload automations → the new automation is created with a new alias and NEW entity_id;
  • go to UI and edit entity_id.

Probably I am doing smth wrong, that is why I asked about a possibility to define “entity_id” explicitly…

Neither can I.

This topic seems to have wandered off from the original questions:

  1. Yes. Initially via alias (not via id as claimed in the first post).
  2. Same answer as #1.

If you want to change the automation’s entity_id afterwards (and it has an id defined) you can do that via the UI.


NOTE

The naming rules are different if the automation does not have id defined. Changing an existing automation’s alias in YAML will change its entity_id.

I did not claim that “id” stands for “entity_id”, you misunderstood.
That was merely my initial thought which I refused even before posting the 1st post.

I think the issue is clear, thanks again!

Then I misunderstood this statement:

Overlooking that misinterpretation, everything else I wrote explains how an automation’s entity_id is derived from its alias for cases when id is defined and when it’s not.

1 Like

I see your point, the “It is not said here that “id” becomes “entity_id”” was about:
“Guys, do not think that “id” stands for “entity_id”, it is just to allow changing in UI”.
Language))). (guess you do know Russian…)

1 Like