I am new to Home Assistant (coming from Homebridge/NodeRed) and I am not a programmer. I am trying to set up some elevator devices from the public API of German Railways. I was searching for hours to even get some results and ended up in some AI generated code that results in several entities, which are not combined to a single device.
Any chance to get a single device out of that?
The JSON output from the API is:
{
"equipmentnumber": 10458690,
"type": "ESCALATOR",
"description": "zu Gleis 103/104 (S-Bahn)",
"geocoordX": 8.6634878,
"geocoordY": 50.10777155,
"state": "ACTIVE",
"stateExplanation": "available",
"stationnumber": 1866,
"operatorname": "DB InfraGO"
}
The AI generated configuration.yml currently looks like that:
rest:
- resource: 'https://apis.deutschebahn.com/db-api-marketplace/apis/fasta/v2/facilities/10458690'
scan_interval: 180
headers:
Accept: "application/json"
DB-Client-ID: "abcdefg"
DB-Api-Key: "12345678"
sensor:
- name: "Aufzug Gleis 103/104 Status"
unique_id: "elevator_10458690_state"
value_template: "{{ value_json.state }}"
device_class: enum
icon: >-
{% if value_json.state == 'ACTIVE' %} mdi:elevator
{% elif value_json.state == 'INACTIVE' %} mdi:elevator-off
{% else %} mdi:elevator-variant {% endif %}
- name: "Aufzug Gleis 103/104 Beschreibung"
unique_id: "elevator_10458690_description"
value_template: "{{ value_json.description }}"
icon: "mdi:information-outline"
- name: "Aufzug Gleis 103/104 Erklärung"
value_template: "{{ value_json.stateExplanation }}"
icon: "mdi:text-box-check-outline"
- name: "Aufzug Gleis 103/104 Betreiber"
unique_id: "elevator_10458690_operator
value_template: "{{ value_json.operatorname }}"
icon: "mdi:account-hard-hat"
- name: "Aufzug Gleis 103/104 Geräte-ID"
unique_id: "elevator_10458690_eq
value_template: "{{ value_json.equipmentnumber }}"
icon: "mdi:identifier"
- name: "Aufzug Gleis 103/104 Stationsnummer"
unique_id: "elevator_10458690_stationnumber
value_template: "{{ value_json.stationnumber }}"
icon: "mdi:train"
- name: "Aufzug Gleis 103/104 Typ"
unique_id: "elevator_10458690_type
value_template: "{{ value_json.type }}"
icon: "mdi:tag"
# Geokoordinaten als separate Sensoren (optional, aber nützlich für Karten)
- name: "Aufzug Gleis 103/104 Longitude"
value_template: "{{ value_json.geocoordX }}"
unit_of_measurement: "°"
#device_class: "longitude"
icon: "mdi:map-marker"
- name: "Aufzug Gleis 103/104 Latitude"
value_template: "{{ value_json.geocoordY }}"
unit_of_measurement: "°"
#device_class: "latitude"
icon: "mdi:map-marker"
The device classes longitude and latitude doesn’t exist and are probably an AI hallucination. But nevertheless, it would be great to have a location entity in the device.
And of course, I want to have more devices from different elevators. So the URL may be somehow templated?
https://apis.deutschebahn.com/db-api-marketplace/apis/fasta/v2/facilities/{{EQUIPMENTNUMBER}}
Subscribe to the free API at developers.deutschebahn.com/db-api-marketplace/