How to use wget.exe for Grafana dashboard screenshot

Recently I made a OpenHAB ( 2.2.0-1) OS platform change from MS Windows to openhabian.

It appears to be not that straight forward as I expected, even most of the different rules, items etc. could be copied as is. But my use of the wget command really cause me some headache! Ironically the use of wget was a big challenge under MS Windows too, but my perception was, that it was exactly because of MS Windows as OS.

I’m using wget to make a Grafana dashboard screenshot every 24 hours, for use in a “Energy” sitemap panel.

I managed to do that with the following code when running under MS Windows:

Energy. rules

var cmdelkwh = "c:\\Program Files (x86)\\GnuWin32\\bin\\wget.exe --output-document c:\\openHAB2\\conf\\icons\\classic\\electricity.png"

rule "Generate png snapshot electricity kwh"
        Time cron "0 10 00 * * ?"

To run this under openhabian, I have tried with different changes, but my expectation is that it should look something like this:

var cmdelkwh = "wget.exe --output-document electricity.png"

rule "Generate png snapshot electricity kwh"
        Time cron "0 10 00 * * ?"

However, it doesn’t work.

When running the rule a file with the right name is formed, but it’s not formatted correct, it contains some HTML code.

Any idea what I’m doing wrong? I’m not married to wget, so if there is a more correct way to achieve the function, I am open.

BR Ole

There are no “exe” files on Linux or any other OS besides Windows. It’s just wget, not wget.exe.

So I’m not entirely certain how you are getting anything at all.

What do you get when you execute that from the command line?

What do you get when you execute it as the openhab user?

sudo -u openhab wget --output...

However, you can easily show a graph of the last 7 days at the time you bring up your sitemap using:

Image label="whatever" refresh=60000 url=""

Thanks’ for your reply!

Sorry, my bad, a “copy and paste” mistake. I’m using it without .exe on openhabian.

var cmdelkwh = "wget --output-document electricity.png"

rule "Generate png snapshot electricity kwh"
        Time cron "0 10 00 * * ?"

Executing it from the command line (PuTTY) does the same, but the file is located in /home/openhabian/electricity.png instead of /srv/openhab2-userdata/electricity.png - still containing HTML when opening it in an editor.

[23:01:36] openhabian@openHABianPi:~$ --2018-04-03 23:01:36--
Tilslutter forbundet.
HTTP forespørgsel sendt, afventer svar... 302 Found
Sted: /login [omdirigeret]
--2018-04-03 23:01:36--
Genbruger eksisterende forbindelse til
HTTP forespørgsel sendt, afventer svar... 200 OK
Længde: uspecificeret [text/html]
Gemmer til: 'electricity.png'

electricity.png                        [ <=>                                                             ]   9,97K  --.-KB/s    in 0s

2018-04-03 23:01:36 (38,0 MB/s) - 'electricity.png' gemt [10214]

Hmm, “Sted: /login [omdirigeret]” Means redirected, wonder why that is.

Executing it from the command line (PuTTY) using the openhab user seems to act different, and no file is formed

[23:06:16] openhabian@openHABianPi:~$ sudo -u openhab wget --output-document electricity.png
[22] 11043
[23] 11044
[24] 11045
[25] 11046
[26] 11047
[27] 11048
[23]   Færdig                 from=now-7d
[24]   Færdig                 to=now
[25]   Færdig                 panelId=5
[26]   Færdig                 width=1000
[23:06:27] openhabian@openHABianPi:~$

I have tried to show the graph directly, but I cannot make it Work. When pasting the URL in a browser, there is a 5-6 seconds delay before Grafana response. That’s why I’m using executeCommandLine(cmdelkwh,10000) with a 10 second delay.

Since the result is kind of the same from the command line, where I assume this delay is not performed, I Wonder if that could be my problem in openHAB as well?


If it doesn’t work from the command line it will never work when run form oh. You need to figure out how to make it work there and then you can start working work oh.

I’m fairly sure wget does not do what you are expecting of it. It’s not a browser that renders things to png? It simply “gets” the location you give it and saves the response.

I definitely agree, hopefully I will improve my skills in using the command line.

Can you confirm that it should be possible to get this delay by adding “,10000” in the end when using the command line, like:

sudo wget --output-document electricity.png,10000



Have a look here:

So I should not expect wget to work about the same as when running in MS Windows?

I will definitely try this! :slight_smile:


I may be interpreting the problem incorrectly. If you are trying to save a png file it will work correctly. It won’t however render “” as a png. It will save the html source in to the file

I’ve used grafana only a small amount in the past and I was not aware of it producing any png output

