Chart on the panel with custom source data (no persistence)

I am running Openhabian 2.3 (installed from image on Raspberry). I am looking for a way to display a chart on a hab panel using the source data coming from web. I can get JSON data with time series from HTTP POST request, and I want to put it on a chart (like Grafana). I don’t want to use any persistence and store this data in DB. Is there a way to use some script or transform to prepare the data and feed it to some chart?

That would make you life much easier though.
Any particular reasons you don’t want to do that?
There are many tools available for presenting data in databases.
For raw data, you’ll have to make your own. It’ll be much easier to dump the data in a db and work from there

Ok, so how in your opinion I should do this? I get this kind of data on HTTP request:

{
    "tab":[
            [[2018,12,20,10,30],101],
		[[2018,12,20,10,40],102],
		[[2018,12,20,10,47],103],
		[[2018,12,20,11,01],104],
		[[2018,12,20,11,15],105]
	]
}

When I refresh in several minutes, it will look like:

{
    "tab":[
		[[2018,12,20,10,40],102],
		[[2018,12,20,10,47],103],
		[[2018,12,20,11,01],104],
		[[2018,12,20,11,15],105],
		[[2018,12,20,11,27],106]
	]
}

If I understand you correctly I should store it (somehow) in DB and use i.e. Grafana to display it, right? In that case, I would have to after each request remove everything from DB and add loaded data again. Alternatively I could check what new appeared since last refresh. That seemed to me more troublesome that just preparing the above data and “streaming” straight to the chart. Also, I don’t know how to incorporate persistence in such solution since I will be populating this data on my own, not just taking some item state.

That is an invalid JSON because of the 01 with a 0 in front of the 1
Can you control the output of your device and change that?

If you can then you can use the HTTP binding with a JSONPATH transformation $.tab[-1:][1]
which will give you the last value in the json.

Bind this to an item, persist it and you’re done

1 Like

No you can’t it comes from the web.
You need to contact the webadmin of your data source to let them know that the json they are generating is invalid

If only the actual value is needed, a rule could be used to separate to value to be persisted.

Ok, I have simplified the data and this was my error. Part of the original source data looks like this:

{
   "line":[
      "[[\"2018\",11,\"18\",\"00\",\"03\"],null,null,null,null,null,\"237\"]",
      "[[\"2018\",11,\"18\",\"00\",\"05\"],null,null,null,null,null,\"239\"]",
      "[[\"2018\",11,\"18\",\"00\",\"08\"],null,null,null,null,null,\"237\"]",
      "[[\"2018\",11,\"18\",\"00\",\"12\"],null,null,null,null,null,\"251\"]"
	  ]
}

So as you can see each element of “line” table has two inner tables all encoded in a string (I’m interested in both the date and number at the end). So I need some kind of pre processing in order to “extract” it and parse JSON. I was hoping to use some kind of OH2 transformation written in Java Script for this.

Another problem is that these values are not produced by the source in constant time breaks. Sometimes new value appears in 5 minutes, sometimes in 3 or 15 minutes. I would like to visualize all these values with their original time, not the time or OH2 item refresh.

You are most likely going to have to do this entirely externally to OH. OH can only generate charts from stuff it has persisted. Grafana can only generate charts from data that has been saved to a supported database. So you will have to write your own code to generate a chart from this data and you can show it on the sitemap or HABPanel using a webview.

Or you can have an external script or program receive this data and store it in a Grafana supported database and use Grafana to generate your charts.

There is no way you can save this data using OH persistence in a way that uses the original values.

Since you appear to have control over this source of data, is it possible to change from just polling for data to have it push the data out as the reading change? MQTT is a popular choice but there are other options as well.

Thanks @rlkoshak! This is a good answer and actually gives me some ideas. I’ll try to find out whether populating InfluxDB for example is fairly easy and I’ll set up custom script working under Cron Jobs that populates it. As I understand what you’re saying using this data should be easy then. Alternatively (if populating that DB is too complex for me) I’ll use such custom script to generate some PNG file with that chart and I’ll display it on the panel.