How to deal with "Transient" entities for a transit system integration? (Create many, reuse names, something else?)

I’m looking at making an integration for the local public transit. (Related: Server Sent Event listener / RESTful api?)

This isn’t quite home automation, but I think there a lot of useful things that those of us who live by and depend on such service would benefit from. (A light that blinks when it’s time to leave to catch the bus, for example.)

I’m new to Home Assistant, and I could use help thinking about the right data model and some of the other conceptual basics.

What kind of … thing are things?

There’s kind of a natural hierarchy of: Lines → Routes → Stops → Vehicles → Trips. Because I’m envisioning this as a “view from your home” integration (rather than some sort of replacement for general transit apps), I think it’s basically fine to treat Lines, Routes, and Trips all as metadata for specific vehicles (the API is very flexible and allows you to ‘include’ items in requests, so that’s pretty easily done).

I started with the idea of “Transit Stop” as a device, and “Vehicle” (Or “Transit Vehicle”) as entities linked to that device. But, I think maybe it fits better to make them two types of entities?

Transit Stops would have attributes:

  • name
  • latitude
  • longitude
  • prediction (discussed separately)

and Transit Vehicles would have:

  • route
  • destination
  • direction
  • latitude
  • longitude
  • status (in transit or stopped)
  • other useful metadata perhaps (bus #, whether it’s crowded… lots of possibilities)

Questions:

  1. Does that make sense at all?
  2. Should I represent these as sensor entities, or should I create new Vehicle (or Transit Vehicle) and Transit Stop entity types?
  3. For stops, rather than having a latitude and longitude, would it be possible for the integration to actually create zones that are linked in some way?

Reuse or recycle — and GeoJSON?

The Transit Stop entities don’t move or otherwise change much unless the MBTA rearranges the service. But the vehicles I’m not sure what to do about. My thoughts on possibilities:

  1. Create a new one every time we see a new id for a vehicle. (These correspond to the numbers on the buses or train cars.)
  2. Create, say, 10 Transit Vehicle entities, and cycle through them.
  3. Create and destroy entities as they appear and disappear in the predictions.

The first option seems interesting if you’re, like, bus-spotting, but not really practically useful. The second seems kludgy. And the third… maybe that’s right? It looks like what the GeoJSON integration does.

If I would go that third route… I see that there’s a special field on the Map Card for " Geolocation Sources". How would I go about adding “Transit Sources”? I assume that’d be “convince the creators of that card to include it”. Or, could I piggy-back on the “Geolocation Sources” functionality in some way?