Show next bus departures

I want to show next bus departures from my location.
Next 3 departures and time for departure would be great.

Here is the link to bus information:
Bus departures

Is there a way I can scrape this information and show if in HA?

1 Like

Thank you! Just wish I had the knowledge to do this :slight_smile:

Ask the bus company where their API is.

In fairness, I think the api (if such even exists) would be just as much work as scraping the site.

@borgeolsen, notice when you select the bus route it gives you a nice long url in the browser which basically contains the request you want, then you use that url in your scrape sensor to return the time fields. So from a random click on the page I got the url…

https://rp.tromskortet.no/scripts/TravelMagic/TravelMagicWE.dll/turinfo?dep1=1&from=Kleiva+(Harstad)&direction=1&date=24.10.2018&time=01%3A41&now=1&destinations=Harstad+Byterminal&changepenalty=1&changepause=0&through=&throughpause=&lang=en&trip=43397.1822.1297572166&starthpl=19031302%3A1&startdate=24.10.2018

So I’m guessing that dep1=1&from=Kleiva+(Harstad)&direction=1& is all just saying an outgoing bus from that stop, date/time/now are telling it when to pick from the timetable, the destination and a few other options to tweak the results.

Once you get the url that reliably outputs the data you want, click view-source on your browser and find what tags the data you want is in, and hopefully we can configure the scrape sensor to pluck it out.

1 Like

I have found that this is the url gives me exactly what I need:

https://rp.tromskortet.no/scripts/TravelMagic/TravelMagicWE.dll/svar?dep1=1&from=19031302%3A1&direction=1&now=1&destinations=Harstad+Byterminal&changepenalty=1&changepause=0&through=&throughpause=&lang=no

The original url was much longer, coming from their website tromskortet.no.

About finding tags, I am not sure how to do that. This is what I found when inspecting the data:

So yeah, all the times appear in the tags

<span class="tm-block-float tm-departurelist-time">
                    17:11
                </span>

The problem now is working out how to convey that to the scrape sensor - I can try and have a play with it later this evening - or maybe @fabaff can give us a clue?

Thank you so much :slight_smile:

This is ugly AF… but it works :stuck_out_tongue:

  - platform: command_line
    name: "Buss Kleiva (Harstad) -> Harstad Byterminal"
    command: "curl -sSL 'https://rp.tromskortet.no/scripts/TravelMagic/TravelMagicWE.dll/svar?dep1=1&from=19031302%3A1&direction=1&now=1&destinations=Harstad+Byterminal&changepenalty=1&changepause=0&through=&throughpause=&lang=no' | grep '                    ' | sed -n '58p' | awk -F' ' '{ print $1 }'"

image

2 Likes

Wow. This is a good start :smile:

Agreed, maybe not the best presentation. But it looks like this can be done.

My hope is that it would be possible to present it in a nice box, with all the information lined up nicely :slight_smile:

Was not the “box” I ment but the way I got the data :wink:

2 Likes

God job making that work anyway :slight_smile:

Would be better to get a component working for entur’s API that would cover all of norway but I have no idea how to do that :man_shrugging:

Is there a published api?

Yes: https://www.entur.org/dev/api/

My Norwegian is non existent, but no doubt someone should be able to work with it.

I have tried but it was too complex for the end user to use :confused:

Accoring to @Danielhiversen Entur is integrated:
https://github.com/home-assistant/home-assistant/pull/17286

Having said that I can’t find this component in HA (Platform not found: sensor.entur_public_transport) so I guess the component didn’t make it to the the 0.83.1 update.

1 Like

That component was only merged in to the dev branch 7 hours ago, will take a little bit of time to be available in homeassistant, at the very least you’ll have to wait for the next release :slight_smile:

1 Like

You have to use the dev branch or wait for 0.84

1 Like