Components for Belgian public transport

That’s nice! What are those cards?

see below config, i’m using the following custom cards

Bar-card
Attributes card / entity row

entities:
  - entity: sensor.train_home
    from: left
    height: 30px
    indicator: true
    max: 40
    min: 0
    rounding: 5px
    saturation: 50%
    severity:
      - hue: '120'
        value: 30
      - hue: '40'
        value: 31
      - hue: '0'
        value: 35
    style:
      '--paper-card-background-color': 'rgba(84, 95, 108, 0.7)'
      border-radius: 8px
      left: 1%
      overflow: hidden
      top: 29%
      transform: none
      width: 48%
    title: Train Home
    type: 'custom:bar-card'
    width: '70'
  - entity: sensor.train_home
    filter:
      exclude:
        - sensor.train_home.at*
        - sensor.train_home.fr*
        - sensor.train_home.oc*
        - sensor.train_home.ic*
        - sensor.train_home.oc*
        - sensor.train_home.uni*
      include:
        - sensor.train_home.*
    heading_name: Home
    heading_state: '  '
    type: 'custom:entity-attributes-card'
  - entity: sensor.train_work
    from: left
    height: 30px
    indicator: true
    max: 40
    min: 0
    rounding: 5px
    saturation: 50%
    severity:
      - hue: '120'
        value: 30
      - hue: '40'
        value: 31
      - hue: '0'
        value: 35
    style:
      '--paper-card-background-color': 'rgba(84, 95, 108, 0.7)'
      border-radius: 8px
      left: 1%
      overflow: hidden
      top: 29%
      transform: none
      width: 48%
    title: Train Work
    type: 'custom:bar-card'
    width: '70'
  - entity: sensor.train_work
    filter:
      exclude:
        - sensor.train_work.at*
        - sensor.train_work.fr*
        - sensor.train_work.oc*
        - sensor.train_work.ic*
        - sensor.train_work.oc*
        - sensor.train_work.uni*
      include:
        - sensor.train_work.*
    heading_name: Work
    heading_state: '  '
    type: 'custom:entity-attributes-card'
show_header_toggle: false
type: entities

Just finished adding displaying if the train is a via train and show on map:

Nice update; what’s more useful if to add real time arrival/departure instead of arriving in 4 minutes.
I cant even use that as template sensor if wanted to.

For example I want to monitor the train arriving at 8h34 in Brussels or any train between 8 o’clock till 8h30.

I’ll try to do that in 2.1

@thibmaek just upgraded to the latest HA version 0.89 and I got the following error:

lan hass[27455]: 2019-03-07 09:38:50 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Mar 07 09:38:50 raspi.lan hass[27455]: Traceback (most recent call last):
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/usr/local/lib/python3.6/asyncio/tasks.py", line 179, in _step
Mar 07 09:38:50 raspi.lan hass[27455]:     result = coro.send(None)
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 352, in _async_add_entity
Mar 07 09:38:50 raspi.lan hass[27455]:     await entity.async_update_ha_state()
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 239, in async_update_ha_state
Mar 07 09:38:50 raspi.lan hass[27455]:     device_attr = self.device_state_attributes
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/sensor/nmbs.py", line 197, in device_state_attributes
Mar 07 09:38:50 raspi.lan hass[27455]:     'occupancy': self._attrs['departure']['occupancy']['name'],
Mar 07 09:38:50 raspi.lan hass[27455]: KeyError: 'occupancy'
Mar 07 09:38:50 raspi.lan hass[27455]: 2019-03-07 09:38:50 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Mar 07 09:38:50 raspi.lan hass[27455]: Traceback (most recent call last):
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/usr/local/lib/python3.6/asyncio/tasks.py", line 179, in _step
Mar 07 09:38:50 raspi.lan hass[27455]:     result = coro.send(None)
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 352, in _async_add_entity
Mar 07 09:38:50 raspi.lan hass[27455]:     await entity.async_update_ha_state()
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 239, in async_update_ha_state
Mar 07 09:38:50 raspi.lan hass[27455]:     device_attr = self.device_state_attributes
Mar 07 09:38:50 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/sensor/nmbs.py", line 127, in device_state_attributes
Mar 07 09:38:50 raspi.lan hass[27455]:     'occupancy': self._attrs['occupancy']['name'],
Mar 07 09:38:50 raspi.lan hass[27455]: KeyError: 'occupancy'
Mar 07 09:38:51 raspi.lan hass[27455]: 2019-03-07 09:38:51 INFO (SyncWorker_8) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -s 6
Mar 07 09:38:51 raspi.lan hass[27455]: 2019-03-07 09:38:51 INFO (SyncWorker_13) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -s 10
Mar 07 09:38:51 raspi.lan hass[27455]: 2019-03-07 09:38:51 INFO (SyncWorker_10) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -t 0
Mar 07 09:38:51 raspi.lan hass[27455]: 2019-03-07 09:38:51 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform mqtt is taking over 10 seconds.
Mar 07 09:38:51 raspi.lan hass[27455]: 2019-03-07 09:38:51 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Mar 07 09:38:51 raspi.lan hass[27455]: Traceback (most recent call last):
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/usr/local/lib/python3.6/asyncio/tasks.py", line 179, in _step
Mar 07 09:38:51 raspi.lan hass[27455]:     result = coro.send(None)
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 352, in _async_add_entity
Mar 07 09:38:51 raspi.lan hass[27455]:     await entity.async_update_ha_state()
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 239, in async_update_ha_state
Mar 07 09:38:51 raspi.lan hass[27455]:     device_attr = self.device_state_attributes
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/sensor/nmbs.py", line 127, in device_state_attributes
Mar 07 09:38:51 raspi.lan hass[27455]:     'occupancy': self._attrs['occupancy']['name'],
Mar 07 09:38:51 raspi.lan hass[27455]: KeyError: 'occupancy'
Mar 07 09:38:51 raspi.lan hass[27455]: 2019-03-07 09:38:51 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Mar 07 09:38:51 raspi.lan hass[27455]: Traceback (most recent call last):
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/usr/local/lib/python3.6/asyncio/tasks.py", line 179, in _step
Mar 07 09:38:51 raspi.lan hass[27455]:     result = coro.send(None)
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 352, in _async_add_entity
Mar 07 09:38:51 raspi.lan hass[27455]:     await entity.async_update_ha_state()
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 239, in async_update_ha_state
Mar 07 09:38:51 raspi.lan hass[27455]:     device_attr = self.device_state_attributes
Mar 07 09:38:51 raspi.lan hass[27455]:   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/sensor/nmbs.py", line 197, in device_state_attributes
Mar 07 09:38:51 raspi.lan hass[27455]:     'occupancy': self._attrs['departure']['occupancy']['name'],
Mar 07 09:38:51 raspi.lan hass[27455]: KeyError: 'occupancy'

Yup, I’m aware of the issue. Seems like something changed in the iRail API and the component needs to be updated.

Feel free to make this into an issue on HA’s Github and tag me (@thibmaek) so I can look into it.

done, there is still one open, just added an update to that request

HI,

what station name is to be used? the components documentation states is uses the api.irail.be which shows name Gent-Dampoort, but you use Gent Dampoort?:

station locationX="3.740591" locationY="51.056365" id="BE.NMBS.008893120" URI="http://irail.be/stations/NMBS/008893120" standardname="Gent-Dampoort">Ghent-Dampoort</station>

I ask because I need to travel to Brussel Noord, which is listed in the api as Brussel-Noord/Bruxelles-Nord:

station locationX="4.360846" locationY="50.859663" id="BE.NMBS.008812005" URI="http://irail.be/stations/NMBS/008812005" standardname="Brussel-Noord/Bruxelles-Nord">Brussels-North</station>

following the above, would I need:

  - platform: nmbs
    station_from: 'Essen'
    station_to: 'Brussel-Noord/Bruxelles-Nord'
    station_live: 'Essen'
    exclude_vias: true
    name: Essen - Brussel Noord
    show_on_map: true

or:

  - platform: nmbs
    station_from: 'Essen'
    station_to: 'Brussel Noord'
    station_live: 'Essen'
    exclude_vias: true
    name: Essen - Brussel Noord
    show_on_map: true

iRail API is pretty flexible in naming I noticed: you can just use it like that:

Best way to check is just seeing if the URL with your station returns a valid response (see screenshot)

not sure why, but trying this doesn’t give me any sensor:

sensor:

  - platform: nmbs
    station_from: 'Essen'
    station_to: 'Brussel-Noord'
    station_live: 'Essen'
    exclude_vias: true
    name: Essen - Brussel Noord
    show_on_map: true

  - platform: nmbs
    station_from: 'Brussel-Noord'
    station_to: 'Essen'
    station_live: 'Brussel-Noord'
    exclude_vias: true
    name: Brussel Noord - Essen
    show_on_map: true

That’s related to the errors posted above and https://github.com/home-assistant/home-assistant/issues/20744

If you check your logs you should have a similar error.

ok thanks for clarifying, btw I’m on 87.1, so guess will wait for this to be resolved and try again.

Great addon !

I second the request to cut the “Vehicle ID” to only show the train number.
Drop the “BE.NMBS.”-part, please.

Hi,

I can see the issue was closed on github, but was it fixed or not? I just configured this integration but see no sensor in the entity registry.

If your line has no current connection (for example Bruges -> Aalter) it might take until the next connection to show up (next day)

Thanks for the quick response. The error was due to my config yaml, apparently all sensor platforms need to be listed under one sensor entry (i had multiple).

Hi again,

been playing around with the sensor for a while now. Am I right assuming the state of the sensor only returns the next train that’s going to depart (for both the live board and specific route sensor)? I’m trying to get an array of trains so I can make a list appear in Home Assistant.

Presuming the sensor can’t give you access to an array of trains, I just made a custom card to display a liveboard for a given route (it’s not using this nmbs integration, but direcly using the iRail api).

If anyone is interested you can find it here:

2 Likes

nice, can you share the styled card config please?

edit : can you fix the missing zero per screenshot below