Custom component Stib - Brussels public transportation

Hi,
I’ve checked again, for lines that are not in service, there’s no message.
Thats what I get for pointDetail 5719:

[{'points': [{'gpsCoordinates': {'latitude': 50.809901, 'longitude': 4.317548}, 'id': '5719', 'name': {'fr': 'SAINT-DENIS', 'nl': 'SINT-DENIJS'}}]}]
[{'points': [{'passingTimes': [{'destination': {'fr': 'SPORTCENTRUM R.',
                                                'nl': 'SPORTCENTRUM R.'},
                                'expectedArrivalTime': '2020-05-29T17:36:00+02:00',
                                'lineId': '50'},
                               {'destination': {'fr': 'TRONE', 'nl': 'TROON'},
                                'expectedArrivalTime': '2020-05-29T17:28:00+02:00',
                                'lineId': '54'},
                               {'destination': {'fr': 'DROGENBOS CHATEAU',
                                                'nl': 'DROGENBOS KASTEEL'},
                                'expectedArrivalTime': '2020-05-29T17:30:00+02:00',
                                'lineId': '82'},
                               {'destination': {'fr': 'DIEWEG', 'nl': 'DIEWEG'},
                                'expectedArrivalTime': '2020-05-29T17:28:00+02:00',
                                'lineId': '97'},
                               {'destination': {'fr': 'SPORTCENTRUM R.',
                                                'nl': 'SPORTCENTRUM R.'},
                                'expectedArrivalTime': '2020-05-29T17:45:00+02:00',
                                'lineId': '50'},
                               {'destination': {'fr': 'TRONE', 'nl': 'TROON'},
                                'expectedArrivalTime': '2020-05-29T17:39:00+02:00',
                                'lineId': '54'},
                               {'destination': {'fr': 'DROGENBOS CHATEAU',
                                                'nl': 'DROGENBOS KASTEEL'},
                                'expectedArrivalTime': '2020-05-29T17:33:00+02:00',
                                'lineId': '82'},
                               {'destination': {'fr': 'DIEWEG', 'nl': 'DIEWEG'},
                                'expectedArrivalTime': '2020-05-29T17:47:00+02:00',
                                'lineId': '97'}],
              'pointId': '5719'}]}]

T32 and N12 are missing from this list and the sensor returns an error.

So one cannot know all lines that are passing by a certain stop. I’m afraid one must cycle through all PointByLine and check if the line does pass at the given stop.

Then that either has changed or they have a lot of problems with their api at the moment. See the last card example on my github, that’s how it used/is supposed to be when a line temporarely does not serve a stop. I’ve asked on the forum but haven’t got a reply yet.

Hi, at the moment i don’t know how my lib will react to the end of service. I’ll try it ASAP and i think that the best solution is to raise an exception “end of service” that will contain information about the next passage in the next morning. I’ll try to implement that ASAP. ( https://github.com/helldog136/pystibmivb/issues/2 )

Added methods to get GPS location of Stops
Improved stop_name matching
Added crawling of schedule in GTFS files
When API returns no waiting times or is End_of_service, an Exception is now raised containing information about the next scheduled passage (from GTFS)

Hello Emil, are you ok with the config-flow? Can I help? Where is your latest work so I can look at it and help you a little when I have time.

Kind Regards,

EDIT: 17/06 No news, i guess Emil doesn’t have time at the moment to develop.
I plan on making my own PR with my library then.

See https://github.com/helldog136/ha-stib-mivb

(Still a WIP)

1 Like

@Helldog136 @Emilv2 has any one already looked into API v2?
Seems that we don’t need an api-key anymore and can directly get json from an url like
https://data.stib-mivb.be/api/records/1.0/search/?dataset=waiting-time-rt-production&q=5152&timezone=Europe%2Fbrussels
Time to rewrite pyStibMivb :wink:

Hi, I have seen the mail about API V2, Once I get a bit of time I will rethink pystibmivb… I’m not satified with the current version anyway…

1 Like

I have now played with it a bit. You still need an API key (bot no token anymore).

I created a quick & dirty python script that gets json date from the API and sends it to mqtt

def getJson(q, ds, api):
    #print("getJson")
    url = "https://data.stib-mivb.be/api/records/1.0/search/"
    params = dict(
    dataset= ds,
    q=q,
    start=0,
    rows=99,
    apikey = api
    )

    resp = requests.get(url=url, params=params)
    data = resp.json()
    records = data['records']
    return records

...
    {
    "LT8257191": {
        "arrival": -1,
        "destination": "DROGENBOS",
        "gpscoordinates": "50.809901; 4.317548",
        "message": "Ligne déviée",
        "status": "not available",
        "stopName": "SAINT-DENIS",
        "timestamp": "2022-10-28T18:11:00+02:00"
    },
    "LT8257192": {
        "arrival": -1,
        "destination": "DROGENBOS",
        "gpscoordinates": "50.809901; 4.317548",
        "message": "Ligne déviée",
        "status": "not available",
        "stopName": "SAINT-DENIS",
        "timestamp": "2022-10-28T18:11:00+02:00"
    }
}

In HA I have some mqtt sensors (one for each estimated arrival time):

sensors:
 - platform: mqtt
   name: "50 dir Gare du Midi 1er passage Bervoets"
   state_topic: stib
   value_template: "{{ value_json.L5010851.arrival }}"
   unit_of_measurement: "min"
   state_class: "measurement"
   json_attributes_topic: "stib"
   json_attributes_template: "{{ value_json.L5010851 | default('') | tojson}}"    
 - platform: mqtt
   name: "50 dir Gare du Midi 2e passage Bervoets"
   state_topic: stib
   value_template: "{{ value_json.L5010852.arrival }}"
   unit_of_measurement: "min"
   state_class: "measurement"
   json_attributes_topic: "stib"
   json_attributes_template: "{{ value_json.L5010852 | default('') | tojson}}" 

You can even get the GTFS files via a json request.
But still some data are hard to get (like if a bus is at a certain stop).