Why: Some Areas have a slugified area_id, others a system generated number

experimenting with templates and Area’s, like eg

{{ states.binary_sensor|selectattr('state', 'eq', 'off')
  |map(attribute='entity_id')|map('area_id')|reject('eq', None)|unique|list }}

resulting in:

[  "51721157e7d0491abbffa49c9b069e7e",
  "df21e517d2624b49a682041fe632cddc",
  "b36ceff2389e4b189f528ede60ad291f",
  "c52f1c47fd9111eaa95e2bc99216c855",
  "stookhok"
]

changing to

{{ states.binary_sensor|selectattr('state', 'eq', 'off')|map(attribute='entity_id')|map('area_name')|reject('eq', None)|unique|list }}

solves that list to use the Area names, but this exercise raises the question why there’s a difference between the area_id’s, as displayed in the first template return

(was on Discord for this, Discord and Discord)

I discovered several of my Areas have an id that is a sluggified name of that area like:

               "name": "Backdoor",
               "id": "backdoor"
           },

, while many have system generated numbers like:

{
                "name": "Pond",
                "id": "c52f1c47fd9111eaa95e2bc99216c855"
            },
            {
                "name": "Front room",
                "id": "b39bee42058e11ebb8b72598f576a1ed"
            }

listed in core.area_registry.

why the difference?

Checking the areas page in /configuration doesn’t give a clue for this.
Would appreciate a pointer…

2 Likes

as in Discord, repeat here for reference:

the auto generated id’s apparently were made by a previous version of HA. Ive changed that, but please be careful not to simply edit them (you’ll lose all connections to devices…)

1- rename the Areas with the numbered area_id’s to lets say _old. In the above case rename ‘Pond’ to ‘Pond old’
2- create a new Area with the name you want, in this case ‘Pond’
3- move all devices in ‘Pond old’ to the now new Area ‘Pond’
4- check ‘Pond old’ for remaining devices (refresh the page if must)
5- delete the old Area ‘Pond old’

6 Likes

I was exactly looking for this. It was so weird to write automation with such area_id Thx :slight_smile: