Components for Belgian public transport


#1

The Belgian public transport companies for railway and busses/metros opened up their data recently to the public.

Maybe somebody finds this interesting to create components for:

https://data.delijn.be/
http://docs.irail.be/#vehicle

Personally I do not get around by public transport, but it can be useful.


#2

I do use Belgian public transport and it would be nice to have this integrated into home assistant (mostly the irail.be api)
That way i can glance in the morning if the car or the train is faster.


#3

I tried to get it working using the iRail API but know too little Python unfortunately…


#4

@geoffrey @T_L what would you like to get as state value from this component. Managed to set it up and retrieve data from irail in my lunch break:

image


#5

i was looking into implementing this.

what would you like to have integrated?
1- a list of trains departing in a station? = https://docs.irail.be/#stations
2- a specific route (between 2 stations)? = https://docs.irail.be/#connections
3- disturbances? https://docs.irail.be/#disturbances
4- info in one station? https://docs.irail.be/#liveboard

i think 2 and 3 are the highest priority not?


#6

I would also choose 2 and 3 as a starting point.


#7

@thibmaek Really nice that you are picking this up and trying to get this working. I don’t know any python.
As the 2 mentions above. point 1,2 and 3 would be nice to have. I’m looking for a way to calculate the total travel time between 2 station with delays so I can easily see if the train or car (via the waze platform) is faster to work at the moment of departure.


#8

OK! This already uses a connection between 2 stations but the specific question was what the state value should be: the total time it takes? Amount of delay on this connection etc. etc.

I’d link everything else that is relevant data as an attribute since you can only have 1 state field for a sensor.


#9

Ideally for me the total time it takes (including the delay). So probably just like the waze travel time sensor where you get the time it takes to get to a certain location.


#10

Alright, will split them up in multiple sensors like this:

- platform: nmbs
    station_from: 'Brugge'
    station_to: "Gent Dampoort"
    station_live: "Gent Dampoort"

image

PS: Also working on getting De Lijn up and running, nearly there :slight_smile:


#11

i will leave this component up to you, as you are far further then me :slight_smile:


#12

Cool. I have the live sensor pretty much done. Until I manage to make a PR to Home Assistant itself anyone can track the progress here: https://github.com/thibmaek/custom-components/blob/master/sensor/nmbs.py

image


#13

iRail is great :slight_smile: i used to do a student job for them.
But you might want to check out the official data from the nmbs.

As of today, you can request the official GTFS real-time feeds of SNCB! This is great news: our real-time feeds were only a scraped version of what was announced on their websites. If you now want to rely on a high-quality data feed of train disturbances and train delays, you can rely on their new feeds. Request this over here:

http://www.belgianrail.be/nl/klantendienst/infodiensten-reistools/public-data.aspx


#14

i requested access :slight_smile:

@thibmaek cool you also have the velo sensor integrated :slight_smile:

we should get that one merged into HA


#15

I requested this before and then needed to sign a Word document with a bunch of stuff I didn’t want to fill in.
Would rather use the iRail API.

Using this GTFS feed is probably also better with the HA provided sensor.gtfs platform


#16

Chance that I’ll ever merge this again is small though. See this PR I previously made but closed: https://github.com/home-assistant/home-assistant/pull/18276#pullrequestreview-172266227

Still, the custom component is available and works excellent:

image


#17

how wopuld you pass 2 directions?

i want one for my daily track to, and one for my track back from work


#18

Create 2 sensors:

sensor:
  - platform: nmbs
    name: "Work"
    from: "Gent Dampoort"
    to: "Brugge"
  - platform: nmbs
    name: "Home"
    from: "Brugge"
    to: "Gent Dampoort"

#19

I had some errors in my log file today

Traceback (most recent call last):
File “/home/cereal/home-assistant/homeassistant/helpers/entity.py”, line 221, in async_update_ha_state
await self.async_device_update()
File “/home/cereal/home-assistant/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/cereal/.homeassistant/custom_components/sensor/nmbs.py”, line 144, in update
next_connection = connections[“connection”][0]
TypeError: ‘int’ object is not subscriptable


#20

Using the config you provided, I get an error message

  - platform: nmbs
    name: "Work"
    from: "Gent Dampoort"
    to: "Brugge"


2018-11-16 14:01:17 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.nmbs]: required key not provided @ data['station_from']. Got None
required key not provided @ data['station_live']. Got None
required key not provided @ data['station_to']. Got None. (See ?, line ?). 
2018-11-16 14:01:17 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.nmbs]: required key not provided @ data['station_from']. Got None
required key not provided @ data['station_live']. Got None
required key not provided @ data['station_to']. Got None. (See ?, line ?).