Programatic adaption of entity ids for KNX entities

Dear all,

I run into the discussion on following FR: KNX: Define enitity_id, icon and area via YAML@farmio recommended to update the event id “programatically”.

What I have done so far:

  • Changed the entity id via UI (not practical for a large number of knx entries)
  • Directly edited the core.device_registry inside .storage (this felt like being completly wrong … also I do not understand if and when changes would be reflected by the core)

Could you provide a hint or some kind of documentation on how to do this correctly? I guess if programatic changes are mentioned some kind of API call might be used for this? On REST API docs I couldn’t find anything pointing in this direction.

Thanks for your support!

p.S.: I would like to enforce a certain semantic for the naming of my knx entities to make later use in automation and UI more convient.

Wait, Stop! I never recommended this.

But that’s at your own risk - remember to do a backup before!

Doesn’t imply recommendation. I merely said it would be possible to change the friendly_name (rather than entity_id) in core.entity_registry (not device_registry) if you aren’t too attached to your HA instance.

There will not be any documentation about that, as you shouldn’t do it. I don’t know if there is any API for it (and that was not meant by "programmatically`).

Use the UI for changing names or entity_ids of entities.

Hi @farmio,

Sorry for the misinterpretation - you’re right - it was clearly not a recommendation. But understood → core.entity_registry “could” be the place to go for.

Thanks for the very fast reply!

1 Like

to conclude the discussion: Yes, theoretically, you can create/modify entities programmatically through an API. Home Assistant provides a WebSocket connection and also a JavaScript client library for this purpose: GitHub - home-assistant/home-assistant-js-websocket: :aerial_tramway: JavaScript websocket client for Home Assistant

Take a look at your WebSocket connections in the browser DevTools, and you’ll see how Home Assistant communicates with the backend.

The code of _async_add_entity has a comment saying:

An entity may suggest the entity_id by setting entity_id itself

Found here: core/homeassistant/helpers/entity_platform.py at aa5c4d87867657e28372c4b352e6433784a4c222 · home-assistant/core · GitHub

I’d really need to (at least) suggest the entity_id via the YAML configuration. My use case: I have several KNX temperate sensors and KNX heating actuators that need to be addressed in a generic_thermostat.

You do already suggest the entity_id via yaml now. It’s a slug of the name value.

Yes, that’s true. I could do the same transformation to derive the entity_id from the name as a workaround. I’ll try that.

Currently Küche becomes kuche and Gästezimmer becomes gastezimmer. It would be nicer to have this transliteration for german “Umlaute”:

  • ö => oe
  • ü => ue
  • ä => ae
  • ß => ss

My favorite way is still have more control over the entity_id.

The suggested entity id. If that one is already used, you’ll still get an integer appended. Same would hold for any yaml configured entity id value - which is one of the reasons this is not a thing.