Git Product home page Git Product logo

metlink-nz's Introduction

Metlink Wellington Transport for Home Assistant

This is a custom component for Home Assistant which uses the Metlink opendata API to obtain realtime departure info for Greater Wellington public transport, which can then be displayed on your Home Assistant dashboard or used in automations.

BuyMeCoffee

Installation

hacs_badge

The integration can be installed using HACS. If you prefer to instal manually, copy custom_components/metlink to your installation's config/custom_components directory.

Configuration

After installing the custom component, you still need to configure it before it will do anything.

The integration can be added from the Integrations configuration screen.

API keys can be obtained by registering on the Metlink Developer Portal. Be sure to subscribe to the "Metlink Open Data API". Currently this is the only API they offer, and is free, but is still unsubscribed by default.

stop_id for Train and Cable Car stops is a 3 to 4 character alphabetic code, and for bus and ferry stops, is a 4 digit numeric code. The IDs are on bus stop signs, or can be looked up on the Metlink main web site.

If your stop is busy with multiple routes, you can filter by route and/or destination. Currently exact matches are expected and only a single route or destination can be specified, though the destination does check the name as well as the stop id for a match, but some of the names that come through the API are abbreviated in ways that do not match the main web site so stop id will be more reliable. The destination filter is only available on the final destination, not any intermediate stops.

Each stop will create a sensor in Home Assistant, which will return the next departure time as its status.

It will also return attributes for departure time, service, service name, destination name, stop id for the destination, status, service alerts and more. The duplication of departure time in the attributes makes more sense when there is more than one result being returned.

If more than 1 result is requested in num_departures, the attributes will be suffixed with a number for second and subsequent departures.

Stop IDs sometimes behave differently, E.g. if your start stop ID is NAEN and the final destination is WELL, it doesn't work but it works with WELL1 as the final destination. To ensure that you have the correct final destination Stop ID, create a sensor without a final destination and get the final destination which shows up in the attributes.

Acknowledgements

Thanks to Greater Wellington Regional Council for making their data available via an open API, and the following users who have submitted improvements to this Home Assistant integration.

  • messum for identifying that train stations are not always 4 characters, and fixing that, and contributing documentation to advise on the new train station naming complexity where major stations have numbered source/destination ids.
  • Me-sudoer for finding an issue with the HA iOS app's different handling of timestamps than web and Android.
  • meringu for contributing service alert support.

metlink-nz's People

Contributors

make-all avatar meringu avatar messum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

metlink-nz's Issues

API Key provided is not valid

Hi there,

Thank you for writing this integration. I have the below issue after pasting in my valid API key using the UI integration.
Error: "The api key provided is not valid."

When I configure the integration in my sensor.yaml; results are unavailable (I configure my sensors in a sperate file).

Sensor.yaml

  • platform: metlink
    api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    stops:
    • stop_id: 3244
      route: CP
    • stop_id: 5008
      destination: 3244
      num_departures: 3

Sensor returning "UNKNOWN" but data is extracting when API is queried directly

Hi there. I've recently noticed that my sensor for tracking the trains running from PAEK to WELL has started reporting as unknown. It has been running fine for the last 2 years, and I would blame an update to HA, but it's the only metlink sensor that's not working...

What works:

  • My sensors for PAEK>WAIK and WELL>PAEK are working as expected in HomeAssistant.
  • Querying the API directly through the Metlink Developer Portal preview and from Terminal via the provided curl script.

I've attached a screenshot of the Dev Portal, and the current sensor behaviour.

There are also errors being reported in the HA logs (I've attached a screenshot of the top level entry, but if you need more detail I'm happy to get it out for you).

Thank you for providing a very niche but very useful add-on!

Screen Shot 2024-05-04 at 11 07 06 PM Screen Shot 2024-05-04 at 11 08 25 PM Screen Shot 2024-05-04 at 11 07 28 PM

Listing Multiple Departures in Dashboard

Hi Jason

Nice Integration!

Quick question. If "Number of Departures to Track" is set to 3 then is it possible to show the next 3 departures on a card? If so which one would you use?

SteveW

Invalid time stamp on iOS devices

When using the integration on both the companion app in or browser (Safari/Edge Chromium) on iOS 14.6 device - the entities card displays 'Invalid Timestamp' for each stop that is monitored.

The integration runs fine on Android.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.