Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
12.03k stars 1.67k forks source link

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

Closed hvanoch closed 4 years ago

hvanoch commented 4 years ago

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 commented 4 years ago

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:

hvanoch commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@felixstorm good idea! implemented

to4ko commented 4 years ago

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

to4ko commented 4 years ago

@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 commented 4 years ago

can we have some kind of a switch on that?

+1 I like my 0x entities!

Spirituss commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

I've updated the behaviour:

septillion-git commented 4 years ago

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

Koenkk commented 4 years ago

That is the same as:

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

septillion-git commented 4 years ago

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 commented 4 years ago

Yes, or the recently integrated frontend (https://github.com/Koenkk/zigbee2mqtt/issues/4266) (homeassistant_rename option will be added soon there).

septillion-git commented 4 years ago

Sounds great! Thanks!

to4ko commented 4 years ago

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 (#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[bot] commented 4 years ago

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

MDSDM commented 3 years ago

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 commented 1 year ago

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 commented 5 months ago

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