Spritpreise aus Website in Openhab integrieren
- udo1toni
- Beiträge: 13865
- Registriert: 11. Apr 2018 18:05
- Wohnort: Darmstadt
Re: Spritpreise aus Website in Openhab integrieren
Ja, das ist aber quasi die Definition für http1 in grün. Kannst Du mal die genaue Definition für den Cache spritmonitor aus der http.cfg posten?
openHAB4.1.2 stable in einem Debian-Container (bookworm) (Proxmox 8.1.5, LXC), mit openHABian eingerichtet
-
- Beiträge: 58
- Registriert: 15. Okt 2019 19:50
Re: Spritpreise aus Website in Openhab integrieren
Das ist doch in OH3 was für das HTTP-Binding
Dort ein Thing anlegen, unter baseURL die URL eingeben. Show Advanced anklicken und weiter unten dann application/JSON markieren
Der Code mit 6 beispielhaften Channels würde dann so aussehen
Dort ein Thing anlegen, unter baseURL die URL eingeben. Show Advanced anklicken und weiter unten dann application/JSON markieren
Der Code mit 6 beispielhaften Channels würde dann so aussehen
Code: Alles auswählen
UID: http:url:89e7050e8d
label: Austria
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
baseURL: https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48&longitude=16&fuelType=SUP&includeClosed=false
password: keins
delay: 0
stateMethod: GET
refresh: 30
commandMethod: GET
contentType: application/json
timeout: 3000
bufferSize: 2048
username: irgendwas
channels:
- id: Adresse
channelTypeUID: http:string
label: Adresse
description: ""
configuration:
stateTransformation: jsonpath:$.[0].location.address
- id: Preis
channelTypeUID: http:string
label: Preis
description: ""
configuration:
stateTransformation: JSONPATH:$.[0].prices[0].amount
- id: Tankstellenname
channelTypeUID: http:string
label: Tankstellenname
description: ""
configuration:
stateTransformation: JSONPATH:$.[0].name
- id: Adresse5
channelTypeUID: http:string
label: Adresse5
description: null
configuration:
stateTransformation: jsonpath:$.[1].location.address
- id: Preis5
channelTypeUID: http:string
label: Preis5
description: null
configuration:
stateTransformation: JSONPATH:$.[1].prices[0].amount
- id: Tankstellenname5
channelTypeUID: http:string
label: Tankstellenname5
description: null
configuration:
stateTransformation: JSONPATH:$.[1].name
-
- Beiträge: 43
- Registriert: 26. Jan 2019 13:27
Re: Spritpreise aus Website in Openhab integrieren
anbei mein funktionierendes Setup in OH3:
Ich frage die 5 billigsten Tankstellen in meiner Umgebung ab:
"HTTP Binding" und "JSONPath Transformation" installiert
folgendes thing angelegt (in Visual Studio):
in der baseURL muss natürlich latitude und longitude (xx.xxx) entsprechend euren Koordinaten angepasst werden bzw fuelType wenn etwas anderes als der Super Preis angezeigt werden soll
meine Items sehen so aus:
in weiterer folge habe ich dann noch über eine Rule Name und Adresse in ein Item zusammengeführt und über ein mapping das ganze schön formatiert.
Viel Spaß
Ich frage die 5 billigsten Tankstellen in meiner Umgebung ab:
"HTTP Binding" und "JSONPath Transformation" installiert
folgendes thing angelegt (in Visual Studio):
Code: Alles auswählen
Thing http:url:spritmonitor "Spritmonitor" [
baseURL="https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=xx.xxx&longitude=xx.xxxx&fuelType=SUP&includeClosed=false",
refresh=60] {
Channels:
Type string : Ts_1 "TS" [ stateTransformation="JSONPATH:$.[0].name" ]
Type string : Ts_Adresse_1 "Adresse" [ stateTransformation="JSONPATH:$.[0].location.address" ]
Type string : Ts_Preis_1 "Preis" [ stateTransformation="JSONPATH:$.[0].prices[0].amount" ]
Type string : Ts_2 "TS" [ stateTransformation="JSONPATH:$.[1].name" ]
Type string : Ts_Adresse_2 "Adresse" [ stateTransformation="JSONPATH:$.[1].location.address" ]
Type string : Ts_Preis_2 "Preis" [ stateTransformation="JSONPATH:$.[1].prices[0].amount" ]
Type string : Ts_3 "TS" [ stateTransformation="JSONPATH:$.[2].name" ]
Type string : Ts_Adresse_3 "Adresse" [ stateTransformation="JSONPATH:$.[2].location.address" ]
Type string : Ts_Preis_3 "Preis" [ stateTransformation="JSONPATH:$.[2].prices[0].amount" ]
Type string : Ts_4 "TS" [ stateTransformation="JSONPATH:$.[3].name" ]
Type string : Ts_Adresse_4 "Adresse" [ stateTransformation="JSONPATH:$.[3].location.address" ]
Type string : Ts_Preis_4 "Preis" [ stateTransformation="JSONPATH:$.[3].prices[0].amount" ]
Type string : Ts_5 "TS" [ stateTransformation="JSONPATH:$.[4].name" ]
Type string : Ts_Adresse_5 "Adresse" [ stateTransformation="JSONPATH:$.[4].location.address" ]
Type string : Ts_Preis_5 "Preis" [ stateTransformation="JSONPATH:$.[4].prices[0].amount" ]
}
in der baseURL muss natürlich latitude und longitude (xx.xxx) entsprechend euren Koordinaten angepasst werden bzw fuelType wenn etwas anderes als der Super Preis angezeigt werden soll
meine Items sehen so aus:
Code: Alles auswählen
// SPRITMONITOR
String Tankstelle_Name_1 "[%s]" {channel="http:url:spritmonitor:Ts_1"}
String Tankstelle_Adresse_1 "[%s]" {channel="http:url:spritmonitor:Ts_Adresse_1"}
String Tankstelle_Preis_1 "[%s]" {channel="http:url:spritmonitor:Ts_Preis_1"}
String Tankstelle_Name_2 "[%s]" {channel="http:url:spritmonitor:Ts_2"}
String Tankstelle_Adresse_2 "[%s]" {channel="http:url:spritmonitor:Ts_Adresse_2"}
String Tankstelle_Preis_2 "[%s]" {channel="http:url:spritmonitor:Ts_Preis_2"}
String Tankstelle_Name_3 "[%s]" {channel="http:url:spritmonitor:Ts_3"}
String Tankstelle_Adresse_3 "[%s]" {channel="http:url:spritmonitor:Ts_Adresse_3"}
String Tankstelle_Preis_3 "[%s]" {channel="http:url:spritmonitor:Ts_Preis_3"}
String Tankstelle_Name_4 "[%s]" {channel="http:url:spritmonitor:Ts_4"}
String Tankstelle_Adresse_4 "[%s]" {channel="http:url:spritmonitor:Ts_Adresse_4"}
String Tankstelle_Preis_4 "[%s]" {channel="http:url:spritmonitor:Ts_Preis_4"}
String Tankstelle_Name_5 "[%s]" {channel="http:url:spritmonitor:Ts_5"}
String Tankstelle_Adresse_5 "[%s]" {channel="http:url:spritmonitor:Ts_Adresse_5"}
String Tankstelle_Preis_5 "[%s]" {channel="http:url:spritmonitor:Ts_Preis_5"}
Viel Spaß
- udo1toni
- Beiträge: 13865
- Registriert: 11. Apr 2018 18:05
- Wohnort: Darmstadt
Re: Spritpreise aus Website in Openhab integrieren
Ich habe mir erlaubt, das mal etwas umzuformatieren.
openHAB4.1.2 stable in einem Debian-Container (bookworm) (Proxmox 8.1.5, LXC), mit openHABian eingerichtet