I’m pretty sure it will work in this context. The URL he is using is to the static prerendered graph generated by Grafana. It just returns a PNG (when everything works correctly). And OP had it working with wget on Windows prior to moving his OH to Linux.

@OB75, what is the contents of the HTML that you are receiving. It might indicate an error on the Grafana side.

@belikh I will take a closer look on your suggestion if wget will not do the job

@rlkoshak the HTML content is as follows:

<!DOCTYPE html>
<html lang="en">

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width">
  <meta name="theme-color" content="#000">


  <base href="/" />

  <link rel="stylesheet" href="public/build/grafana.dark.css?v5.0.3">

  <link rel="icon" type="image/png" href="public/img/fav32.png">
  <link rel="mask-icon" href="public/img/grafana_mask_icon.svg" color="#F05A28">


<body ng-cloak class="theme-dark">
  <grafana-app class="grafana-app">

    <sidemenu class="sidemenu"></sidemenu>

    <div class="page-alert-list">
      <div ng-repeat='alert in dashAlerts.list' class="alert-{{alert.severity}} alert">
        <div class="alert-icon">
          <i class="{{alert.icon}}"></i>
        <div class="alert-body">
          <div class="alert-title">{{alert.title}}</div>
          <div class="alert-text" ng-bind='alert.text'></div>
        <button type="button" class="alert-close" ng-click="dashAlerts.clear(alert)">
          <i class="fa fa fa-remove"></i>

    <div class="main-view">
      <div class="scroll-canvas" grafana-scrollbar>
        <div ng-view></div>

        <footer class="footer">
          <div class="text-center">
                <a href="" target="_blank">
                  <i class="fa fa-file-code-o"></i>
                <a href="" target="_blank">
                  <i class="fa fa-support"></i>
                  Support Plans
                <a href="" target="_blank">
                  <i class="fa fa-comments-o"></i>
                <a href="" target="_blank">Grafana</a>
                <span>v5.0.3 (commit: 91162f3)</span>

    window.grafanaBootData = {
      user: {"isSignedIn":false,"id":0,"login":"","email":"","name":"","lightTheme":false,"orgCount":0,"orgId":0,"orgName":"","orgRole":"","isGrafanaAdmin":false,"gravatarUrl":"","timezone":"browser","locale":"en-US","helpFlags1":0},
      settings: {"alertingEnabled":true,"allowOrgCreate":false,"appSubUrl":"","authProxyEnabled":false,"buildInfo":{"buildstamp":1521216676,"commit":"91162f3","env":"production","hasUpdate":false,"latestVersion":"5.0.0","version":"5.0.3"},"datasources":{"-- Grafana --":{"meta":{"type":"datasource","name":"-- Grafana --","id":"grafana","info":{"author":{"name":"","url":""},"description":"","links":null,"logos":{"small":"public/img/icn-datasource.svg","large":"public/img/icn-datasource.svg"},"screenshots":null,"version":"","updated":""},"dependencies":{"grafanaVersion":"*","plugins":[]},"includes":null,"module":"app/plugins/datasource/grafana/module","baseUrl":"public/app/plugins/datasource/grafana","annotations":true,"metrics":true,"alerting":false,"builtIn":true,"routes":null},"name":"-- Grafana --","type":"datasource"},"-- Mixed --":{"meta":{"type":"datasource","name":"-- Mixed --","id":"mixed","info":{"author":{"name":"","url":""},"description":"","links":null,"logos":{"small":"public/img/icn-datasource.svg","large":"public/img/icn-datasource.svg"},"screenshots":null,"version":"","updated":""},"dependencies":{"grafanaVersion":"*","plugins":[]},"includes":null,"module":"app/plugins/datasource/mixed/module","baseUrl":"public/app/plugins/datasource/mixed","annotations":false,"metrics":true,"alerting":false,"queryOptions":{"minInterval":true},"builtIn":true,"mixed":true,"routes":null},"name":"-- Mixed --","type":"datasource"}},"defaultDatasource":"-- Grafana --","disableLoginForm":false,"disableUserSignUp":true,"externalUserMngInfo":"","externalUserMngLinkName":"","externalUserMngLinkUrl":"","googleAnalyticsId":"","ldapEnabled":false,"loginHint":"email or username","oauth":{},"panels":{"alertlist":{"baseUrl":"public/app/plugins/panel/alertlist","hideFromList":false,"id":"alertlist","info":{"author":{"name":"Grafana Project","url":""},"description":"Shows list of alerts and their current status","links":null,"logos":{"small":"public/app/plugins/panel/alertlist/img/icn-singlestat-panel.svg","large":"public/app/plugins/panel/alertlist/img/icn-singlestat-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/alertlist/module","name":"Alert List","sort":6},"dashlist":{"baseUrl":"public/app/plugins/panel/dashlist","hideFromList":false,"id":"dashlist","info":{"author":{"name":"Grafana Project","url":""},"description":"List of dynamic links to other dashboards","links":null,"logos":{"small":"public/app/plugins/panel/dashlist/img/icn-dashlist-panel.svg","large":"public/app/plugins/panel/dashlist/img/icn-dashlist-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/dashlist/module","name":"Dashboard list","sort":7},"gettingstarted":{"baseUrl":"public/app/plugins/panel/gettingstarted","hideFromList":true,"id":"gettingstarted","info":{"author":{"name":"Grafana Project","url":""},"description":"","links":null,"logos":{"small":"public/app/plugins/panel/gettingstarted/img/icn-dashlist-panel.svg","large":"public/app/plugins/panel/gettingstarted/img/icn-dashlist-panel.svg"},"screenshots":null,"version":"","updated":""},"module":"app/plugins/panel/gettingstarted/module","name":"Getting Started","sort":100},"graph":{"baseUrl":"public/app/plugins/panel/graph","hideFromList":false,"id":"graph","info":{"author":{"name":"Grafana Project","url":""},"description":"Graph Panel for Grafana","links":null,"logos":{"small":"public/app/plugins/panel/graph/img/icn-graph-panel.svg","large":"public/app/plugins/panel/graph/img/icn-graph-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/graph/module","name":"Graph","sort":1},"heatmap":{"baseUrl":"public/app/plugins/panel/heatmap","hideFromList":false,"id":"heatmap","info":{"author":{"name":"Grafana Project","url":""},"description":"Heatmap Panel for Grafana","links":[{"name":"Brendan Gregg - Heatmaps","url":""},{"name":"Brendan Gregg - Latency Heatmaps","url":""}],"logos":{"small":"public/app/plugins/panel/heatmap/img/icn-heatmap-panel.svg","large":"public/app/plugins/panel/heatmap/img/icn-heatmap-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/heatmap/module","name":"Heatmap","sort":5},"pluginlist":{"baseUrl":"public/app/plugins/panel/pluginlist","hideFromList":false,"id":"pluginlist","info":{"author":{"name":"Grafana Project","url":""},"description":"Plugin List for Grafana","links":null,"logos":{"small":"public/app/plugins/panel/pluginlist/img/icn-dashlist-panel.svg","large":"public/app/plugins/panel/pluginlist/img/icn-dashlist-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/pluginlist/module","name":"Plugin list","sort":100},"singlestat":{"baseUrl":"public/app/plugins/panel/singlestat","hideFromList":false,"id":"singlestat","info":{"author":{"name":"Grafana Project","url":""},"description":"Singlestat Panel for Grafana","links":null,"logos":{"small":"public/app/plugins/panel/singlestat/img/icn-singlestat-panel.svg","large":"public/app/plugins/panel/singlestat/img/icn-singlestat-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/singlestat/module","name":"Singlestat","sort":2},"table":{"baseUrl":"public/app/plugins/panel/table","hideFromList":false,"id":"table","info":{"author":{"name":"Grafana Project","url":""},"description":"Table Panel for Grafana","links":null,"logos":{"small":"public/app/plugins/panel/table/img/icn-table-panel.svg","large":"public/app/plugins/panel/table/img/icn-table-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/table/module","name":"Table","sort":3},"text":{"baseUrl":"public/app/plugins/panel/text","hideFromList":false,"id":"text","info":{"author":{"name":"Grafana Project","url":""},"description":"","links":null,"logos":{"small":"public/app/plugins/panel/text/img/icn-text-panel.svg","large":"public/app/plugins/panel/text/img/icn-text-panel.svg"},"screenshots":null,"version":"5.0.0","updated":""},"module":"app/plugins/panel/text/module","name":"Text","sort":4}}},
      navTree: [{"id":"dashboards","text":"Dashboards","subTitle":"Manage dashboards \u0026 folders","icon":"gicon gicon-dashboard","url":"/","children":[{"id":"home","text":"Home","icon":"gicon gicon-home","url":"/","hideFromTabs":true},{"id":"divider","text":"Divider","divider":true,"hideFromTabs":true},{"id":"manage-dashboards","text":"Manage","icon":"gicon gicon-manage","url":"/dashboards"},{"id":"playlists","text":"Playlists","icon":"gicon gicon-playlists","url":"/playlists"},{"id":"snapshots","text":"Snapshots","icon":"gicon gicon-snapshots","url":"/dashboard/snapshots"}]},{"id":"help","text":"Help","icon":"gicon gicon-question","url":"#","hideFromMenu":true,"children":[{"text":"Keyboard shortcuts","icon":"fa fa-fw fa-keyboard-o","url":"/shortcuts","target":"_self"},{"text":"Community site","icon":"fa fa-fw fa-comment","url":"","target":"_blank"},{"text":"Documentation","icon":"fa fa-fw fa-file","url":"","target":"_blank"}]}]

<script type="text/javascript" src="public/build/manifest.ce371925c160edcc5808.js"></script><script type="text/javascript" src="public/build/vendor.77a1eeb34c586857bf8c.js"></script><script type="text/javascript" src="public/build/app.a4b7f5a163ea89ff6420.js"></script></body>


I did play a little bit more with wget from the command line. When executing the command, I’m writing like this:

 wget --output-document electricity.png

The following Picture is what shows up when wget has been executed.

I have marked something with yellow, and I wonder why this is only partial the URL to the static Grafana image. It seems that everything after the first “&” in the URL is cut away. Probably nothing to wonder about, if I was a bit more skilled in wget / command line use and Linux.!? :frowning:

Pasting this part of the URL to a webbrowser definitely not lead to the image, but a Grafana server error page. I have checked the error page HTML code, but it does not match the HTML found in the formed PNG file.

Best regards Ole

Whatever URL wget is trying to pull down is not the png so the first thing is likely a problem with the URL.

Put the URL in quotes on the command line and see if that makes a difference.

Go back into Grafana and make sure you have the right URL to the statically generated PNG.

After a lot of trial and error, I’m a bit closer to make it work.

@rlkoshak I put the URL in quotes, and then the wget command was using the complete URL. However still no file appears.

I was looking a bit more on the behave when using wget from the command line, and the lines with something saying “trying to login” wondered me. Because pasting the URL in a browser did generate and show the static Grafana PNG without logging in.

But then i remembered some setting in the Grafana config file to allow anonymous access. Checking the file with Nano makes me a bit embarrassed. Anonymous access was set to “false”. :frowning:

Said in Danish, I owe “kvaje-bajer” - a game of beer or something like that.

The reason why it works from the browser is, that I was logged in to the Grafana web interface on another browser pane.

Changing the Grafana allow anonymous access to “true” make it to work. Sorry for my sloppy work.

A problem solved, another occurs - please let me know if it rightfully should be in a new thread?

To be able to show the PNG on my sitemap, it must be located in either openhab2-conf/html or openhab2-conf/icons. When using wget from the command line the following way, it is possible:

sudo -u openhab wget --output-document ../openhab2-conf/icons/electricity.png ""

Doing it from OH does not work

var cmdelkwh = "wget --output-document  ../openhab2-conf/icons/electricity.png"

rule "Generate png snapshot electricity kwh"
        Time cron "0 10 00 * * ?"

But doing like thes does:

var cmdelkwh = "wget --output-document  electricity.png"

rule "Generate png snapshot electricity kwh"
        Time cron "0 10 00 * * ?"

But the PNG is located in the openhab2-userdata folder.

There is a tmp folder in the openhab2-userdata folder, changing the path in the rule to use that folder is working too. But it seems impossible to go up one level, to access the openhab2-conf folder.

From the command line I have tried to make a link from within openhab2-userdata to the openhab2-conf/icons folder, doing like this:

sudo -u openhab ln -s ../openhab2-conf/icons icons

And using this folder (link) with wget from the command line is working too. But unfortunately, not from OH

It seems completely impossible to move away from the openhab2-userdata folder, to place the PNG elsewhere, when trying from OH

Any idea what I’m doing wrong / can try?

Thanks in advance.

Use the full path. /etc/openhab2/html

1 Like

Thanks Again @rlkoshak

When I enter the path as you describe it, it Works!

Obviously, I have a little difficulty understanding this file structure, compared to what I know from Windows hopefully I’m improving!


On the Linux command line you must 'escape the & symbol using backslash. So anywhere there is & in the url make it \&

1 Like

Here is my grafana.rules

It run fine

var cmdbrtemp = “/usr/bin/wget -O /etc/openhab2/html/grafana/bathroom-temp.png ‘’”

rule “Generate png snapshot Bathroom Temp Hum”
Time cron “0 0/5 * * * ?”
logInfo(“Crontab”, “Generate png snapshot Bathroom Temp Hum”)

create a folder grafana in openHAB-conf/html

In HabPanel use a image widget and define URL as this

I’m on a raspbian


1 Like