Entity IDs in automations are more cryptic now?

I noticed recently (not sure how recent) that automations I create for devices now use a cryptic entity_id instead of the more human readable one that shows up when looking at an entity from a device page.

For example, in an automation controlling this device:

          - type: turn_on
            device_id: a339a2668aaa9e2b4bfc8ffce596b209
            entity_id: 79b56d3c38ca30ec5150365e54b34cdc
            domain: switch

While the device in the above code has an entity_id of switch.family_room_bookshelf_sonoff_on_off which is more readable. I can’t find the long string above anywhere in the device page for reference.

This makes it a bit harder to code using the yaml vs. the visual editor.

Just wondering what’s going on?

Not a direct solution for the problem. But I always avoid using the devices and use only the entities. Many advantages with this. And reason against doing it as well?

So instead of starting with device, start with call service, use switch.turn_on and then the entity. Done.

This is then still working with a replaced device, if you give the new entity the name of the old.

Actually, I almost always start with the visual editor since it’s generally a quick and easy way to get an automation started (for me at least). So I don’t pick device or entity IDs, I pick devices by name from a drop down list in the visual editor. The resulting code is what has the device_id (which I know is always a long string) and the entity_id - which is now a cryptic string instead of the human readable text as shown in the device editor page.

That’s what my question is based on – why is it different know. When I add a new device to an existing automation, I see the older yaml code that references the entity_ids of devices by their human readable string. The newly added devices to the automation use the string instead.

I guess I’ll try modifying the automations by hand to replace the string with the human readable string to see if they still work. If that works then I’ll call it done and just an annoyance of something extra I have to do when editing an automation these days.

Or - in a general statement - I wish there was a way to insert # comments in an automation so I can just simply add a comment to a section saying what the device is. But comments seem to disappear when I save so it’s not possible (as far as the last time I checked).

I think this was an automated response? Not sure.

But my post is not in reference to triggers, it’s in the action items where I control a device. I totally agree with the use of states in triggers but that’s not what I’m referencing here in this post.

No. He and I are refering to the actions as well. It is an exact part in his quote, if you read it.

Actually, I almost always start with the visual editor since it’s generally a quick and easy way to get an automation started (for me at least). So I don’t pick device or entity IDs, I pick devices by name from a drop down list in the visual editor.

Can you please post a screenshot what are you meaning? Perhaps we can explain than better, what is unclear in our answers.

OK, no problem. I’ll walk you through a simple example:

  1. I’ll make an automation that turns off the bookshelf light device (sonoff on/off module).
  2. Let’s ignore triggers & conditions - just the action part for now.

Screenshot 2023-12-11 103128

Picking device:

Screenshot 2023-12-11 103139

Find it by name:

Screenshot 2023-12-11 103256

Click and add what happens:

Screenshot 2023-12-11 103310

View YAML:

Screenshot 2023-12-11 103334

I was hoping for switch.family_room_bookshelf_sonoff_on_off as the entity_id that’s human readable as seen on the device page:

I did notice something, however, this particular device is zigbee and controlled via zigbee2mqtt but I can’t seem to find that entity ID anywhere on the Zigbee2Mqtt dashboard either for the device.

Yes. Exactly. And instead selection “Device” here, select “Call service”. Same dropdown, same UI.

Screenshot 2023-12-11 103139

Then a fitting service. e.g. switch.turn_on. Or the generic homeassistant.turn_on. And then select the entity.

More or less no change and not more to select. But better in many ways.

In both way, you need to do what (on) and which (device/entity), so instead of starting with the which and then selecting the what, start with the what and then select the which.

It is both the visual editor.

1 Like

Nice!

That gives me this result, and I’m happy to do it that way. I do it that way for “light.turn_{on,off}” anyway.

action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.family_room_bookshelf_sonoff_on_off

Thank you for the clarification, I’ll update my process.

Oh side note – and this will be super helpful to me… can I list multiple entities here? I think I would be able to… that will make things a lot cleaner for me.

i.e.

action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.family_room_bookshelf_sonoff_on_off
      entity_id: switch.family_room_island_sonoff_on_off
      entity_id: switch.family_room_table_sonoff_on_off
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: 
        - switch.family_room_bookshelf_sonoff_on_off
        - switch.family_room_island_sonoff_on_off
        - switch.family_room_table_sonoff_on_off

Beside the example from finity as answer, you can always just do it in UI. There just select more entities from the picker, service call options, … And then switch to yaml and see what magic happened and what is the syntax for it.