Code Monkey home page Code Monkey logo

bkk_stop's Introduction

hacs_badge

Buy me a coffee

BKK Stop Information custom component for Home Assistant

Providing also a custom state card for legacyUI.

This custom component and custom card shows Budapest Public Transportation (BKK) line information departing in the near future from a configurable stop.

Installation

The easiest way to install it is through HACS (Home Assistant Community Store), search for BKK Stop Information in the Integrations.

If you are not using HACS, download the files from custom_components/bkk_stop into your $homeassistant_config_dir/custom_components/bkk_stop.

Once downloaded and configured as per below information you'll need to restart HomeAssistant to have the custom component and the sensors of bkk_stop platform taken into consideration.

Configuration:

Define sensors with the following configuration parameters:


Name Optional Default Description
name N - sensor of bkk_stop type to display
stopId N - StopId as per go.bkk.hu
apiKey N - API Key to BKK data as per opendata.bkk.hu
maxItems Y 0 Number of items to consider. 0 disables this feature
minsAfter Y 20 Number of minutes ahead to show vehicles departing from station
wheelchair Y false Display vehicle's wheelchair accessibility
bikes Y false Display whether bikes are allowed on vehicle
colors Y false Display BKK's default color for the line and the text
ignoreNow Y true Ignore vehicles already in the station
entity_id Y `` Used instead of name for automatic generation of entity_id
inPredicted Y false Calculate time in as per estimated arrival time, when available
routes Y `` List of routes to consider. Those not listed will be discarded
headsigns Y `` List of headsigns to consider. Those not listed will be discarded. Useful for trans stations
minsBefore Y 0 Skip vehicles departing from station in minsBefore minutes, e.g. while walking to the station. Use non-positive value!

On begining of June the test API key has been revoked, therefore to use this integration you'll have to create an account at opendata.bkk.hu, generate an API key for yourself and set that in the integration configuration.

Example

platform: bkk_stop
name: 'bkk7u'
stopId: 'BKK_F00940'
minsAfter: 25
wheelchair: true
apiKey: !secret bkk_apikey
routes:
  - 287
  - 114
  - 213

Lovelace UI

There is a Lovelace custom card related to this component at https://github.com/amaximus/bkk-stop-card.

Legacy UI

Custom state card is provided for presenting data on legacy UI. Pls see the legacyUI directory structure for example.

Lovelace UI:
bkk_stop Lovelace example

bkk_stop's People

Contributors

afarago avatar amaximus avatar heatnet avatar sipimokus avatar t1k3 avatar viktorschlaffer avatar wrt54g 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

Watchers

 avatar  avatar  avatar  avatar

bkk_stop's Issues

Version

No 'version' key in the manifest file for custom integration 'bkk_stop'. This will not be allowed in a future version of Home Assistant. Please report this to the maintainer of 'bkk_stop'

Multiple stopIds

Hi,

It would be nice to be able to set 2 stopids for the same sensor so it would be possible to merge to stops. Like for Tram 1 at Róbert Károly krt:
#F02596
#F02597

It would make it possible to see both directions on the same Lovelace card.

[feature request] Renaming stops displayed on the card

I would like to rename the stop displayed on lovelace.

For example: Bem tábornok utca --> Bem stop

bkk_stop Lovelace example

The name attribute could be used in the yaml like this:

type: custom:bkk-stop-card
entity: sensor.bkk_bem
name: Bem stop

wrong timezone is displayed on the card

steps to reproduce:

  • server (or user running HA on the server) is in UTC while client browser is CET
  • current time in CET is 23:45

card displays:
... in 2 mins at 22:45

While the shown schedule is correct the displayed time is in UTC and not acourding to the TZ of the profile settings

JSONDecodeError problem after restart if no data from station

Hello!

I restarted my HASS after midnight, when no transports some bus stations, and I got this error and these sensors not created:

Logger: homeassistant.components.sensor
Source: custom_components/bkk_stop/sensor.py:122
Integration: Érzékelő (documentation, issues)
First occurred: 00:27:04 (3 occurrences)
Last logged: 00:27:05

Error adding entities for domain sensor with platform bkk_stop
Error while setting up bkk_stop platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 607, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 486, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in _async_write_ha_state
    extra_state_attributes = self.device_state_attributes
  File "/config/custom_components/bkk_stop/sensor.py", line 122, in device_state_attributes
    return json.loads(bkkjson)
  File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 16 (char 15)

At the morning I got back the sensors again. :)

BKK Version: 2.0.0
HASS: 2021.11.5

