Skip to main content

Train Commute Companion

HACS Custom Validate GitHub release PyPI Python Home Assistant License

Follows your usual NS train journey and tells you when something changes: a delay, a cancelled train, a platform change or a transfer you can no longer make.

Data: NS. You bring your own NS API key; none is bundled. This project is not made by or linked to NS.

Open your Home Assistant instance and open this repository in HACS.

What it does

  • Follows your trains. You describe your usual trips once, in a small YAML file. On a travel day it picks your train and watches it.
  • Tells you what changed. Delays, cancellations, platform changes, a train cut short, a new route, a transfer at risk or broken, and a train you missed.
  • Suggests what to do. When your train no longer works, it names the best train you can still catch.
  • Looks ahead. Before the day, it warns you about planned works on your route.
  • Summarizes the week. An optional works digest checks seven calendar days and labels unknown coverage.
  • Tracks replacement transport. Follow reviewed bus, walk and metro plans with explicit boarding and arrival confirmations. Replacement transport.
  • Shows crowd forecasts. NS forecasts appear with your trains and alternatives; changed forecasts can send silent updates. Crowd forecasts.
  • Changes plans and alerts. Resume a skipped journey and control quiet or paused notifications in Home Assistant.
  • Pauses for holidays. Set an inclusive date range and monitoring resumes afterward. Holiday pauses.
  • Uses weekday departure times. Set different first trains within one profile while preserving already-followed journeys. Weekday schedules.
  • Shows train context. Optional NS composition, listed capacity and candidate vehicle coordinates include source limits. Train context.
  • Loud only when it matters. Alerts you must not miss ring; small updates arrive silently.
  • Says when NS is unclear. When NS gives two different answers about the same train, you get both, so you can decide.

Ways to run it

Way What you get Guide
Home Assistant (HACS) Alerts on your phone through the companion app, sensors and buttons docs/home-assistant.md
Docker Alerts and buttons in a private Telegram chat docs/docker.md
Household A separate Docker companion and private bot for each traveller docs/household.md
Webhooks Each alert as signed JSON to your own URL, from Docker or Home Assistant docs/webhooks.md
Email Optional encrypted SMTP copies alongside Telegram in Docker docs/email.md
Today Private read-only journey and service status in a browser, from Docker docs/docker.md
MCP Three read-only tools (status, next connections, planned works) for a local MCP client docs/mcp.md

Location (optional) helps it know when you leave and where you are. See Where you are below.

Profiles can request accessible journeys and disable notification categories. These settings also appear in the Home Assistant profile form.

Save an explicit arrival to compare it with the original plan and optionally check NS compensation rules. The companion does not decide eligibility. Today also offers deliberate calendar and offline route-preview downloads.

Quick start (Home Assistant)

  1. In HACS, add https://github.com/rhnfzl/train-commute-companion as a custom repository of type Integration, or use the button above.
  2. Download Train Commute Companion and restart Home Assistant.
  3. Add the integration under Settings, Devices and services, and enter your NS API key.
  4. Enable guided setup to choose stations and trains in forms, or select an existing profiles file.

The full guide is in docs/home-assistant.md.

Where you are

A timetable app knows your train. It does not know where you are. With location on, the companion can:

  • see that you are still at home when your train leaves, and tell you the next train and when to leave;
  • see that you are on the train, so a late phone position does not cause a false "you missed it";
  • pick the next train you can catch when you leave home before your usual train leaves.

Phones often report a position minutes late. A position just after the departure does not prove a miss. The companion also checks movement, Wi-Fi, activity and time:

flowchart TD
    A["Your train leaves"] --> B{"Any sign you ride?<br/>Left the zone, 8 m/s or more,<br/>or Automotive"}
    B -- yes --> C["Keep following your train"]
    B -- no --> D{"Tracker still places you at home/work<br/>or at your boarding station?"}
    D -- no --> C
    D -- yes --> E{"Proof?<br/>Home/work Wi-Fi on, buffer over 5 min;<br/>or Stationary/Walking, 3 min after departure;<br/>or still there after 12 min"}
    E -- no --> C
    E -- yes --> F["You missed it: next train.<br/>At home/work also: leave by"]

