InfluxDB 2 rename entity_id / measurement

If a Integration change it’s Name like hahm → hmip, new Data will be written with new entitiy_id to the InfluxDB. If you have longtime Data and want to visualize it with Grafana for Example, it is kind of PITA.

Use Influx 2 Data Explorer to look at your data and get your entity_id and or _measurement value.

Data need to copied from old to new measurement, as Influx 2 does not support rename. Than old measurement can be deleted.

Source

Flux Example copy entity_id

  • entity_id OLD: hahm_00xxxxxxxxxxxxx_1_actual_temperature
  • entitiy_id NEW: hmip_swo_pl_00xxxxxxxxxxxxx_temperatur

execute in Influx 2 Data Explorer:

from(bucket: "home_assistant/autogen")
  |> range(start: -720d)
  |> filter(fn: (r) => r.entity_id == "hahm_00xxxxxxxxxxxxx_1_actual_temperature")
  |> set(key: "entity_id", value: "hmip_swo_pl_00xxxxxxxxxxxxx_temperatur")
  |> to(bucket: "home_assistant/autogen")

Flux Example copy _measurement

  • _measurement OLD: binary_sensor.hahm_00xxxxxxxxxxxxx_1_raining
  • _measurement NEW: binary_sensor.hmip_swo_pl_00xxxxxxxxxxxxx_regen

execute in Influx 2 Data Explorer:

from(bucket: "home_assistant/autogen")
  |> range(start: -720d)
  |> filter(fn: (r) => r._measurement == "binary_sensor.hahm_00xxxxxxxxxxxxx_1_raining")
  |> set(key: "_measurement", value: "binary_sensor.hmip_swo_pl_00xxxxxxxxxxxxx_regen")
  |> to(bucket: "home_assistant/autogen")

Delete old entity_id / _measurement

Look at source links for curl example

influx cli example

influx delete --bucket "home_assistant/autogen" --org "examle-org" --token xxxxxxxxxxxxxxxxxxxxxxx-GvFl-xxxxxxxxxxxxxxxxxxxxxx-YT3icTsm90Rp5w== --predicate 'entity_id="hahm_00xxxxxxxxxxx_1_actual_temperature"' --start '2009-01-02T23:00:00Z' --stop '2023-06-16T23:00:00Z'

Tested with

  • InfluxDB: 2.7.1
  • HomeAssistant: 2023.6.1
5 Likes

Hi pixeldoc2000!

your article was just what what I needed to bring data together after a device update in ESPHome.

I thought!!!

I have Home Assistant Core 2024.1.4 and InfluxDB 5.0.0 running. I tested your adapted script exept the last line:

from(bucket: “homeassistant/autogen”)
|> range(start: 2022-12-15T00:00:00Z, stop: 2024-01-21T00:00:00Z)
|> filter(fn: (r) => r.entity_id == “wasserstand_cm”)
|> set(key: “entity_id” , value: “levelheight”)

that worked fine. Then I added the line with the to() function
.
|> to(bucket: “homeassistant/autogen”)

I even were helped editing it. When starting the script I was told

grafik

Is this by design? Do I need to allow this function especially?
Has anybody an idea?

any solution to this?