Using the websocket client to subscribe to just a few entities

I like to take my automations quite far, and feel limited by yaml / the UI, so I write my own code and run it in node to automate some of my stuff. This has worked fine so far, but I’ve been using various packages that are available on NPM to communicate with HA. These work, but have their limitations. Most have also been abandoned. Since HA has their own websocket client available, I figured I’d use that.

Now, I can get the connection up and running and it all works fine, but I’m struggling with how the client is setup. It feels like it’s all or nothing, especially when it comes to entities. For my automation I only need roughly 20 out of my hundreds of entities, but I can only find a single way to subscribe to entities, and that’s to subscribe to all. A collection seems to be what I need, but I haven’t got a clue how to use them, and it seems like nobody (at least nobody that has published their code) uses collections either.

So, how do I use the websocket client to subscribe to state changes for a select amount of entities?

Websocket client: GitHub - home-assistant/home-assistant-js-websocket: 🚡 JavaScript websocket client for Home Assistant