Generate Chart for Switch item

Hello,

I would like to generate a chart for a Switch item. As the value of Switch is ON/OFF I was thinking on putting a map there, but do not know the syntax or whether it is even possible.

A workaround would be to create a Number item and then a rule that would update the Number based on ON/OFF command received. But isn’t there any easier way to do that?

Thank you
Peter

Have you tried charting it without mapping ?
Technically, ON/OFF is 1/0. You can chart a switch in habmin. I haven’t tried in GUI, though.

Hi Markus,

I get error:

2016-07-01 09:03:00.208 [WARN ] [e.jetty.servlet.ServletHandler] - /openhab.app
java.lang.NullPointerException: null
    at org.openhab.ui.webapp.internal.render.ImageRenderer.renderWidget(ImageRenderer.java:54) ~[na:na]
    at org.openhab.ui.webapp.internal.render.PageRenderer.renderWidget(PageRenderer.java:158) ~[na:na]
    at org.openhab.ui.webapp.internal.render.PageRenderer.processChildren(PageRenderer.java:121) ~[na:na]
    at org.openhab.ui.webapp.internal.render.PageRenderer.processChildren(PageRenderer.java:138) ~[na:na]
    at org.openhab.ui.webapp.internal.render.PageRenderer.processPage(PageRenderer.java:86) ~[na:na]
    at org.openhab.ui.webapp.internal.servlet.WebAppServlet.service(WebAppServlet.java:127) ~[na:na]
    at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61) ~[na:na]
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:128) ~[na:na]
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60) ~[na:na]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) ~[javax.servlet_3.0.0.v201112011016.jar:na]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598) ~[org.eclipse.jetty.servlet_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486) [org.eclipse.jetty.servlet_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413) [org.eclipse.jetty.servlet_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.Server.handle(Server.java:350) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:944) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630) [org.eclipse.jetty.http_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230) [org.eclipse.jetty.http_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606) [org.eclipse.jetty.io_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46) [org.eclipse.jetty.io_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603) [org.eclipse.jetty.util_8.1.3.v20120522.jar:8.1.3.v20120522]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538) [org.eclipse.jetty.util_8.1.3.v20120522.jar:8.1.3.v20120522]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_101]

It looks to me that OpenHAB is not able to handle ON/OFF and converts it to NULL.

Peter

What persistence are you using?

NullPointerException, unfortunately is the default exception OH throws when it runs into any sort of problem. That error is more likely to indicate that you have a typo on your sitemap for the chart, you do not have your persistence set up correctly (e.g. if using rrd4j are you saving state at least every minute?) or something like that.

Indeed, a Switch is saved in the database by persistence using ON = 1 and OFF = 0 so you can chart a switch without a mapping.

Hello Rich, Markus,

I found the problem: sitemaps setup was incorrect.

Incorrect sitemaps:

Switch item=light_1 label="Light 1" icon="light"
{
    Frame
    {
        Chart item=light_1 period=D refresh=30000
    }
}

Correct sitemaps:

Text item=light_1 label="Light 1 Chart"
{
    Frame
    {
        Chart item=light_1 period=D refresh=30000
    }
}

I tried to nest the chart into Switch and obviously this does not work. I wanted to save one line in the UI, but it looks that the only way is to have one line for the switch and second for the chart.

Thank you for the help
Peter