This is my quick approach, that can handle closed stations:
But: The information provider will not support the prices via the detail.php anymore
Maybe the items can be transferred, in order to use the script.
(API-Keys can be banned, if they’re using the old interface which leads to much more traffic)
The new Inferface looks like this (all stations (up to 10) in one request)
https://creativecommons.tankerkoenig.de/json/prices.php + the desired stations + APIKEY
{"ok":true,"license":"CC BY 4.0 - http:\/\/creativecommons.tankerkoenig.de","data":"MTS-K","prices":{"00000000-0000-0000-0000-000000000001":{"status":"open","e5":1.299,"e10":false,"diesel":1.059},"00000000-0000-0000-0000-000000000002":{"status":"open","e5":1.349,"e10":1.329,"diesel":1.119}}}
rule:
rule "E5 Update"
when
Item Gas_Prices_E5 received update or
Item Gas_Prices_E5 changed
then
var Lock lockE5 = new ReentrantLock()
var Map <String, Double> E5PricesMap = new HashMap <String, Double>() // Stationsnamen und Preise für den Kraftstoff
var ArrayList <StringItem> E5sortItems = new ArrayList <StringItem>()
var i = 0
lockE5.lock()
E5sortItems.add(0, Tankstelle1_E5_TXT)
E5sortItems.add(1, Tankstelle2_E5_TXT)
E5sortItems.add(2, Tankstelle3_E5_TXT)
if(Tankstelle1Closed.state==OFF){E5PricesMap.put("Shell", (Tankstelle1_E5.state as DecimalType).doubleValue())}
if(Tankstelle2Closed.state==OFF){E5PricesMap.put("Esso", (Tankstelle2_E5.state as DecimalType).doubleValue())}
if(Tankstelle3Closed.state==OFF){E5PricesMap.put("Star", (Tankstelle3_E5.state as DecimalType).doubleValue())}
if(Tankstelle1Closed.state==ON) {E5PricesMap.put("geschlossen1", (0).doubleValue())}
if(Tankstelle2Closed.state==ON) {E5PricesMap.put("geschlossen2", (0).doubleValue())}
if(Tankstelle3Closed.state==ON) {E5PricesMap.put("geschlossen3", (0).doubleValue())}
// Map nach Preisen sortieren und die Werte dann dem Anzeigearray zuweisen
for (PriceEntry : E5PricesMap.entrySet.sortBy[value]) {
if(PriceEntry.getValue()!=0){E5sortItems.get(i).postUpdate(String::format("%s - %.3f €", PriceEntry.getKey(), PriceEntry.getValue()))}
if(PriceEntry.getValue()==0){E5sortItems.get(i).postUpdate("geschlossen")}
i = i+1
}
lockE5.unlock()
postUpdate(E5_LastUpdate, new DateTimeType())
end
sitemap:
Text label="Spritpreise" icon="gas_station_64_2" {
Group item=Gas_Prices_E5 {
Text item=E5_LastUpdate valuecolor=[E5_LastUpdate>7200="red", E5_LastUpdate>3600="orange"] label="Letze Änderung [%1$tA, %1$tR]"
Text item=Price_E5_LOW
Text item=Price_E5_HIGH
Switch item=Gas_Prices_Period label="" mappings=[1="Tag", 2="Woche"]
Chart item=Gas_Prices_E5 period=D refresh=3600 visibility=[Gas_Prices_Period==1, Gas_Prices_Period=="Uninitialized"]
Chart item=Gas_Prices_E5 period=W refresh=3600 visibility=[Gas_Prices_Period==2]
Frame label="Geöffnete Tankstellen" {
Text item=Tankstelle1_E5_TXT label="[%s]" visibility=[Tankstelle1_E5_TXT!="geschlossen"]
Text item=Tankstelle2_E5_TXT label="[%s]" visibility=[Tankstelle2_E5_TXT!="geschlossen"]
Text item=Tankstelle3_E5_TXT label="[%s]" visibility=[Tankstelle3_E5_TXT!="geschlossen"]}}}