Giter VIP home page Giter VIP logo

home-assistant-berlin-transport's Introduction

Berlin (BVG) and Brandenburg (VBB) transport widget for Home Assistant

Custom integration that displays upcoming departures from your defined public transport stops for Berlin and Brandenburg.

This repository contains only the integration, the Lovelace card itself lives here: https://github.com/vas3k/lovelace-berlin-transport-card

You need to install them both. Preferably through HACS. We have separated two repositories to make installation through it more convenient.

I use iOS Dark Mode Theme by @basnijholt, installed from HACS

💿 Installation

The component consists of two parts:

  1. A sensor, which tracks departures via VBB public API every 90 seconds. This is this repository.
  2. A widget (card) for the lovelace dashboard, which displays upcoming transport in a nice way. It has its own separate repository with installation instructions.

Install sensor component via HACS

1. Add this repository as a custom repository in HACS in the category "integration".

2. Add Berlin (BVG) and Brandenburg (VBB) transport as a new integration under Settings -> Devices & services

3. Search for your stop (it will provide up to 15 stops that match your query)

4. Select the stop you're looking for

5. Enter further details on which transport, walking time, direction you want

Install sensor component manually

How do I find my stop_id?

Unfortunately, I didn't have time to figure out a proper user-friendly approach of adding new components to Home Assistant, so you will have to do some routine work of finding the IDs of the nearest transport stops to you. Sorry about that :)

Simply use this URL: https://v6.vbb.transport.rest/locations?results=1&query=alexanderplatz

Replace alexanderplatz with the name of your own stop.

🧐 Pro tip: You can also use their location-based API to find all stops nearby using your GPS coordinates.

1. Copy the whole berlin_transport directory to the custom_components folder of your Home Assistant installation. If you can't find the custom_components directory at the same level with your configuration.yml — simply create it yourself and put berlin_transport there.

2. Go to Home Assistant web interface -> Developer Tools -> Check and Restart and click "Restart" button. It will reload all components in the system.

3. Now you can add your new custom sensor to the corresponding section in the configuration.yml file.

sensor:
  - platform: berlin_transport
    departures:
      - name: "S+U Schönhauser Allee" # free-form name, only for display purposes
        stop_id: 900110001 # actual Stop ID for the API
        # direction: 900110002,900007102 # Optional stop_id to limit departures for a specific direction (same URL as to find the stop_id), multiple Values can be specified using a comma separated list
        # walking_time: 5 # Optional parameter with value in minutes that hides transport closer than N minutes
        # suburban: false # Optionally hide transport options
        # show_official_line_colors: true # Optionally enable official VBB line colors. By default predefined colors will be used.
        # duration: 30 # Optional (default 10), query departures for how many minutes from now?
      - name: "Stargarder Str." # currently you have to add more than one stop to track
        stop_id: 900000110501
        # direction: 900000100002 # Optional stop_id to limit departures for a specific direction (same URL as to find the stop_id), multiple Values can be specified using a comma separated list
        # excluded_stops: 900110502,900007102 # Exclude these stop IDs from the departures, duplicate departures may be shown for nearby stations
        # walking_time: 5 # Optional parameter with value in minutes that hide transport closer than N minutes
        # show_official_line_colors: true # Optionally enable official VBB line colors. By default predefined colors will be used.
        # duration: 30 # Optional (default 10), query departures for how many minutes from now?

4. Restart Home Assistant core again and you should now see two new entities (however, it may take some time for them to fetch new data). If you don't see anything new — check the logs (Settings -> System -> Logs). Some error should pop up there.

Add the lovelace card

Go to lovelace-berlin-transport-card repo and follow installation instructions there.

👩‍💻 Technical details

This sensor uses VBB Public API to fetch all transport information.

The component updates every 60-90 seconds, but it makes a separate request for each stop. That's usually enough, but I wouldn't recommend adding dozens of different stops so you don't hit the rate limit.

The VBB API is a bit unstable (as you can guess), so sometimes it gives random 503 or Timeout errors. This is normal. I haven't found how to overcome this, but it doesn't cause any problems other than warning messages in the logs.

After fetching the API, it creates one entity for each stop and writes 10 upcoming departures into attributes.departures. The entity state is not really used anywhere, it just shows the next departure in a human-readable format. If you have any ideas how to use it better — welcome to Github Issues.

