Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advice on how to use with home assistant and naming things #4096

Closed
hvanoch opened this issue Aug 13, 2020 · 20 comments
Closed

Advice on how to use with home assistant and naming things #4096

hvanoch opened this issue Aug 13, 2020 · 20 comments
Labels
stale Stale issues

Comments

@hvanoch
Copy link

hvanoch commented Aug 13, 2020

Hi,

Just starting with integrating the zigbee2mqtt in my home assistant setup.
Everything in home assistant has to be referenced with an enity_id.

When using home assistant and zigbee2mqtt with discovery all entities get a name like binary_sensor.0x00158d00053f84dc_contact

What are the possible ways to change this entity ID. Is this only through the UI or is there also a way to do it through some configuration (either in the home assistant or in the zigbee2mqtt)? That way I can put it my source control. It would also be a lot easier to search.

What would you advice?

@Koenkk
Copy link
Owner

Koenkk commented Aug 13, 2020

The 0x00158d00053f84dc part of binary_sensor.0x00158d00053f84dc_contact is taken from the friendly_name in the Zigbee2MQTT configuration.yaml. However this is only set once! When the friendly_name is updated and Zigbee2mqtt resend the discovery payload, Home Assistant does not update the entity_id.

So the options are:

  • Change via UI in Home Assistant
  • Prevent Home Assistant from discovering the id containing the "wrong" friendly_name by either:
    • Stopping Home Assistant when pairing new devices
    • Stop Zigbee2MQTT, set homeassistant: false in Zigbee2MQTT configuration.yaml, start, pair device, stop and set homeassistant: true again.

@hvanoch
Copy link
Author

hvanoch commented Aug 13, 2020

Thank you for the clear explanation. Guess it makes sense it doesn't update the entity_id by itself.

If I get annoyed by this then I guess I might make a script that changes the entity_id in the config/.storage/core.entity_registry with some regex whenever I do a rename of a zigbee device through ha.

@felixstorm
Copy link
Sponsor Contributor

felixstorm commented Aug 14, 2020

I was trying to find an easy way to also change HA's entity_id for some time as well and reading your issue, I think I found another option: If you actively delete all of the device's entities from Home Assistant before you rename, HA will accept the new name also as the entity_id (and not the friendly name only).

Deletion should be done via MQTT also (publish an empty payload to all config topics) and I found a relatively easy way to do this here (picture taken from there also):
image

So the complete procedure would be:

  1. Pair the new device with zigbee2mqtt.
  2. Remove all of the device's HA entities using it's device id (e.g. homeassistant/sensor/<device_id>/action/config, homeassistant/sensor/<device_id>/battery/config, homeassistant/sensor/<device_id>/linkquality/config, homeassistant/binary_sensor/<device_id>/update_available/config etc. - you can get this information from the z2m log right after pairing) using MQTT as shown above.
  3. Rename the device in zigbee2mqtt.
  4. HA should see the device again as new and will also pickup the new name as the entity_id.

@Koenkk Maybe z2m could delete the entities from HA first, wait a few seconds and then publish the new name when renaming a device? This way it could work seamlessly at least as long as Home Assistant is running while renaming...

Edited to use device_id instead of friendly_name.

@Koenkk
Copy link
Owner

Koenkk commented Aug 17, 2020

@felixstorm good idea! implemented

@to4ko
Copy link

to4ko commented Aug 23, 2020

Ohhhh thats why my devices got renamed automatically and i was needed to rename them back manually...great

@to4ko
Copy link

to4ko commented Sep 2, 2020

@felixstorm good idea! implemented

can we have some kind of a switch on that? entity_id and friendly name little bit different and this kind of "enhancements" can
and would ruin all the existing logic in HA

@depen84
Copy link

depen84 commented Sep 2, 2020

can we have some kind of a switch on that?

+1
I like my 0x entities!

@Spirituss
Copy link

@Koenkk Technically, recreation of ha entities is a possible solution. But one should have choices either to recreate entities automatically or do it manually (current deconz logic, for example), since automatic deletion of entities could be very damaging for existing legacy in the ha, such as automations, lovelace, etc.

@septillion-git
Copy link

What's the status on this? Does it only change entity id when I change the friendly name? Or will it also change entity id of devices I already renamed in the past?

Because although I hate the 0x entity id's and manually renamed most, the key is most... I would hate it even more if current automations en cards stop working with this update... 🙄

@Koenkk
Copy link
Owner

Koenkk commented Sep 4, 2020

I've updated the behaviour:

  • When renaming to configuration.yaml (stop/start z2m) -> no rediscover, was already the case
  • When renaming through the old api (zigbee2mqtt/bridge/config/rename) -> no rediscover anymore
  • When renaming through the new api ([RFC] Revising MQTT bridge structure #3281) (zigbee2mqtt/bridge/request/device/rename) -> by default no rediscover anymore but it can be enabled by publishing: {"from": "oldname", "to": "newname", "homeassistant_rename": true}

@septillion-git
Copy link

And if you rename through the devices.yaml? (Which I used to do...)

@Koenkk
Copy link
Owner

Koenkk commented Sep 4, 2020

That is the same as:

When renaming to configuration.yaml (stop/start z2m) -> no rediscover, was already the case

@septillion-git
Copy link

Thanks!

Good and a shame at the same time. 😛 So what would be the easiest way to rename the friendly names and entities? Or should I just wait for something like Z2M Assistant to support it?

@Koenkk
Copy link
Owner

Koenkk commented Sep 4, 2020

Yes, or the recently integrated frontend (#4266) (homeassistant_rename option will be added soon there).

@septillion-git
Copy link

Sounds great! Thanks!

@to4ko
Copy link

to4ko commented Sep 4, 2020

I've updated the behaviour:

  • When renaming to configuration.yaml (stop/start z2m) -> no rediscover, was already the case
  • When renaming through the old api (zigbee2mqtt/bridge/config/rename) -> no rediscover anymore
  • When renaming through the new api ([RFC] Revising MQTT bridge structure #3281) (zigbee2mqtt/bridge/request/device/rename) -> by default no rediscover anymore but it can be enabled by publishing: {"from": "oldname", "to": "newname", "homeassistant_rename": true}

thanks a lot, Koen! will wait for the next update to install.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2020

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Stale issues label Oct 5, 2020
@MDSDM
Copy link

MDSDM commented Jan 27, 2021

This works almost...

Living Room - door sensor in ZigBee2MQTT

Change name in Home Assistant to Door Sensor

Then I change in ZigBee2MQTT to Sensor Door and disable change in Home Assistant

I get link quality, contact and battery to change their names.

@RezzZ
Copy link

RezzZ commented May 15, 2023

any chance we can have a setting to auto tick the "Update Home Assistant entity ID" option when renaming devices?
I'm migrating from deconz to z2m and It's pretty anoying that I have to check this option every time I rename a devices friendly name :).
Otherwise I'm very happy with Z2M so far 😃

edit:
also, just ticking the option "Update Home Assistant entity ID" to get the friendly name pushed gives the error that the friendly name is already in use. Although I understand the error, perhaps this can be fixed so we can more easily push a new friendly name (in case the option to update HA entity id was not ticked) instead of renaming, and renaming again with the option ticked?

@hyphus
Copy link

hyphus commented May 6, 2024

Can this option be set in the yaml config for a device?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues
Projects
None yet
Development

No branches or pull requests

10 participants