mark1foley/ha-gtfs-rt-v2

Not Defined

Closed this issue · 7 comments

I am unable to see the following information.

  • Due in
  • Due at
  • latitude
  • longitude
  • Next Train

and all of the values returned are Not defined. I have attached my configuration below as well as the output of the test script.

sensor:
  - platform: gtfs_rt
    trip_update_url: 'https://gtfsrt.api.translink.com.au/api/realtime/SEQ/TripUpdates'
    vehicle_position_url: 'https://gtfsrt.api.translink.com.au/api/realtime/SEQ/VehiclePositions'
    route_delimiter: '-'
    departures:
    - name: Grovely (Outbound)
      route: BNFG
      stopid: '600385'
      icon: mdi:train
      service_type: Train
    - name: Bowen Hills (Outbound)
      route: BNFG
      stopid: '600005'
      icon: mdi:train
      service_type: Train
INFO:root:Input file configuration is valid.
INFO:__main__:Adding Sensor: Name: Grovely (Outbound), route id: BNFG, direction id: 600385
INFO:sensor:trip_update_url: https://gtfsrt.api.translink.com.au/api/realtime/SEQ/TripUpdates
INFO:sensor:vehicle_position_url: https://gtfsrt.api.translink.com.au/api/realtime/SEQ/VehiclePositions
INFO:sensor:route_delimiter: ,
INFO:sensor:header: None
INFO:sensor:Successfully updated vehicle positions: 200
INFO:sensor:Successfully updated trip data: 200
INFO:sensor:Sensor Update:
INFO:sensor:   Name: Grovely (Outbound)
INFO:sensor:   Route: BNFG
INFO:sensor:   Stop ID: 600385
INFO:sensor:   Direction ID: 0
INFO:sensor:   Icon: mdi:train
INFO:sensor:   Service Type: Train
INFO:sensor:   unit_of_measurement: min
INFO:sensor:   Due in: -
INFO:sensor:   Due at: not defined
INFO:sensor:   latitude: not defined
INFO:sensor:   longitude: not defined
INFO:sensor:   Next Train: not defined
INFO:__main__:Adding Sensor: Name: Bowen Hills (Outbound), route id: BNFG, direction id: 600005
INFO:sensor:Sensor Update:
INFO:sensor:   Name: Bowen Hills (Outbound)
INFO:sensor:   Route: BNFG
INFO:sensor:   Stop ID: 600005
INFO:sensor:   Direction ID: 0
INFO:sensor:   Icon: mdi:train
INFO:sensor:   Service Type: Train
INFO:sensor:   unit_of_measurement: min
INFO:sensor:   Due in: -
INFO:sensor:   Due at: not defined
INFO:sensor:   latitude: not defined
INFO:sensor:   longitude: not defined
INFO:sensor:   Next Train: not defined

Hi,

You are using the incorrect route id - it should be FGBN instead of BNFG

@andrewdrob10 were you ever able to figure this out? I have the same problem and cannot figure it out.

trip_update_url: 'https://opendata.hamilton.ca/GTFS-RT/GTFS_TripUpdates.pb'
vehicle_position_url: 'https://opendata.hamilton.ca/GTFS-RT/GTFS_VehiclePositions.pb'
departures:
- name: '27N Upper James Northbound'
  route: '5083'
  stopid: '2807'
  service_type: 'Bus'

And output from the test script:

INFO:root:Input file configuration is valid.
INFO:__main__:Adding Sensor: Name: 27N Upper James Northbound, route id: 5083, direction id: 2807
INFO:sensor:trip_update_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_TripUpdates.pb
INFO:sensor:vehicle_position_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_VehiclePositions.pb
INFO:sensor:route_delimiter: None
INFO:sensor:header: None
INFO:sensor:Successfully updated vehicle positions: 200
INFO:sensor:Successfully updated trip data: 200
INFO:sensor:Sensor Update:
INFO:sensor:   Name: 27N Upper James Northbound
INFO:sensor:   Route: 5083
INFO:sensor:   Stop ID: 2807
INFO:sensor:   Direction ID: 0
INFO:sensor:   Icon: mdi:bus
INFO:sensor:   Service Type: Bus
INFO:sensor:   unit_of_measurement: min
INFO:sensor:   Due in: -
INFO:sensor:   Due at: not defined
INFO:sensor:   latitude: not defined
INFO:sensor:   longitude: not defined
INFO:sensor:   Next Bus: not defined

Hi, I believe @andrewdrob10 problem was an invalid combination of route and stop id.

The "not defined" message basically means that there is no data for the specified route and stop id combination in the TripUpdate message that was received. This could be because:

  1. It is an invalid combination; or
  2. It is a valid combination but there are no matching services running at the moment, and therefore not in the realtime feed

I just had a look at the hamilton.ca feed and it is completely blank, because it is 1:00am in California. I will look again in a few hours

Hi @mark1foley. Yes I figured that was the case but I cannot for the life of me figure out what I am doing wrong. The stop is 100% correct as it matches the right lat/lng on a map. The route might be incorrect but I've tested it with the other route id with no success. I assume there are two route id's for both directions, one being 5032 and the other 5083.

I'm getting my id values from the GTFS (static) data that I found here: https://googlehsrdocs.hamilton.ca/

Looking at the pdf schedule, service should be resumed now so the feed shouldn't be empty anymore.

Thanks for helping me out.

