So if there’s no “area_id” on entities, in either the hass object, the rest api to entities, or the websocket api to subscribeEntities, how do I get a list of areas and all entities / devices inside those areas?
I want to create a Dashboard with page that show all areas and cards for all entities in those areas.
PS. I’m using TypeScript for my project.
Related links.
Git pull request for this feature that was never merged
Feature request for this feature that wasn’t responded to.
This file seems to be related somehow, but no documentation on how I could get this “config” from the websocket or rest api.
There doesn’t seem to be any way to get the area_registry list using either the hass object, the rest API or the official websocket package.
However if instead of using the proper package, you manually set up the websocket yourself, you can get the list of areas like this:
const socket = new WebSocket('ws://homeassistant.local:8123/api/websocket')
socket.onopen = function (event) {
socket.send(
JSON.stringify({
type: 'auth',
access_token: HOMEASSISTANT_TOKEN,
})
)
}
// after you get the auth_ok message, send this websocket:
socket.send(JSON.stringify({ type: 'config/area_registry/list', id: 4 }))
and then you will get a response with areas!
I don’t understand why this isn’t part of the actual package. But at least there’s a workaround
man you’re a real life saver, this worked perfectly!! I just had to add a line with “const WebSocket = require(‘ws’);” and run the command npm install ws and it worked. I also added the same for entity and device registry filtering to only appear the most important parameters such as entity_id’s or area_id’s. My code looks like this (note: replace “TOKEN” with your long-lived access token from home assistant):
const WebSocket = require(‘ws’);
const socket = new WebSocket(‘ws://YOURHOMEASSISTANTURL:8123/api/websocket’);