Ich hab mal das Ganze per HTTP bei mir aufgesetzt. Natürlich die Transformationen, wie von Udo beschrieben voraus gesetzt.
Wie bereits weiter oben erwähnt ist aus meiner Sicht kein Switch-Channel möglich (standardmässig), lässt sich ggf. per Rule und ungebundenem Item oder weiterer Anhängsel (z.B. Profile) realisieren. Das kommt halt auf den Grund an.
.things
Code: Alles auswählen
Thing http:url:eis "Eiswarnung" [
baseURL="https://api.eiswarnung.de?key=<KEY>&lat=<GPS_LAT>&lng=<GPS_LNG>,refresh=2000 ]
{
Channels:
Type string : requestDate "Anfrage Datum" [ stateTransformation="JSONPATH:$.result.requestDate"]
Type number : forecastId "Vorschau ID" [ stateTransformation="JSONPATH:$.result.forecastId"]
Type string : forecastText "Vorschau Text" [ stateTransformation="JSONPATH:$.result.forecastText"]
Type string : forecastCity "Vorschau Ort" [ stateTransformation="JSONPATH:$.result.forecastCity"]
Type datetime : forecastDate "Vorschau Datum" [ stateTransformation="JSONPATH:$.result.forecastDate"]
}
...das sieht dann als YAML-Code so aus:
Code: Alles auswählen
UID: http:url:eis
label: Eiswarnung
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
baseURL: https://api.eiswarnung.de?key=<KEY>&lat=<GPS_LAT>&lng=<GPS_LNG>
delay: 0
stateMethod: GET
refresh: 2000
commandMethod: GET
timeout: 3000
bufferSize: 2048
channels:
- id: requestDate
channelTypeUID: http:string
label: Anfrage Datum
description: null
configuration:
mode: READWRITE
stateTransformation: JSONPATH:$.result.requestDate
escapedUrl: false
- id: forecastId
channelTypeUID: http:number
label: Vorschau ID
description: null
configuration:
mode: READWRITE
stateTransformation: JSONPATH:$.result.forecastId
escapedUrl: false
- id: forecastText
channelTypeUID: http:string
label: Vorschau Text
description: null
configuration:
mode: READWRITE
stateTransformation: JSONPATH:$.result.forecastText
escapedUrl: false
- id: forecastCity
channelTypeUID: http:string
label: Vorschau Ort
description: null
configuration:
mode: READWRITE
stateTransformation: JSONPATH:$.result.forecastCity
escapedUrl: false
- id: forecastDate
channelTypeUID: http:datetime
label: AVorschau Datum
description: null
configuration:
mode: READWRITE
stateTransformation: JSONPATH:$.result.forecastDate
escapedUrl: false
Die dazugehörigen Items sind
Code: Alles auswählen
String requestDate "Anfrage Datum" {channel="http:url:eis:requestDate"}
Number forecastId "Vorschau ID" {channel="http:url:eis:forecastId"}
String forecastText "Vorschau Text" {channel="http:url:eis:forecastText"}
String forecastCity "Vorschau Ort" {channel="http:url:eis:forecastCity"}
DateTime forecastDate "AVorschau Datum" {channel="http:url:eis:forecastDate"}
Der Gesamt-String/Array, den du bekommst, sieht so aus
Code: Alles auswählen
[true, Request successful!, 200, 33, 50, 57398, {requestDate=2024-03-08 08:03:22, forecastId=1, forecastText=Eis!, forecastCity=Isny da gewesen, forecastDate=2024-03-08}]
[true, Request successful!, 200, 24, 50, 39398, {requestDate=2024-03-08 13:03:22, forecastId=2, forecastText=Vielleicht Eis., forecastCity=Isny da gewesen, forecastDate=2024-03-09}]
Du kannst, wie von Udo beschrieben, das Item "forecastId" mit einer MAP-Transformation ändern, aber eigentlich wird die entsprechende Texttransformation bereits im Feld "forecastText" bereitgestellt.
Was den Refresh-Intervall betrifft, so habe ich den Wert in meinem Beispiel auf 2000 Sekunden gesetzt. Du kannst das aber noch ein bisschen ändern.
Du hast ja 50 Abfragemöglichkeiten pro Tag frei. Genau ist der Wert - 86400 Sekunden pro Tag / 50 Abfragen = 1728 Sekunden. Das wäre dann der Minimal-Refresh-Wert. (Ich hoffe das stimmt so

)