Hi @StarScream159 , just to be sure (i.e. eliminate my code) I downloaded the RT file from https://opendata.hamilton.ca/GTFS-RT and decoded it using the Google-supplied protoc tool and here are the results.
dump.txt
I agree that 5032 and 5083 are the correct route ids for route '27'. However, stop id 2807 does not appear to be on that route. I can successfully use test.py for stop id '1771':

INFO:main:Adding Sensor: Name: 27N Upper James Northbound, route id: 5083, direction id: 1771
INFO:main:trip_update_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_TripUpdates.pb
INFO:main:vehicle_position_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_VehiclePositions.pb
INFO:main:route_delimiter: None
INFO:main:header: None
INFO:main:Successfully updated vehicle positions: 200
INFO:main:Successfully updated trip data: 200
INFO:main:Sensor Update:
INFO:main: Name: 27N Upper James Northbound
INFO:main: Route: 5083
INFO:main: Stop ID: 1771
INFO:main: Direction ID: 0
INFO:main: Icon: mdi:bus
INFO:main: Service Type: Bus
INFO:main: unit_of_measurement: min
INFO:main: Due in: 0
INFO:main: Due at: 06:12
INFO:main: Latitude: 43.25556945800781
INFO:main: Longitude: -79.87076568603516
INFO:main: Next Bus: not defined

So we now know that GTFS-RT service is working and the code is ok. It's just a matter of getting the stop id correct. They don't make it easy by putting stop numbers on the pdf timetables that are not the stop id in the stops.txt file. But using the attached dump.txt (or alternatively run test.py with the -d DEBUG parameter) you can see the valid stop ids for route 5083. You will need to match up these stop ids with the descriptions in the stops.txt file to find the one you want.

Hope that helps.

That does indeed help! Thanks so much for the dump from the RT file (I didn't know how to do that).

The PDF stop numbers are phone codes that you can use when you call a system standard phone number, then enter the stop code and an automated operator will tell you the time to the next bus. So yeah it's a little misleading. Weird the id's from the stops.txt file don't match up though.

While I suspect this issue is unique to my transit provider, I'll update this ticket when I figure out a solution.

I really appreciate your help, but I think I will give up on this. None of this is making any sense and I feel like it is due to my transit provider. Even your example routeId 5083 and stopId 1771 doesn't work for me now:

INFO:root:Input file configuration is valid.
INFO:__main__:Adding Sensor: Name: 27N Upper James Northbound, route id: 5083, direction id: 1771
INFO:sensor:trip_update_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_TripUpdates.pb
INFO:sensor:vehicle_position_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_VehiclePositions.pb
INFO:sensor:route_delimiter: None
INFO:sensor:header: None
INFO:sensor:Successfully updated vehicle positions: 200
INFO:sensor:Successfully updated trip data: 200
INFO:sensor:Sensor Update:
INFO:sensor:   Name: 27N Upper James Northbound
INFO:sensor:   Route: 5083
INFO:sensor:   Stop ID: 1771
INFO:sensor:   Direction ID: 0
INFO:sensor:   Icon: mdi:bus
INFO:sensor:   Service Type: Bus
INFO:sensor:   unit_of_measurement: min
INFO:sensor:   Due in: -
INFO:sensor:   Due at: not defined
INFO:sensor:   latitude: not defined
INFO:sensor:   longitude: not defined
INFO:sensor:   Next Bus: not defined

Even if I use DEBUG and get a list of stops for a trip, using one of the stops doesn't work either:

DEBUG:sensor:   Received Trip ID 1829835 Route ID: 5083 direction ID 1 Start Time:  Start Date: 
DEBUG:sensor:      Stop: 355796 Stop Sequence: 0 Stop Time: 1704933480
DEBUG:sensor:      Stop: 355977 Stop Sequence: 0 Stop Time: 1704933574
DEBUG:sensor:      Stop: 355976 Stop Sequence: 0 Stop Time: 1704933625
DEBUG:sensor:      Stop: 2801 Stop Sequence: 0 Stop Time: 1704933652
DEBUG:sensor:      Stop: 2817 Stop Sequence: 0 Stop Time: 1704933680

So using stopId 2817 which is 8 minutes in the future (when I did these tests), running it with that value produces:

INFO:root:Input file configuration is valid.
INFO:__main__:Adding Sensor: Name: 27N Upper James Northbound, route id: 5083, direction id: 2817
INFO:sensor:trip_update_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_TripUpdates.pb
INFO:sensor:vehicle_position_url: https://opendata.hamilton.ca/GTFS-RT/GTFS_VehiclePositions.pb
INFO:sensor:route_delimiter: None
INFO:sensor:header: None
INFO:sensor:Successfully updated vehicle positions: 200
INFO:sensor:Successfully updated trip data: 200
INFO:sensor:Sensor Update:
INFO:sensor:   Name: 27N Upper James Northbound
INFO:sensor:   Route: 5083
INFO:sensor:   Stop ID: 2817
INFO:sensor:   Direction ID: 0
INFO:sensor:   Icon: mdi:bus
INFO:sensor:   Service Type: Bus
INFO:sensor:   unit_of_measurement: min
INFO:sensor:   Due in: -
INFO:sensor:   Due at: not defined
INFO:sensor:   latitude: not defined
INFO:sensor:   longitude: not defined
INFO:sensor:   Next Bus: not defined

I can't make heads or tails of this and I've tried for hours. It's time to move on. Again though, appreciate the help and work you've put into this.