home / skills / openclaw / skills / trein

trein skill

This skill helps you query Dutch Railways NS for real-time departures, trips, disruptions, and stations via the trein CLI.

npx playbooks add skill openclaw/skills --skill trein

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
2.3 KB
---
name: trein
description: Query Dutch Railways (NS) for train departures, trip planning, disruptions, and station search via the trein CLI.
homepage: https://github.com/joelkuijper/trein
metadata: {"clawdbot":{"emoji":"🚆","requires":{"bins":["trein"],"env":["NS_API_KEY"]},"primaryEnv":"NS_API_KEY","install":[{"id":"npm","kind":"node","package":"trein","bins":["trein"],"label":"Install trein (npm)"},{"id":"download-mac-arm","kind":"download","url":"https://github.com/joelkuijper/trein/releases/latest/download/trein-darwin-arm64","bins":["trein"],"label":"Download (macOS Apple Silicon)","os":["darwin"]},{"id":"download-mac-x64","kind":"download","url":"https://github.com/joelkuijper/trein/releases/latest/download/trein-darwin-x64","bins":["trein"],"label":"Download (macOS Intel)","os":["darwin"]},{"id":"download-linux","kind":"download","url":"https://github.com/joelkuijper/trein/releases/latest/download/trein-linux-x64","bins":["trein"],"label":"Download (Linux x64)","os":["linux"]}]}}
---

# trein - Dutch Railways CLI

A CLI for the NS (Dutch Railways) API with real-time departures, trip planning, disruptions, and station search.

## Install

npm (recommended):
```bash
npm i -g trein
```

Or download a standalone binary from [GitHub Releases](https://github.com/joelkuijper/trein/releases).

## Setup

Get an API key from https://apiportal.ns.nl/ and set it:
```bash
export NS_API_KEY="your-api-key"
```

Or create `~/.config/trein/trein.config.json`:
```json
{ "apiKey": "your-api-key" }
```

## Commands

### Departures
```bash
trein departures "Amsterdam Centraal"
trein d amsterdam
trein d amsterdam --json  # structured output
```

### Trip Planning
```bash
trein trip "Utrecht" "Den Haag Centraal"
trein t utrecht denhaag --json
```

### Disruptions
```bash
trein disruptions
trein disruptions --json
```

### Station Search
```bash
trein stations rotterdam
trein s rotterdam --json
```

### Aliases (shortcuts)
```bash
trein alias set home "Amsterdam Centraal"
trein alias set work "Rotterdam Centraal"
trein alias list
trein d home  # uses alias
```

## Tips
- Use `--json` flag for all commands to get structured output for parsing
- Station names support fuzzy matching (e.g., "adam" -> "Amsterdam Centraal")
- Aliases are stored in the config file and can be used in place of station names

Overview

This skill provides a command-line interface to the Dutch Railways (NS) API for real-time departures, trip planning, disruptions, and station search. It is built for quick lookups, scripting, and integration with other tools via JSON output. The CLI supports fuzzy station matching and persistent aliases for frequent routes.

How this skill works

You install the trein CLI and supply an NS API key via environment variable or a local config file. Commands query the NS API for departures, planned trips, current disruptions, and station lookup. Use the --json flag to receive structured output suitable for automation and downstream parsing.

When to use it

  • Check live departures for a station before leaving home or work.
  • Plan a trip between two stations including real-time connections.
  • Monitor network disruptions and planned engineering works.
  • Integrate train data into scripts, dashboards, or home automations.
  • Quickly search stations with fuzzy name matching when unsure of the exact spelling.

Best practices

  • Store your NS API key in the NS_API_KEY environment variable or in ~/.config/trein/trein.config.json for repeatable usage.
  • Use the --json flag when piping output into other tools or scripts to avoid brittle text parsing.
  • Create aliases for frequently used stations to speed up repeated commands (e.g., home, work).
  • Validate station names with the stations command before planning complex trips.
  • Rate-limit automated queries to respect the API usage policy and avoid key suspension.

Example use cases

  • Get the next departures from Amsterdam Centraal in a shell script and format into a notification.
  • Plan a commute from Utrecht to Den Haag Centraal and export the itinerary as JSON for a mobile app.
  • Run a periodic check for disruptions and send an alert when relevant lines are affected.
  • Search for a station using a partial name like 'adam' and use the result to set up an alias.
  • Bundle train departure checks into a morning automation that notifies household members of delays.

FAQ

How do I provide the NS API key?

Set NS_API_KEY in your environment or create ~/.config/trein/trein.config.json with { "apiKey": "your-api-key" }.

Can I use the output in other programs?

Yes — add --json to any command to receive structured JSON suitable for parsing and integration.