HTTP binding - openHAB 3 version

I just switched to openHAB3 and relized that I need to update my http binding which I used for my “Feinstaub” sensor.

I posted my solution 2 years ago here: [SOLVED] Air pollution data from luftdaten.info - #18 by NCO

Now i get it running with the new binding. This thread helped me to make it and also the documentation. But examples are in my opinion the biggest help. Because I am a fan of the textural definition, here my working example for the popular “Feinstaubsensor” project (https://luftdaten.info/)

The http request http://feinstaubsensor-14255834/data.json is answering with a JSON string. So I need some simple JSONPATH transformation and one java script transformation. Data is polled every 10 seconds.

The Thing definition:

Thing http:url:feinstaub "Feinstaub" [ baseURL="http://feinstaubsensor-14255834/data.json", refresh=10] {        
   Channels:            
      Type number : SDS_PM10 [ stateTransformation="JSONPATH:$.sensordatavalues[0].value" ]
      Type number : SDS_PM25 [ stateTransformation="JSONPATH:$.sensordatavalues[1].value" ]
      Type number : Temperatur [ stateTransformation="JSONPATH:$.sensordatavalues[2].value" ]
      Type number : Pressure [ stateTransformation="JS:airpressure.js" ]
      Type number : Humidity [ stateTransformation="JSONPATH:$.sensordatavalues[4].value" ]
}

I have a BME2080 sensor connected. The Humidity must be diveded by 100 to show hPa. I am doing this with a java transformation file airpressure.js:

(function(x) {
    var json = JSON.parse(x);
    return json.sensordatavalues[3].value/100;
})(input)

And the Items:

/* **************************
 * Feinstaub sensor data
 * ************************** */
Number N_FS_SDS_PM10 "Partikelgröße 10µm [%.2f µg/m³]" { channel="http:url:feinstaub:SDS_PM10" }
Number N_FS_SDS_PM25 "Partikelgröße 2.5µm [%.2f µg/m³]" { channel="http:url:feinstaub:SDS_PM25" }
Number N_FS_Temperatur "Temperatur [%.2f °C]" <temperature> { channel="http:url:feinstaub:Temperatur" }
Number N_FS_Pressure "Luftdruck [%.2f hPa]" <pressure> { channel="http:url:feinstaub:Pressure" }
Number N_FS_Humidity "Luftfeuchte [%.2f %%]" <water> { channel="http:url:feinstaub:Humidity" }

I hope its helpful example of the binding for others and I hope the solution also OK for the insiders…

3 Likes