Activity counts only when reported after the departure and at most 5 minutes ago. Without proof the train stays followed, and you may get a quiet "has left. If you are not on it, next train" note. Regular train alerts still apply. Full rules: Missed trains. Other sources: OwnTracks, Telegram.

Phone setup (Home Assistant companion app)

  1. Location: Always. iOS: Settings, Privacy & Security, Location Services, Home Assistant: Always, Precise Location on. Android: Allow all the time.
  2. Motion (optional, recommended). iOS: the app does not ask by itself. In the app open Settings, Companion App, Sensors, tap the blue Motion link and allow access, then enable Activity. Android: enable Detected activity. Details.
  3. Check it. In Home Assistant, Developer tools, States: your phone tracker has latitude and longitude, and the activity sensor is not unavailable.

Then add the location block to your profile. Steps and the optional Wi-Fi tracker: Location with Home Assistant.

The Python core

The core is a typed Python library on PyPI. It has no Home Assistant code.

It is released for its two shells, the Home Assistant integration and the Docker app, so its module APIs can change between versions. The supported entry point is the tcc command: check-profile, replay and run.

pip install train-commute-companion
tcc check-profile profiles.yaml

Development

uv run --extra app pytest -q        # core and app tests (the extra installs the MCP SDK)
uv run --extra app mypy src app/tcc_app
# the published floors: Python 3.12, httpx 0.27, PyYAML 6.0.1 and mcp 2.3
uv run --no-cache --isolated --no-project --python 3.12 --with '.[app]' --with httpx==0.27.0 --with PyYAML==6.0.1 --with mcp==2.3.0 --with pytest --with pytest-asyncio pytest -q tests tests_app
uv run ruff check src tests tests_ha tests_app tests_live custom_components app

# Home Assistant integration: Python 3.14.2+, in its own environment
export UV_PROJECT_ENVIRONMENT=.venv-ha
uv run --python 3.14 --group ha pytest tests_ha -q
uv run --python 3.14 --group ha mypy --explicit-package-bases --namespace-packages -p custom_components.train_commute_companion

The Validate workflow runs these same commands, and a release runs them before it publishes. Each night it also runs tests_ha against the newest Home Assistant test package, because the integration calls private mobile_app code.

Live NS checks run separately with your own key and capture alerts locally.

License

Apache-2.0

Metadata

Release files for train-commute-companion 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for train-commute-companion 0.2.6
File Size Uploaded Provenance Actions
train_commute_companion-0.2.6.tar.gz 998.2 kB With provenance Details for train_commute_companion-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for train-commute-companion 0.2.6
File Interpreter ABI Platform Actions
train_commute_companion-0.2.6-py3-none-any.whl Python 3 none any Details for train_commute_companion-0.2.6-py3-none-any.whl

Total release size: 1.3 MB

Release files / train_commute_companion-0.2.6.tar.gz

Download URL train_commute_companion-0.2.6.tar.gz
Size 998.2 kB
Tags Source
SHA-256 checksum
How to use checksums
719b3d94d3b0c93376587707925b375759786ab131e6ef343498edb69ddca981
BLAKE2b-256 checksum
How to use checksums
0ab340fa11e6dcd02914692fb2f1bef745b8227760df112c98afd3bd701cd0f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / train_commute_companion-0.2.6-py3-none-any.whl

Download URL train_commute_companion-0.2.6-py3-none-any.whl
Size 255.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fa2a1c730a87d480865128aca04b9ebe105cddb504ea16ca6088b30d27e5f97
BLAKE2b-256 checksum
How to use checksums
5920e25e61fc6e1f8fa7d78a6e3fce810f326684bb8bf3a23fe0ac738970bfb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for train-commute-companion 0.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for train_commute_companion-0.2.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page