tl;dr summary:
My source occasionally has reset
events. Those represent the current state. Any entities not listed should not exist at that time.
Long version:
I’ll be more concrete with what I’m doing, which will hopefully help. I’m making a bridge from the local transit system’s streaming bus/train prediction service to Home Assistant, so I can do things like make a light change color when it’s time to leave for the bus.
The transit system API sends updates about “resources” — I’m tracking those for prediction
, stop
, vehicle
, trip
, route
, line
, and alerts
types. For each of these, there will be multiple resources at any given time — obviously stops don’t change very often, but vehicle ID depends on what actual busses happen to be on the line that day, and predictions are highly-transient with unique ids.
There are basically two different ways I can go about this that I can think of — the first is to track state in my bridge application, and send highly-interpretted data, while the second is to make the bridge as lightweight as possible and just reflect the resources closely into HA entities, and use templates on the HA side to do interpretation and processing.
I’m trying the second idea first.
The various resources have interlinked data — for example, each prediction
has a route_id
, stop_id
, trip_id
, and vehicle_id
. I could use those to pull things together into HA devices with the links as attribute data (I’m looking at how my Ecobee thermostats present the weather — they have a “climate” sensor which then has a list of forecast info. A “stop” device could have an “upcoming busses” sensor with the predictions (or a list of prediction ids) as attribute information.) Or, I could just have them all be separate entities and find and ‘stitch’ them with templates and scripting in HA. Not sure yet what will be best.
Anyway: The streaming API sends reset
, add
, update
, and remove
events. The crucial thing here is that on first connect, and arbitrarily whenever there is a lot to update at once (first thing in the morning, for example, as our system tragically does not run all night). And when a reset
event happens, that’s a clean slate. So, “orphans” would be: any entities created (through previous reset
or add
events) but which do not exist in this reset
event.