🤔 In principle, the HAFAS format is standardized in many other cities too, so you should have no problem adapting this component to more places if you wish. Check out transport.rest for an inspiration.

❤️ Contributions

Contributions are welcome. Feel free to open a PR and send it to review. If you are unsure, open an Issue and ask for advice.

🐛 Bug reports and feature requests

Since this is my small hobby project, I cannot guarantee you a 100% support or any help with configuring your dashboards. I hope for your understanding.

  • If you find a bug - open an Issue and describe the exact steps to reproduce it. Attach screenshots, copy all logs and other details to help me find the problem.
  • If you're missing a certain feature, describe it in Issues and try to code it yourself. It's not hard. At the very least, you can try to bribe me with a PayPal donation to make the feature just for you :)

👮‍♀️ License

home-assistant-berlin-transport's People

Contributors

braintimeexception avatar cornelicorn avatar gamdschi avatar herzogvonwiesel avatar kalambet avatar marcosterland avatar mrueg avatar vas3k avatar vdenisyuk avatar vincemue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

home-assistant-berlin-transport's Issues

Unsorted list of upcoming departures

The API returns a list of departures in unsorted order, therefore next_departure returns not really a next (closest) departure, but rather a first in the returned list of departures. The widget shows the list in unsorted order as well.

Caching API responses

As https://v6.vbb.transport.rest/ mentions, they support caching.

