push data to restAPI

I’m wondering if it would be possible to push the data from my server directly to the oh2 restAPI. In the configuration of the luftdaten server I can enter


The server will send a similar json formatted datatype of this format

  "esp8266id": "534958",
  "software_version": "NRZ-2017-099",

I get the following error mesage on my luftdaten server

## Sending to custom api: 
Start connecting to hab
Requesting URL: /rest/items/luftdaten
{"esp8266id": "659987", "software_version": "NRZ-2018-123B", "sensordatavalues":[{"value_type":"SDS_P1","value":"4.00"},{"value_type":"SDS_P2","value":"0.50"},{"value_type":"BME280_temperature","value":"28.72"},{"value_type":"BME280_humidity","value":"27.08"},{"value_type":"BME280_pressure","value":"100411.41"},{"value_type":"samples","value":"1823813"},{"value_type":"min_micro","value":"78"},{"value_type":"max_micro","value":"21029"},{"value_type":"signal","value":"-61"}]}
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
Content-Length: 227
Connection: close
Server: Jetty(9.3.21.v20170918)

{"error":{"message":"HTTP 415 Unsupported Media Type","http-code":415,"exception":{"class":"","message":"HTTP 415 Unsupported Media Type","localized-message":"HTTP 415 Unsupported Media Type"}}}
closing connection

The error is correct, because only plain text is allowed.

How can I post json formated data into the rest api?

I think you could work around this by setting up a reverse proxy in front of openhab (see here) but add a location block for this particular item:

location /rest/items/luftdaten {
		proxy_pass                            http://localhost:8080/rest/items/luftdaten;
		proxy_buffering                       off;
		proxy_set_header Host                 $http_host;
		proxy_set_header X-Real-IP            $remote_addr;
		proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto    $scheme;
		# Change Content-type passed to openhab
		proxy_set_header Content-type text/plain;

Kind of a dirty hack, but I don’t believe you can change anything inside openhab without changing the source code, and I guess it’s the same for the luftdaten server.

@peaeater Did you get this running that the ESP sends the current data automatically to openHAB?
I want to try the same.
If not, I have to read out the ESP webinterface directly.


I just changed one line for testing purpose


thats all. But I didn’t find the time to integrate it properly to github. There youl will have to change a few files more, to get also the homepage of the esp correctly set up.

My items are:

Group gGewetter          "Wetterstation" 
// folgender String wird von der Wetterstation gepushed
String  gewetter "[%s]" 

// String Aufau: 
//  {"esp8266id": "659987",
//   "software_version": "NRZ-2018-123B",
//   "sensordatavalues":[
//         {"value_type":"SDS_P1","value":"2.50"},
//         {"value_type":"SDS_P2","value":"2.30"},
//         {"value_type":"BME280_temperature","value":"23.90"},
//         {"value_type":"BME280_humidity","value":"29.09"},
//         {"value_type":"BME280_pressure","value":"99562.84"},
//         {"value_type":"samples","value":"908823"},
//         {"value_type":"min_micro","value":"155"},
//         {"value_type":"max_micro","value":"22378"},
//         {"value_type":"signal","value":"-27"}
//   ]
//  }

Number SDS_P1                "PM10 [%.1f µg/m³]"                  <pm10>        (Pm10,        gGewetter)
Number SDS_P2                "PM25 [%.1f µg/m³]"                  <pm25>        (Pm25,        gGewetter)
Number BME280_temperature    "Außentemperatur Balkon[%.1f °C]"    <temperature> (Temperature, gGewetter)
Number BME280_humidity       "Luftfeuchtigkeit Balkon [%.1f %%]"  <humidity>    (Humidity,    gGewetter)
Number BME280_pressure       "Luftdruck [%.1f hPa]"               <pressure>    (Pressure,    gGewetter)

and the rules file looks like

rule "Process gewetter"
    Item gewetter changed
    logInfo("Process gewetter", "Update Received")
    if (gewetter !== null && gewetter.state.toString.contains("sensordatavalues")) {
//      logInfo("Process gewetter", gewetter.state.toString)
      var String items = "SDS_P1,SDS_P2,BME280_temperature,BME280_humidity,BME280_pressure"
      var item_buffer = items.split(",")
      var counter = -1
      while ((counter=counter+1) < 5) {
        var value = transform("JSONPATH", "$.sensordatavalues["+counter+"].value", gewetter.state.toString)
        var item_to = item_buffer.get(counter)
        logInfo("Process gewetter", item_to + "="+ value)

I had quite the same problem: I also built that sensor (some topic here inspired me), and wanted to have these values in openHAB.

In the end I didn’t get their software to run on my ESP8266, so I ended up installing Tasmota, which can directly push these values to my MQTT server - voila!

Now I have the problem the other way around - how to push the data to :smiley:

I finally managed it - all set up: Push sensor data to aka using Tasmota and openHAB

thank you for the fix!