Sanitize Entity IDs

Hi,

when I started using HA I made a mistake renaming the entity ids as well using ZigBee2MQTT. I simply didn’t know better back then.

Now that I figured out how to pass the friendly name to Influx DB, I want to clean up the mess but would like to get your ideas in advance. What I believe needs to be done is:

  1. Rename all entity ids of effected devices i.e. from “sensor.test_sensor_battery” to “sensor.0xbc33acfffea99f6e_battery” using the IEEE-Address.
  2. Copying all values in Influx DB and deleting deprecated data:
  1. Optionally: Adjusting Node Red flows
  2. Optionally: Adjusting Grafana dashboards

What would be the most reliable and efficient approach?

Many thanks in advance
Mike

Why do you consider this a mistake?

Renaming serial number entity ids to something meaningful is well worthwhile. As long as you do it before using it. And for zigbee2mqtt do it from the zigbee2mqtt dashboard.

1 Like

@tom_l the issue I noticed is that renaming the entity id is, sometimes, not automatically reflected in InfluxDB. renaming the entity ID automatically creates “orphaned” sensor data if I am not fast enough with renaming.

Leaving the entity unchanged makes a lot of things much easier.

How are you using the influxdb data?

In Garfana?

If so you can edit your graph queries to use the old and new entity tag.

e.g. I’ve just been remodelling my downstairs rooms. Which required some sensor renaming. To ensure continuity I just do this:

I only keep the data for two years so I will eventually delete the old sensor name from that query.

The primary challenge I face is that there are old entries in the DB like these from the states_meta table:

metadata_id entity_id
1568 sensor.0x5c0272fffe4987ee_battery
1569 sensor.0x5c0272fffe4987ee_action
1570 update.0x5c0272fffe4987ee
1571 sensor.remote_test_2_battery
1572 sensor.remote_test_2_action
1573 update.remote_test_2

I tried updating the metadata_id in states_meta as well as states but that caused more issues until the devices sensors seem to not report anything anymore. Only removing and repairing the test device brought it back to life.

So the question for me still is, how to sanitize multiple device names and / or the duplicated sensors?

PS: Tampering with the HA DB seems to have a greater chance of messing things up badly. Simply removing the device and having it rejoin the network, followed by a rename of the friendly name, does the trick.

Though, there is still the challenge of merging / harmonizing the long term statistics. This post, at least for Influx DB, seems a good appraoch: