SL public transport information (Sweden)

Sorry for the late reply, i guess i missed one file when i converted to non async code.
Ill see if i get some free time to fix this the coming days.

I’m completly new to the home automation scene. Can I just import your repo to my home assistant?

I have seen your library before but not the component. Seems like a very good job to me. Why haven’t you created a PR to get an offical HA component or am I missing something?

Br Qxlkdr

Hi Qxlkdr, I wanted to do some refactoring of the library before I create a PR, but I haven’t managed to get any IDE to work correctly (or it might just be that I have laid out the files incorrectly) , and after trying a few times I just gave up.

I apparently have no idea what I’m doing :stuck_out_tongue:.

Hi Andersson! Fantastic idea, Since you never can trust vasttrafik to inform you of late train arrivals. Never installed a custom python script before. I tried to install this on my hassio installation with no luck so far. Is this just working on a normal HA installation?

@johbe i had so many issues trying to use the xml library python uses, so i just gave up (when you import my library, it tries to compile the xml library and it uses huge amounts of ram, so if you have anything else running on the pi it crashes, i don’t understand how compiling something can use so much ram).
I’m currently working on writing it in c# and using mqtt to get the data into home assistant, but i hit a minor roadblock Format mqtt json fields once that is done i should be able to create a docker container, that some one could convert into a hassio plugin… (i don’t use hassio my self, last time i tried it stopped me from using my pi for other stuff)

Alright I see. BIG THANKS for developing and I hope to see it as a hassio plugin in the future. It would be so cool to have automations created based on the input from trafikverket. Keep up the good work man! :slight_smile:

Did some enhancements on a sensor for SL, feedback is welcome. Please see https://github.com/DSorlov/ha-sensor-sl

1 Like

I’m getting this error. Maybe someone can help with it . I’m running it on Hassio.

2018-12-01 10:57:10 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.sl_somestation fails
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 221, in async_update_ha_state
await self.async_device_update()
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/sensor/sl.py”, line 172, in update
if self._enabled_sensor is None or sensor_state.state is STATE_ON:
AttributeError: ‘NoneType’ object has no attribute ‘state’

Ok, error handling is still lacking a bit… :stuck_out_tongue:

This seems to be an invalid sensor supplied to the function. Must be a binary sensor. If you dont use the sensor just remove that entry.

Thanks. I’m just started with HA.

Let me know if it worked or not =)

Now it works . For what purpose do use binary sensor ? I just removed that line :slight_smile:
Strangely trafiklab do not show that I am accessing API. Maybe it will be updated later.

I have updated the code again, now to actually display the deviances also in the GUI. Not sure if this approach is the best but works for now. =)

1 Like

Hi,

This looks like a great component and a dedicated card is really smart. Thanks for creating and sharing it.

I have tried to follow your instructions and I get no errors but it does not work:

I have set up the sensor as follows:

  - platform: sl
    name: storamossen
    ri4key: redacted
    si2key: redacted
    siteid: 9111
    lines: 17, 18, 19

The sensor renders the following attributes:

attribution: Stockholms Lokaltrafik
unit_of_measurement: min
departure_board: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
deviances: 
friendly_name: sl storamossen
icon: mdi:train-car

The card does not appear in Lovelace. I have installed sl-card.js in the correct folder and referred to it in my ui-lovelace.yaml file (I do not use raw yet).

  - url: /local/custom_ui/sl-card.js
    type: js

The card is applied as follows:

      - type: custom:sl-card
        departures: true
        deviations: true
        updated: true
        name: Avgångar från Stora Mossen
        entities:
          - sensor.sl_storamossen

The custom updater does not display the custom card.

The custom updater displays the component and shows that there is a new version available (0.0.7 vs current 0.0.6) but it does not update.

I would really want to make this work, but I do not know what to do next. Any ideas?

I copied the actual content of sl-card.js to my own file.
I emptied all cashes and website data.
It now works with the issue that Avgång cannot show the å.

I still do not se the card in custom updater and the component still shows there is a new version 0.0.7 even if the version in sl.py is 0.0.6.

It is of course a problem when updates can only be made every four minutes when traffic is more frequent. But I guess the only way to resolve that is to somehow get to silver or gold level.

Hmm… Sorry been offline some days now, have you been able to solve the issues? I would recommend actually going onto github and getting the last version manually, I have not fully got the update stuff to work. No expert in that.

It works just fine now. Only problem is that I cannot get å in Avgång to show.

I don’t know how to do it but as the update of the sensor is made every 10 minutes it would be interesting to estimate the actual departure time based on time elapsed since last update.

Can you please explain how you setup the sensor to turn on/off the status update.

You would have some binary sensor, when that is true it will update and when false it will not. I have a sensor that is only true during the day to reduce the number of calls and increase the intervall of the calls.