Implement entity area property
Opened this issue · 1 comments
As in YIO v1: request areas and set entity.area property in available entities.
Testing with Home Assistant 2023.3.6
There doesn't seem an easy way anymore to get the area of an entity.
Get areas:
{
"type": "config/area_registry/list",
"id": 4
}
Result (sample):
{
"id": 4,
"type": "result",
"success": true,
"result": [
{
"aliases": [],
"area_id": "living_room",
"name": "Living Room",
"picture": null
},
{
"aliases": [],
"area_id": "kitchen",
"name": "Kitchen",
"picture": null
},
{
"aliases": [],
"area_id": "bedroom",
"name": "Bedroom",
"picture": null
}
]
}
So far so good. But how do we get the entities in an area_id
?
There's the entity registry:
{
"type": "config/entity_registry/list",
"id": 5
}
Result (sample):
{
"area_id": null,
"config_entry_id": "18c9ecbd442b0fad06359ece6efe4bbe",
"device_id": "3d293c15b9646fa6ee3c4659a3b17317",
"disabled_by": null,
"entity_category": null,
"entity_id": "light.esstisch",
"has_entity_name": false,
"hidden_by": null,
"icon": null,
"id": "f5bb2da87a4a4de5ea257d282d672f96",
"name": null,
"options": {},
"original_name": "Esstisch",
"platform": "hue",
"translation_key": null,
"unique_id": "3fd17309-9d07-4b50-8e6c-a8b78d20e84a"
}
Buth light.esstisch
is in a defined area:
Interestingly the manually defined power switch to control a Sonos speaker has an area:
{
"area_id": "essen",
"config_entry_id": null,
"device_id": null,
"disabled_by": null,
"entity_category": null,
"entity_id": "switch.mystrom_switch",
"has_entity_name": false,
"hidden_by": null,
"icon": null,
"id": "00212855345302ed74851d23db636556",
"name": "Sonos Esstisch",
"options": {},
"original_name": "myStrom Switch",
"platform": "mystrom",
"translation_key": null,
"unique_id": "30AEA491D184"
}
This doesn't seem to work: from my 100+ entities all except 3 return "area_id": null
👎
But I have assigned many many more entities to areas! Where are they?
I remember that retrieving the area was working about 3+ years ago when we were implementing the onboarding for the YIO remote...
Looks like that quite a few things have changed. My current understanding:
- entities belonging to devices. The device is linked to an area. This seems to be the standard case.
- entities can also be directly linked to areas
Only example I've found:
https://developers.home-assistant.io/docs/frontend/custom-ui/custom-strategy/#full-example
Then let's try with the device registry:
{
"type": "config/device_registry/list",
"id": 6
}
Bingo! area_id
for the light.esstisch
entity with device_id: 3d293c15b9646fa6ee3c4659a3b17317
shown above is finally set:
{
"area_id": "essen",
"configuration_url": null,
"config_entries": [
"18c9ecbd442b0fad06359ece6efe4bbe"
],
"id": "3d293c15b9646fa6ee3c4659a3b17317",
"name": "Esstisch",
"sw_version": "1.101.2",
"via_device_id": "ee5dbf4b9197e2863380054b26dcc3ed"
},
So, no more easy way to get the area, now we have an additional indirection to deal with...