PS.: Thank you very much the json attribute usage, very impressive and helpful for custom designs!

Characters coding issue

I found recently, that characters coding is wrong for BKK information:

image
image

Is there any possibility to fix it?

minsBefore

Hi,
A suggestion: I guess the main use case is to check when to leave home to catch the next bus. That means the ones arriving earlier than the walking time to the station are not important. Probably the minsBefore parameter can be used for that (maybe with a negative value), so could you add this one? Alternatively, either in this component or in the lovelace card those routes may be discarded.

The bus data is not loading.

Hello, starting from 14:30 today, I am encountering the following error. Theoretically, nothing has changed.
I appreciate your work both in advance and afterwards. It is very useful.

Logger: homeassistant.components.sensor
Source: helpers/aiohttp_client.py:67
Integration: Érzékelő (documentation, issues)
First occurred: 16:52:11 (2 occurrences)
Last logged: 16:52:11

bkk_stop: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 521, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 748, in async_device_update
await task
File "/config/custom_components/bkk_stop/sensor.py", line 167, in async_update
self._bkkdata = await response.json()
File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 67, in json
return await super().json(*args, loads=loads, **kwargs)
File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1104, in json
raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain;charset=iso-8859-1', url=URL('https://go.bkk.hu/api/query/v1/ws/otp/api/where/arrivals-and-departures-for-stop.json?key=apaiary-test&version=3&appVersion=apiary-1.0&onlyDepartures=true&stopId=BKK_F02647&minutesAfter=25')

Display the exact hour and minute of arrival

Hi,

I would like to request a feature to have an option (bool) to enable displaying the hour and minute of arrival like:
14 to Lehel Tér M in 8 mins at 10:05

Thanks!

p.s.: This issue might belong to the other repo where you store the Lovelace card.

After the update, the plugin is not loading.

Hello,

After I installed the latest version of HomeAssistant (https://www.home-assistant.io/blog/2023/06/a/release-20236/), the plugin throws the following error. I assume it's because of Python 3.11.

I would greatly appreciate it if you could look into whether anything can be done about it!

Thanks in advance for your work.

Logger: homeassistant.loader
Source: custom_components/bkk_stop/sensor.py:49
Integration: bkk_stop (documentation, issues)
First occurred: 22:39:35 (2 occurrences)
Last logged: 22:39:35

Unexpected exception importing platform custom_components.bkk_stop.sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 833, in get_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 850, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/bkk_stop/sensor.py", line 49, in <module>
    @asyncio.coroutine
     ^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio' has no attribute 'coroutine'

Still the minutesBefore :(

Sorry, I think it's not a good idea to add the minus sign to the request.
The swagger says, both minutesBefore and minutesAfter set the relative time to server time. So, I'd set it in component config (minsBefore: -10) if I want to see only routes arriving after now(). Adding a minus sign there causes 2 issues actually: it won't work if someone sets a negative time in yaml and the parameter name and value won't be in sync. I see, that the parametes names in BKK service are simply misleading, something like 'from' 'to' would be better, but that's their problem.

Sensor failing - is this already known?

Hello,

in the last 2 weeks I experience many times these errors in the log:

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:945
First occurred: 11:17:01 (1 occurrences)
Last logged: 11:17:01

Update for sensor.nameofsensor fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 945, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1262, in async_device_update
await self.async_update()
File "/config/custom_components/bkk_stop/sensor.py", line 179, in async_update
self._bkkdata = await response.json()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 71, in json
return await super().json(*args, loads=loads, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1166, in json
raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8', url=URL('https://go.bkk.hu/api/query/v1/ws/otp/api/where/arrivals-and-departures-for-stop.json?key=0aa3308e-b39a-434f-88ee-81430ea60da3&version=3&appVersion=apiary-1.0&onlyDepartures=true&stopId=BKK_F02283&minutesAfter=45&minutesBefore=0')

Is this a sensor issue? ...or rather something in my HA config?
Could you provide me some infos where to look into that?

Displaying not rounded arrival informations in minutes

Hello!

I updated this integration to the latest version (2.1.0), and now, the in parameters are containing a lot of decimal places.

Maybe this commit caused the problem, but I am really not sure:
c57faa2
( diff changed to str(diff) )

image
image

PS.: Thank you for this integration. Really helpful!

[feature request] display the exact departure time

Currently the departure time is displayed in relative format.
Displaying it in absolute would be welcomed.
(165 to Kolosy tér in 17 mins) --> (165 to Kolosy tér at 14:27)
It could be switched on in config using an attribute
absolute_times: true #default: false

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.