No data on sitemap

I’ve set everything up with an Arduino sending a value that increments by 1 every 2 seconds to openhab. Openhab sends the data received to mysql and from there, I want to create a graph of the data persisted, yet no data is persisted onto the chart. What may I have done wrong? The base graph is there yet, no values are showing up. I will be happy to provide more information if necessary

openhab.cfg:
persistence:default=mysql
chart:provider=default

items:
Group arduino
String Arduino “Arduino [%s]” (arduino) { serial=“COM3” }
Number Weight " [%s]" (arduino)

rules:
import org.openhab.core.library.types.*

rule "Arduino sends to Openhab"
when
Item Arduino received update
then
var Double newWeight = new Double(Arduino.state.toString)
Weight.postUpdate(newWeight)
end

persist:
Strategies{
default = everyChange
}
Items{
* : strategy = everyChange, restoreOnStartup
}

sitemap:
sitemap demo label=“REU”
{
Chart item=Weight period=h refresh=2000
}

Do you see any data received by openHAB? If openHAB is started manually through start.bat, any received value should be written to the terminal.
Be aware that the chart displayed in the UI will not refresh automatically (I think this will be fixed in 1.9.0? - not sure)
To see, if the rule is fired correctly, you can use logInfo():

rule "Arduino sends to Openhab"
when
    Item Arduino received update
then
    logInfo("My Rule","Value from Arduino: {}",Arduino.state)

This would result in a line, written to Terminal and logs/openhab.log

Yes, data is received by openhab.

If you are using rrd4j, you need to use an everyMinute strategy in your persist file to get charts.

The persistence i’m using is mysql and the chart is set to default. is there something that I have to change? I’d like to use mysql since I am not familiar with rrd4j.

I’ve only ever used rrd4j for charting.

is it possible to use mysql for persistence and rrd4j for charting?

As asked the answer is no but for what you mean the answer is yes.

If you are using rrd4j you are by definition using rrd4j for persistence so the answer is no you can use mysql for persistence and rrd4j only for charting. But you can use multiple persistence engines at the same time so the answer is yes, you can use mysql and rrd4j for persistence and chart with the data in rrd4j.

But I would question the value in that. If the only reason you are using MySQL is because you are familiar with it I would argue MySQL is probably the wrong choice.

There are three reasons why you want to use persistence:

  1. Restore your Items to their prior states on OH startup

  2. Historic data access in rules; e.g. getting previous values, calculations of values since a certain time, getting when the Item was last updated, etc.

  3. Analysis; e.g. charting, processing data with a third party tool, accurate data well into the past, etc.

Luckily you can have as many persistence engines set up as you want, you can specify which Items get saved to which engine, and an Item can be saved to multiple places at the same time.

So, IMHO the proper persistence to use for the three cases above are:

  1. MapDB: it only saves the most recent value but it supports all data types and because it only saves the last value it never grows (i.e. no maintenance down the road)

  2. rrd4j: it only works with numerical data and as the data gets old it “compresses” the database by replacing a series of data with their average. But the advantage is that it does this compression so that the DB never grows beyond a certain size (i.e. no maintenance down the road). For rrd4j charting you must use an everyMinute strategy to save values because of quirks on how rrd4j works.

  3. MySQL, InfluxDB, etc: they work with all data types and they save all values unchanged forever. They also provide standard interfaces and have lots of third party tools to work with the data. However, they will continue to grow forever so there will be needed maintenance down the line. They also have a more difficult time dealing with changing the type of an Item that has already been saved in the DB (e.g. changing a Switch to a Number because you realized you need more than two states).

The easiest way to specify which Items get saved to which persistence engine is to create a Group for each, config the persistence using the myGroupName* approach which saves all members of that group according to that strategy, and then you can control which Items get saved where through group membership. Personally I just save everything to MapDB with restoreOnStartup as I don’t want to have to deal with Undefined Items, ever.

One final note. OH charting is very very basic with almost no customization capabilities. They are also relatively unattractive and often do not let people present the data the way they want. As such I would recommend looking into using a third party charting tool (search the forum for “chart” and you will find some posts of people telling what they use) if you are serious about making charts part of your UI.

1 Like