I am trying to publish the time of the next train leaving on my Ulanzi clock with Awtrix.
Setup:
HA installed in a virtual machine on my Synology NAS
- Connection to the NS API is successful
- NS Integration works
- MQTT Broker en MQTT Integration also work
- Sending messages to the Ulanzi clock work
- Testing the integration in an automation template also works
But…
Displaying the next departure time on the clock does not work.
Here is the YAML text:
alias: Send next train to Awtrix
description: Sends valid train time to Awtrix via MQTT
mode: single
trigger:
- platform: time_pattern
minutes: "/1" # Every minute
variables:
train_payload: >
{% set going = state_attr('sensor.castricum_amsterdam', 'going') %}
{% if going %}
{% set time = state_attr('sensor.castricum_amsterdam', 'departure_time_planned') %}
{{ '{"text":"Next train: ' ~ time ~ '","duration":15}' }}
{% else %}
{% set next_time = state_attr('sensor.castricum_amsterdam', 'next') %}
{% if next_time %}
{{ '{"text":"Next train: ' ~ next_time ~ '","duration":15}' }}
{% else %}
{{ '{"text":"No valid train info","duration":15}' }}
{% endif %}
{% endif %}
action:
- service: mqtt.publish
data:
topic: aw_trixie
payload: "{{ train_payload }}"
qos: 0
Here is the (working) Jinja2 template:
{% set going = state_attr('sensor.castricum_amsterdam', 'going') %}
{% if going %}
{% set time = state_attr('sensor.castricum_amsterdam', 'departure_time_planned') %}
{"text": "Next train: {{ time }}", "duration": 15}
{% else %}
{% set next_time = state_attr('sensor.castricum_amsterdam', 'next') %}
{% if next_time %}
{"text": "Next train: {{ next_time }}", "duration": 15}
{% else %}
{"text": "No valid train info", "duration": 15}
{% endif %}
{% endif %}
Here is an overview of the state attributes of this integration:
going: true
departure_time_planned: "18:09"
departure_time_actual: "18:10"
departure_delay: true
departure_platform_planned: "2"
departure_platform_actual: "2"
arrival_time_planned: "18:38"
arrival_time_actual: "18:38"
arrival_delay: false
arrival_platform_planned: "4"
arrival_platform_actual: 4b
next: "18:25"
status: normal
transfers: 1
route:
- Castricum
- Amsterdam Sloterdijk
- Amsterdam Centraal
remarks: null
attribution: Data provided by NS
icon: mdi:train
friendly_name: Castricum-Amsterdam
Please help me find what I am doing wrong…