When configured, this blueprint should notify you of the trains leaving now and next, when you get near the train station. Iโve set it up to trigger about 500m from the stations I use, so I know if I need to hurry or not.
It features a โRefreshโ button to get the notification again.
Enjoy / Good luck / Sterkte!
blueprint:
name: NS Dagelijkse Reis
description: >-
## โ ๏ธ Prerequisites
1. **Register for NS API access**: Visit https://apiportal.ns.nl/product#product=NsApp to register and get your API key
2. **Install Nederlandse Spoorwegen integration**:
- Go to Settings โ Devices & Services โ Add Integration
- Search for "Nederlandse Spoorwegen"
- Enter your API key from step 1
- Configure your departure station and destination
3. **Create zone entities** for your train stations (Settings โ Areas & Zones)
## What this blueprint does
* Notify when entering a train station zone with current and next train departure times.
* Each automation created from this blueprint handles ONE station with its own time schedule.
* Create multiple automations for different stations (e.g., one for home station in morning, one for work station in evening).
domain: automation
input:
person_entity:
name: Person
description: The person entity to track
selector:
entity:
domain: person
station_zone:
name: Station Zone
description: The zone entity for the train station
selector:
entity:
domain: zone
train_sensor:
name: Train Departure Sensor
description: The sensor that provides train departure information for this route
selector:
entity:
domain: sensor
integration: nederlandse_spoorwegen
notification_device: # Renamed input from notification_service
name: Mobile Notification Device
description: >-
Select the mobile device to send notifications to via the Home Assistant app.
selector:
device:
integration: mobile_app # Filters to only show devices from the mobile_app integration
multiple: false # Assuming you want to send to a single device for this blueprint
start_time:
name: Start Time
description: Only send notifications after this time (e.g., 07:00 for morning commute, 17:00 for evening commute)
default: "07:00:00"
selector:
time:
end_time:
name: End Time
description: Only send notifications before this time (e.g., 10:00 for morning commute, 23:59 for evening commute)
default: "10:00:00"
selector:
time:
active_days:
name: Active Days
description: Days of the week when notifications should be sent
default:
- mon
- tue
- wed
- thu
- fri
selector:
select:
options:
- label: Monday
value: mon
- label: Tuesday
value: tue
- label: Wednesday
value: wed
- label: Thursday
value: thu
- label: Friday
value: fri
- label: Saturday
value: sat
- label: Sunday
value: sun
multiple: true
notification_title:
name: Notification Title
description: Title for the notification
default: "Your Train departures"
selector:
text:
refresh_action_id:
name: Refresh Action ID
description: >-
Unique identifier for the refresh button action.
This should be unique for each automation to avoid conflicts.
default: "refresh_train_info"
selector:
text:
variables:
train_sensor: !input train_sensor
notification_title: !input notification_title
refresh_action_id: !input refresh_action_id
notification_device: !input notification_device # Use the new input name
alias: >-
Train Notification - {{ station_zone | replace('zone.', '') | replace('_', ' ') | title }}
description: >-
Blueprint-generated automation for train departure notifications at {{ station_zone | replace('zone.', '') | replace('_', ' ') | title }}
trigger:
- platform: zone
entity_id: !input person_entity
zone: !input station_zone
event: enter
id: zone_enter
- platform: event
event_type: mobile_app_notification_action
event_data:
action: !input refresh_action_id
id: refresh_button
condition:
- condition: time
after: !input start_time
before: !input end_time
weekday: !input active_days
action:
# Removed the 'choose' block for notification_device validation
- device_id: !input notification_device
domain: mobile_app
type: notify
title: >-
{{ notification_title }}
message: >-
๐ Now: {{ state_attr(train_sensor, 'departure_time_actual') | default('N/A') }} @ {{ state_attr(train_sensor, 'departure_platform_actual') | default('N/A') }}
๐ Next: {{ state_attr(train_sensor, 'next') | default('N/A') }}
data:
icon: mdi:train
push:
sound: default
priority: high
ttl: 0
importance: high
actions:
- action: !input refresh_action_id
title: Refresh
mode: single