One API Call providing to multiple sensors

I am working on a platform that exposes a handful of different sensors whos information is gathered from one api call. I want to do it this way because it seems silly to make an api call for each sensor because the data is already being called for one sensor. I found another post that asked the same question, but it got no responses.

I am also well aware of many solutions that involve putting all the data in the attributes of one sensor then creating sensors based on those attributes, but that seems sloppy to me (and there is a character limit that way).

Could anybody try to point me in the right direction?

So I just had to do this recently for a change I am making.

In my case it was for econet water heaters. Attributes are no longer allowed for this type of thing, and you need to use sensors.

The thing you need to look at is dispatcher_send and dispatcher_connect

Basically during the initial setup of the integration you should have a class that handles making/receiving the updates, creating all the sensors, and calling dispatcher send. Then in each entity have dispatcher connect get the latest changes.

Search around for usages of those methods and you can take a look at my usage here

Another solution to this is to use the DataUpdateCoordinator which is designed for this particular use case.

You can find many examples searching for that class in the github repo:

1 Like