Anyone using västtrafik component?

You were right. The system dident have the correct local time. Tm_hours was off by 2. After changing it in rasp-config and restarting it the Västtrafik now shows correct time. You are awesome! Thank you for taking the time guiding me!

//Christian

Great! Do you use this regulary to find the time?

Are you on iOS or android? If so then you can use automation apps like workflow or tasker to make favorite trips and get them instead of fiddle with VT or HA. That way you could get more departures then the only upcoming next departure.

Personally I’ve made an app for my apple watch that has my most common journeys (and much more, basically I have all of the VT app functionality in my watch). But it’s a hobby project and not available on the app store. :smile:

Hi @RitteT, could you explain it in more details? I use this component as well as Android. I would like to get more useful information regarding departure, however, the current component is quite limited.

If you use the app tasker you can pretty much extract what info you want.
I don’t have tasker, but on iOS I wrote a script in workflow that pulled out much more info than the component in hass.

Are you familiar with curl and parsing json?

Unfortunately, I’m not familiar with curl and json.

I guess it’s a little been harder then. You need to make network request and parse json. Not very difficult but could be confusing if you’re very new to it.

If you want to learn it, and give Tasker a shot I’ll gladly help you.

1 Like

It would be nice if we could implement something like this in Home assistant. I´m using it today with the Iframe component but i cannot change the background color which is horrible.

Link to see departures
https://vasttrafik.weightpoint.se/?stopId=9021014006480000

Search for stops,
https://vasttrafik.weightpoint.se/

1 Like

Is anyone using this and got this to work?
Seems the API has changed or something is broken?

I’m using it. It basically works, but I had to add the lines separately to the sensors, like:

- platform: vasttrafik
  key: !secret vast_key
  secret: !secret vast_secret
  departures:
    - from: Scandinavium, Göteborg
      name: vast_tram2
      lines:
        - 2
      delay: 0
- platform: vasttrafik
  key: !secret vast_key
  secret: !secret vast_secret
  departures:
    - from: Scandinavium, Göteborg
      name: vast_tram13
      lines:
        - 13
      delay: 0

image
But I haven’t investigated in details yet.

1 Like

What card are you using to get it like that?

1 Like

I’m using custom:flex-table-card

1 Like

Could you share your yaml files? Or atleast the setup for the vasttrafik part?
I have copied your setup above but still doesnt work.
I have created the API as mentioned, even linked it to their applications Reseplanerare and Trafic situations but still doesnt work.

Im not to familiar with flex custom card :confused:

Sure, first make sure Sensor is ok for Västtrafik, and you can see the data in HA:

  1. Add the inputs to sensor: component (or sensors.yaml depending on your config) based on the wiki.
  2. Check if you see the states for the lines (above in my code I named them as sensor.vast_tram2 and sensor.vast_tram13)

Then move on to the Flex-table-card:

  1. Install it according to flex-table-card from github
  2. Check if that is installed correctly → follow the basic examples from github

Once those are OK, you can add a card to the UI. My card is:

type: 'custom:flex-table-card'
title: Public Transport
columns:
  - name: From Scandinavium
    attr: line
  - name: Direction
    attr: direction
  - name: Depart at
    prop: state
entities:
  include:
    - sensor.vast*

Here:
sensor.vast* - will include every Västtrafik sensor component you have created, if you follow my naming rule:

  • name: vast_tram2
  • name: vast_tram13
  • and so on
    Take it step by step to make sure every component is working separately, then combine them :slight_smile:
    GL
5 Likes

Hi, noob here,

I set up Västtrafik developer account and added subscriptions to services to my ”app”. However it’s just showing ”unknown”. Anyone have an idea what’s up?

Thanks
D

1 Like

Thanks - helped a lot…

1 Like

Did you ever find a solution for this? I’m having the same issue.

Also having this issue.

Long time since anyone replied…anyway.

I also had Unkown issue with my sensors, but after using the ID instead of the station name as Destination I got it working.

I know I’m 5 year late on this, but I’ve used the flex-table-card, which is quite flexible to use css, and got decent results:

type: custom:flex-table-card
title: Västtrafik - Svingeln
strict: true
max_rows: 20
sort_by:
  - Departure+
entities:
  include: sensor.vasttrafik_departure_table
columns:
  - name: Sort column
    data: Departure
    align: center
    hidden: true
    modify: >-
      Math.round((Date.parse((x.rtDate ? x.rtDate : x.Date) + " " + (x.rtTime ?
      x.rtTime : x.Time)) - Date.now())/60000)
  - name: Line
    data: Departure
    modify: x.sname
    align: center
    hidden: true
    style: '''background-color: '' + x.bgColor + '';'' + ''color: '' + x.fgColor + '';'''
  - name: Line
    data: Departure
    modify: >-
      '<div style="padding: 1px 1px 4px 1px; height: 16px; color: ' + x.fgColor
      + '; background-color: ' + x.bgColor + '">&nbsp;' + x.sname +
      '&nbsp;</div>'
    align: center
  - name: Direction
    data: Departure
    modify: x.direction
  - name: Departure
    data: Departure
    align: center
    modify: |-
      if (typeof(x.rtTime) == "string" & typeof(x.rtDate) == "string") 
        { 
          var minutes = Math.round(Math.max(0,(Date.parse(x.rtDate + " " + x.rtTime) - Date.now())/60000));
          if (minutes>=60 || isNaN(minutes))
            {{ x.rtTime }}
          else if (minutes == 0)
            "Now"
          else
            {{ minutes }}
        }
      else
        { 
          var minutes = Math.round(Math.max(0,(Date.parse(x.date + " " + x.time) - Date.now())/60000));
          if (minutes>=60 || isNaN(minutes))
            {{ x.time }}
          else if (minutes == 0)
            "Now"
          else
            {{ minutes }}
        }
  - name: Platform
    data: Departure
    align: center
    modify: >-
      x.track + '&nbsp;<ha-icon icon="mdi:' +
      x.type.toLowerCase().replace("tram", "tram-side") +  '"></ha-icon>'
css:
  tbody tr:nth-child(odd): 'background-color: #535B64;'
  tbody tr:nth-child(even): 'background-color: #3C4650;'
style: |
  ha-card {
    --mdc-icon-size: 16px;
    background-color: #3C4650;
  }

It’s probably possible to scrape data from their website directly, but I’m using a rest sensor to fetch this info.
I’ve certainly lots of spaces for improvement, but my sensors settings are on github:

That rest sensor looks awesome!

I just got it working and I copied your css from flex-card as well.
Thank you for the great work!

1 Like