Chart in OH2 for ON/OFF Value

I have defined a the following chart

Chart  item=Mobile period=12h refresh=60000 service="mysql"

But in OH2 the chart doesn’t show the entries. The item entries based on the values ON/OFF.

I have defined another chart that based on temperature. That chart shows the items.

By the way: In OH1 the chart for the ON/OFF values shows the values. Is there a bug on OH2 or what’s going wrong?

I too have been struggling with charts since moving from OH1 to OH2 a few weeks ago. Some of my charts display, some so not. It seems that all of the ones that do not are monitoring ON/OFF events like motion sensors and such.

I am using rrd4j persistence, and the items I chart are stored everyMinute. This worked just fine in OH1.

Here is an example chart sitemap entry that does not work (ie displays a blank chart):

Chart item=basementLeakDetector period=D refresh=6000 service="rrd4j"

This is tracking a contact closure OPEN/CLOSE event.

Here is the item:

Contact  basementLeakDetector        "Leak Detector [MAP(]"   <faucet>          (gB, Sensors, Leak, gCharts)   {insteonplm="36.B4.0C:F00.00.0A#contact"}

But I have other items that are Switches, and none of them display. I have to conclude that either the items are not stored in the rrd4j database, or they are not charted properly. It used to be that ON/OFF items were stored as 0 and 1 items in the database (as rrd4j can only store numbers). The log seems to indicate that this is the case:

2016-11-23 14:42:04.072 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'basementLeakDetector' with state 'OPEN' in rrd4j database (again)
2016-11-23 14:42:04.072 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'basementLeakDetector' with state '1' in rrd4j database

And the database file timestamps are updated - so it would seem to be stored. Also my switch states are persisted over restarts. So it must be a charting issue.

Checking the charting, if I enter:


I get a blank chart, but if I enter:


Then I get a chart displayed as expected.

Anything that is a number will plot with the 'chart" http call, but it requires a call to rrdchart.png to chart switch items. “chart” will not plot them.

I have to conclude that the charting of ON/OFF items is broken in the latest build of OH2 (and has been for a while) - I upgraded to the nightly build last night. I can work around it, but it would be easier if it was fixed. I will enter this as a github issue.

It seems that both of you have at least manage to get some charts working.
In my case all charts are not working.
Is there a change is syntax in OH2?

It would be really great if some of you could post item, sitemap definition of a working chart.

Yeah, that’s what I also have seen. My ON/OFF chart in OH1 (which I used for presence detection) worked, the same chart in OH2 doesn’t work.

I have tried multiple things to get this going in OH2, but with no luck. As already mentioned, OH1 seems to convert ON/OFF to 0/1 (as rrd4j can only store numbers) and OH2 doesn’t (intentionally or because of a bug, I don’t know).

For now, I changed my presence detection script in OH2, so that the script doesn’t provide ON/OFF as result, but 0/1. And with this adaption, the chart is working.

It actually looks like the values are stored in the rrd4j database as 0/1, they are just not charted correctly. There must be a bug in the charting function.

As to the syntax, the only new thing I have seen is the service=“rrd4j” part of the sitemap chart statement. You need this if you have more than one persistence service defined.

All my charts which use Numbers or Dimmers work normally, just the ones that are ON/OFF or OPEN/CLOSE (ie binary) do not. I have a problem with the legend (key) which is now huge and covers almost half the chart - but that is another issue.

So, to get a chart to work, the item or group has to be persisted in the rrd4j service, it has to be persisted at least once per minute, and it has to be a continually variable item or group (ie all members of the group have to be the same type). Items/groups containing binary types (Switches or Contacts) will not chart.

My workaround is to use the following in the Sitemap:

Frame label="Leak Detector - Day" {
    Image url="http://ip:port/rrdchart.png?items=basementLeakDetector&period=D" refresh=60000
    //Chart item=basementLeakDetector period=D refresh=6000 service="rrd4j"

Notice I have replaced Chart with Image. This will chart, but looks slightly different to the usual OH chart style. The Item basementLeakDetector is a contact type. You can use the usual visibility trick with this to switch the chart period also. If you are charting a group (not an item), the keyword “items” gets replaced with “groups” in the above.

Here is a full example of charting a group with period switching:

Frame label="Motion Sensors" icon="line-incline" {
    Switch item=Motion_Chart_Period label="Chart Period" mappings=[0="Hour", 1="Day", 2="Week"]
    Image url="http://ip:port/rrdchart.png?groups=Motion_Chart&period=h" refresh=30000 visibility=[Motion_Chart_Period==0, Motion_Chart_Period==NULL]
    //Chart item=Motion_Chart period=h refresh=6000 service="rrd4j" visibility=[Motion_Chart_Period==0, Motion_Chart_Period==NULL]
    Image url="http://ip:port/rrdchart.png?groups=Motion_Chart&period=D" refresh=30000 visibility=[Motion_Chart_Period==1]
    //Chart item=Motion_Chart period=D refresh=30000 service="rrd4j" visibility=[Motion_Chart_Period==1]
    Image url="http://ip:port/rrdchart.png?groups=Motion_Chart&period=W" refresh=30000 visibility=[Motion_Chart_Period==2]
    //Chart item=Motion_Chart period=W refresh=30000 service="rrd4j" visibility=[Motion_Chart_Period==2]

This is a working sitemap entry for a group called Battery, which contains Numbers (% battery charge):

Chart item=Battery period=W refresh=30000 service="rrd4j"

This is what it looks like (notice the problem with the legend):

Now if I can just get icons to change state…

1 Like

Thanks for the documentation

It seems that in the DefaultChartProvider, only the variable of decimal type are charted. This does not allow for OnOff; Closed/Open, Dimmer … to be graphed.
A nice improvement would be to implement a type converter such as the one described in
I don’t know where to ask for this improvement/issue as I haven’t found the github dedicated to that topic. But anyway, if anyone from the development team is connected …please upgrade

Happy new year

I have an outstanding pull request that will fix this by bringing the code up to openHAB 1.8.3 level.

1 Like

I use OH2 and I also struggle with this problem.

Being a beginner, can somebody just tell me which IP:port I shall use?

Or is there already another solution in the meantime than
Image url="http://ip:port/rrdchart.png?..


Workaround that I use:
Make the mqtt1 binding publish all events (the mqtt 2 binding does not have that funcionality yet, so you have to use the old one).
Create (shadow) Number items for the ON/OFF items and have them updated by the ON/OFF items (subscribe to the mqtt topic the events are published on) and create a transformation from ON/OFF to 0/1.
You can find my openhab settings in //