How does the Entities page retrieves the entities?

I am trying to get programmatically (via pyscript) a list of entities and their status. I already tried to ask this question elsewhere (both here¹ and on Reddit²) but this seems to be a tough topic.

In practical terms: I am writing a monitoring module and I need to access remotely HA and get a list of entities, their labels and their state.

  • I managed to get the list of entities
  • I did not manage to get their details (namely the labels)
  • I can query the state of each of the entities

Ideally, I would be glad to get this in one big chunk to avoid back-and-forth calls but anything will do.

Why asking here (at “Frontend”)? Well because you managed to solve the problem since this page exists:

I would be really grateful for some pointers, even to the JS code which I will analyze (I have about 13% fluency in JS). Thanks!


¹How can I programatically list entities and their attributes? → no replies
²https://www.reddit.com/r/homeassistant/comments/1cmekyr/how_can_i_programmatically_list_entities_and/ → one reply, but not an answer as I was asking for something else

Maybe you want hass-cli Introducing Home Assistant CLI aka. hass-cli - Blog - Home Assistant Community (home-assistant.io)

The cli is a wrapper for the API (the WebSockets one) and it does not display the labels.

Interestingly the WebSockets API is the one used by the frontend and yet I cannot locate how the labels are queried.

It would be so good to just have .storage/core.entity_registry exposed.

I found it in the code for the frontend at frontend/src/data/entity_registry.ts at 6421a9443dae28f1d10eee923623d9fc75a7572c · home-assistant/frontend · GitHub

You need to send to the WebSockets API the message

ws.send(
            json.dumps(
                {
                    "id": 10,
                    "type": "config/entity_registry/list",
                }
            )
        )

It looks like there are plenty of API calls that are not documented.