Caching-friendly[🔗](https://v6.vbb.transport.rest/#caching-friendly)

This API sends [ETag](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) & [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) headers, allowing clients cache responses properly.

@vas3k do you know if this is something the custom component would benefit from? (I'm not sure if they reload every time the frontend card is triggered)

Also asking because there's a rate limit of 100 reqs/min

Entity not available

Entities are not available since 14.12.2022 @17:35:24
Adapted berlin_transport to the latest changes as of 13.12.2022

Error occurred loading configuration flow

Hi. Unfortunately after installation and HA restart I have such error message:


Logger: homeassistant.config_entries
Source: config_entries.py:809
First occurred: 22:54:09 (2 occurrences)
Last logged: 22:54:51

Error occurred loading configuration flow for integration berlin_transport: No module named 'custom_components.berlin_transport.config_flow'


2022-12-03 23:14:50.563 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading configuration flow for integration berlin_transport: No module named 'custom_components.berlin_transport.config_flow'


Home Assistant 2022.11.1
Frontend 20221102.1 - latest

Update API to V6

The V5 of the vbb transport rest API is marked as deprecated and currently not responding.

Entity State Unavailable

Hi

I'm new to Home Assistant, and I'm trying to use this component but I'm getting the following error after creating the card:

"Entity State Unavailable"

My configuration:

  • type: custom:berlin-transport-timetable-card
    show_stop_name: true
    max_entries: 8
    entities:
    - sensor.stop_id_900000171514
    - sensor.meraner_str

Home Assistant 2022.12.8

Display warnings

The API provides warnings like

				{
					"id": "213021",
					"type": "warning",
					"summary": "Störung.",
					"text": "Aufgrund des Streiks der Gewerkschaft GDL ist der Zugverkehr der S-Bahn Berlin von Mittwoch den 10. Januar 2 Uhr bis einschließlich Freitag den 12.Januar bis 18 Uhr massiv beeinträchtigt. Bitte mit Zugausfällen rechnen. Für Fahrten innerhalb Berlins nutzen Sie bitte die Verkehrsmittel der BVG (U-Bahn, Tram, Bus). Auch der Regional- und Fernverkehr der Deutschen Bahn sind von diesem Streik betroffen. Bitte informieren Sie sich entsprechend bei diesen Unternehmen.\n<a href=\"https://sbahn.berlin/\" target=\"_blank\" rel=\"noopener\">Information</a>",
					"icon": {
						"type": "HIM2",
						"title": null
					},
					"priority": 32,
					"products": {
						"suburban": true,
						"subway": false,
						"tram": false,
						"bus": false,
						"ferry": false,
						"express": false,
						"regional": false
					},
					"company": "VBB",
					"categories": [
						2
					],
					"validFrom": "2024-01-10T03:00:00+01:00",
					"validUntil": "2024-01-10T15:00:00+01:00",
					"modified": "2024-01-08T08:28:13+01:00"
				},

under departures[].remarks[] e.g. on this endpoint: https://v6.vbb.transport.rest/stops/900100003/departures

It would be nice if we could have them displayed in lovelace as well (I'm not sure how to achieve that though) Maybe a little attention mark on the line icon (not sure if this is an easy thing to do in CSS)

Installation on HA 2023.2.4?

Hi,
I guess I ´m doing something wrong, but I can ´t manage to install it correctly, and I get an error on the configuration when trying to re-start: "Invalid config for [sensor.berlin_transport]: [sensors] is an invalid option for [sensor.berlin_transport]. Check: sensor.berlin_transport->sensors. (See ?, line ?)."
I have copied the berlin_transport folder as per instructions:

image

and added this to my sensors.yaml:

Berlin Transport
  • platform: berlin_transport
    sensors:
    departures:
    • name: "S Heiligensee" # free-form name, only for display purposes
      stop_id: 900091203 # actual Stop ID for the API
      direction: 900089303 # Tegel Optional stop_id to limit departures for a specific direction (same URL as to find the stop_id)
      walking_time: 8 # Optional parameter with value in minutes that hides transport closer than N minutes
    • name: "Ziegenorter Pfad" # currently you have to add more than one stop to track
      stop_id: 900091253
      direction: 900089303 # Tegel Optional stop_id to limit departures for a specific direction (same URL as to find the stop_id)
      walking_time: 7 # Optional parameter with value in minutes that hide transport closer than N minutes

Finally, I copied the berlin-transport-timetable-card.js file to www folder, and added it to the resources. (but I cannot see the card yet, I guess I have to re-start... which I can't as I get an error in the config.

image

help please?

Defining how far to look ahead

First of all, awesome integration, many thanks. Also, we seem to live in the same neighbourhood. :-D.

So, it says in the documentation:
After fetching the API, it creates one entity for each stop and writes 10 upcoming departures into attributes.departures.

The behaviour is a bit different for me. It seems to show all connections in the upcoming 5 - 10 minutes. Is there a way to define this time span? For instance set it to 20 or thirty minutes?

config_flow missing?

I can not install the sensor component following the documentation.

I tried the example configuration-yaml as well as a custom one with my own stops and ids. But whenever I want to add the entity "Berlin (BVG) and Brandenburg (VBB) transport" I get the following error in the home assistance interface: "Der Konfigurationsfluss konnte nicht geladen werden: {"message":"Invalid handler specified"}"

In the log file it shows "2023-02-09 09:41:57.597 ERROR (MainThread) [homeassistant. config_entries] Error occurred loading configuration flow for integration berlin_transport: No module named 'custom_ components berlin_transport.config_flow'"

I can not find the file berlin_transport.config_flow in the git - but I'm new to home assistant and do not understand (yet) the whole concept of flows.

Screenshot 2023-02-09 at 10 07 48

Home Assistant 2023.2.3
Supervisor 2023.01.1
Operating System 9.5
Frontend 20230202.0 - latest

Custom element not found: berlin-transport-timetable-card

Hellooo,

I tried this promising integration, but somehow failed to get the card running. Its my first custom card without HACS, so its probably something I am missing.

I added the integration and can see two entities.

I added the card to www directory:
image

and added the resource:
image

but in the dashboard, I receive an errors
image

Thanks alot!

cannot hide name of stop in card title

Hi,

I changed show_stop_name to false but the title did not hide.
Am I missing something maybe?

image

type: custom:berlin-transport-timetable-card
show_stop_name: false
max_entries: 5
entities:
  - sensor.u_vinetastr_alex
  - sensor.u_vinetastr_heinersdorf

EDIT: not sure what happend, but suddenly I also had the issue , that the custom card was not found.
Just deleted the card.js and added the lovelace card from scratch incl. the ressource and now everything is working again.

Canceled trips are displayed

Dear developers,

I have just noticed that cancelled trips (in case of train cancellations etc.) are unfortunately still displayed.

Perhaps further attributes of the VBB API can be evaluated in order to be able to display aborted trips or not to display them in the first place?

Entity:
Bildschirmfoto vom 2023-02-07 14-47-32

VBB-Fahrinfo:
Bildschirmfoto vom 2023-02-07 14-48-08

Wrong Lovelac Card

Hey together,

thanks for your integration. I follow your steps, but i doesn't got the lovely result.
I do it step by step and got the following result
Screenshot 2023-10-29 123111
Screenshot 2023-10-29 122850

Can you help me?

I'm new in Home Assistant and i hope to get some support of you.

THX
David

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.