SL public transport information (Sweden)

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.

I am currently redoing the whole kit to make it into a platform and modernizing all over. This will solve that issue and a heap more. =)

2 Likes

This is really exciting! Looking forward to seeing it!

1 Like

Looking forward to it as well!

1 Like

You know when you dont have the time but you start doing stuff anyways. I just did that. Version 1.0.0 is now on Github, code is on PyPi for the communications library and it have been running stable for about 12 hours at my house… try it out and see what you get as resuts, note there is a breaking change about the name parameter. Also incorporated all change suggestions I have gotten so far as I can see…

https://github.com/DSorlov/ha-sensor-sl/blob/hasl/CHANGELOG.md

1 Like

Just tested the latest version, I cannot make it work with 2 sensors, otherwise it is working great so far.

Edit: Just noticed that the sensor it showing both directions even if I have just one in the configuration.
Edit 2: I found why I get just one sensor instead of 2, both of them are trying to create the same unique id,
"hasl-{}-{}".format(siteid,direction) unfortunately it is not so unique, maybe use a guid instead? I just changed it to "hasl-{}-{}-{}".format(friendly_name,siteid,direction) and now loads both of the sensors.

Changing line 91 in the sensor to self._direction = direction seems to fix the directions problem.

Do you wan to report them as issues in github instead? Or make a PR? Icon for ships should be mdi:ferry mdi:boat doesn’t seem to work.

Perfect! I have moved the friendly name suggestion into the code but saw this post after I worked the list over on GitHub so frankly just missed it but will make a new push later today, I will probably change this naming in the future as this is not a really good method but a bit unsure how I would like to handle it. Suggestions are welcome. =) Same with the icon.

The direction bug was implemented in the release earlier today. And; yes, I prefer working with tracking stuff in GitHub. =) But thanks anyways for the input! it is invaluable.

2 Likes

Ok good to know. Then if I find something else I’m going to report in github :slight_smile: and keep an eye to the next release to sync the changes without breaking mine.

I did changed some things in the sl card too, but so long just for my needs :slight_smile: in case you need some ideas

sl-card