Bulk Edit for Entities

As an administrator, I want to edit multiple entities simultaneously so it doesnt take me hours to do simple reconfigurations

It takes a really long time to do changes to entities when re-organising things like “Area”, a method to do bulk changes of certain fields would reduce the time to reorganise or fix problems from over an hour to seconds.

Adding a “bulk change” in the existing Configuration > Entities screen that uses the existing tickboxes would be a natural place to do this.

Background
The number of available entities quickly grows, HA is an enthusiast platform so a normal house can easily have over 100 entities when you account for 50 bulbs, 20 remote switches, 10 remote sensors, 4-5 media connections, 2-3 HVAC controls and the occasional connected car or smart cat litter.

Operations like area changes can take a long time by the time you select each one, click advanced, select the area, press update, repeat 100 times.

Providing bulk edit capabilities would make this job simpler and alos promote people experimenting with different configurations as it can be done quickly

You might see if hass-cli might let you do shell scripts to make the changes you’d like to do. I think if the entities in question show up in the GUI, then hass-cli should be able to manipulate them.

I used hass-cli in the past to rename a bunch of Z-Wave entities that got automatically created with really ugly names, 4 or 5 entities for each outlet on a Z-Wave power strip…

See https://www.home-assistant.io/blog/2019/02/04/introducing-home-assistant-cli/ and https://github.com/home-assistant-ecosystem/home-assistant-cli for more info.

Here is an example that I just used it for. I needed to rename a bunch of entities from ‘entityname_2’ to just ‘entityname’

hostname# for i in $(hass-cli entity list architect |awk '{print $1}' | grep -v ENTITY_ID |sed 's/\_2$//g')
do
hass-cli entity rename "${i}_2" ${i}   
done
   -  id: 1
      type: result
      success: true
      result:
          entity_entry:
              config_entry_id: 2cb298a867d6d2147ee2e591794c6658
              device_id: 04d52d2bb64937320c85eca30cbc910b
              area_id:
              disabled_by:
              entity_id: device_tracker.architect
              name:
              icon:
              platform: mobile_app
              original_name: architect
              original_icon:
              unique_id: AAC3B418-C77D-5D7A-8B61-0645589BA3D1
              capabilities: {}

1 Like

Here is another example that plays off @overkill32 's work

I wanted to insert a work into the entity ID after the first word, so

sensor.glances_foo becomes sensor.glances_unraid_foo

for i in $(hass-cli entity list glances |awk '{print $1}' | grep -v ENTITY_ID); do
v=$(echo  -n $i | sed -r 's/(.*)\.glances\_(.*)$/\1\.glances_unraid_\2/g')
# echo "${i} ---> ${v}"
hass-cli entity rename "${i}" ${v}
done
1 Like

For the windows crowd: This script renames devices matching a regex string. Save as whatever.ps1 and execute in directory with venv for hass-cli. If you installed it globally just skip the first line.

& .\venv\Scripts\activate

$server = "http://pi-homeassistant:8123"
$token = "yourAccessTokenHere"

$hass_command = "hass-cli"
$hass_params =  "--server $server --token $token"

$replace_from = "_lowbat"
$replace_to = "_batterie_niedrig"

$entities = & $hass_command --server $server --token $token --output yaml entity list $replace_from

foreach ($line in $entities) {
    if ($line -match "entity_id:") {
        $entity_old = $($line -split ": ", 2)[1]
        $entity_new = $entity_old -replace $replace_from, $replace_to
        Write-Host "Old name: $entity_old"
        Write-Host "New name: $entity_new"
    }
}

Write-Warning "Rename this?" -WarningAction Inquire

foreach ($line in $entities) {
    if ($line -match "entity_id:") {
        $entity_old = $($line -split ": ", 2)[1]
        $entity_new = $entity_old -replace $replace_from, $replace_to
        Write-Host "Renaming $entity_old to $entity_new"
        $res = & $hass_command --server $server --token $token entity rename $entity_old $entity_new
        foreach ($r in $res) {
            if ($r -match "success:") {
                $success = $($r -split ": ", 2)[1]
                Write-Host "Success: $success"
            }
        }
    }
}
1 Like

Also worth noting that renaming the parent device will give the option to propagate the change to child entityIds. While this isn’t exactly what you may be looking for, it did the trick for me. More info outlined in this thread: Bulk renaming of related entities

I would like to rename, but for me its not working.

I want to rename theese entities:
sensor.tasmota_ip
sensor.tasmota_last_restart
sensor.tasmota_wifi_connect_count
sensor.tasmota_ip_2
sensor.tasmota_last_restart_2
sensor.tasmota_wifi_connect_count_2
sensor.tasmota_ip_4
sensor.tasmota_last_restart_4
sensor.tasmota_wifi_connect_count_4

For me, this SED command not working

's/(.*)\.tasmota\_(.*)$/\1\.EP2_\2/g'

If I test it just with sensor.tasmota_ip_4>>>The result is fine: “sensor.EP2_ip”:

hass-cli --columns=ENTITY="entity_id,DEVICE_ID=device_id[*]" entity list sensor.tasmota_ip_4 | grep -i 2xxxxxxxxxxxbef61 | awk '{print $1}' | sed -r 's/(.*)\.tasmota\_(.*)$/\1\.EP2_\2/g' | sed 's/\_4$//g'

But if i do the rename process:

for i in $( hass-cli --columns=ENTITY="entity_id,DEVICE_ID=device_id[*]" entity list sensor.tasmota_ip_4 | grep -i 29xxxxxxxxxxxxxxxxxxxxxxxxxef61|awk '{print $1}'); do
> v=$(echo  -n $i | sed -r 's/(.*)\.tasmota\_(.*)$/\1\.EP2_\2/g' | sed 's/\_4$//g')
> hass-cli entity rename "${i}" ${v}
> done
   -  id: 1
      type: result
      success: false
      error:
          code: invalid_info
          message: Invalid entity ID

The rename process fail.

Can somebody help me with she SED command/ regex?

Bulk edit is an even more vital feature now with the new Labels/Categories/Areas etc. Anyone with an existing installation is faced with hours of laborious clicking to assign labels to their existing automations, entities etc. A checkbox-based bulk update feature is sorely needed to make this 100x easier!

Indeed, setting tags or categories would be so much easier with bulk assignment. Regex/script based as mentioned above is no good for this, checkboxes would be great.

… you can

Thanks! How did I miss that one? I did look for it.

Probably needed to clear cache. It was added mid beta, so I had the joys of doing everything without multi-select.

It’s not available everywhere btw. I think it’ll expand to more lists as time comes.

Ah, that may explain it, I joined the beta early on.

Yeah, it wasn’t added until beta 5 or 6.

Good thing I wasn’t done yet by a long way :slight_smile:

We just need bulk area’s now. Still no multi-select way for that…

Recently I’m setting up multiple lights via xiaomi gateway3, some entities are disabled by default and I need to re-enable them manually, I have hundreds of lights and need to repeat again and again, what a mess and not geek at all. :rofl:
@frenck

Do not randomly tag people who are not involved in a conversation. Thank you.

Go to your entities tab instead of the device tab and use multiple select from that list. You can get what you want done in 1 action.