[SOLVED] Get Chart item as png or jpg

Hi Everyone!

I have a chart which I want to export to jpg or png.
Like this I have a link to a specific chart: http://localhost:8080/chart?groups=gAwairCoAndChemicals&period=D

But this returns an html page with an html image in it. Is it somehow possible to convert this to png?


I used this solution some time ago.

1 Like

This post was flagged by the community and is temporarily hidden.

Thanks this helped me to the right way - this is what I wanted to do. However for me cutycapt seems better to do html “screenshots”. wkhtmltoimage provided very small and unreadable output.
It seems to work now, but I have a problem. I’m trying to execute this with the exec binding, but it fails somewhere (says there is no xvfb-run).
Running as user openhab from ssh, everything works as expected. I have added this command to the sudoers to be executeable without password. But I don’t know whats wrong now…
This is what I get if I want to run from exec binding:

/usr/bin/xvfb-run: 183: /usr/bin/xvfb-run: 0,: not found

To be more precise: running the command from openhab user works everytime, but it seems if I run without sudo it won’t update the output picture, but not throwing any error. Running with sudo works. Doing the same (with sudo) from exec binding, creates the error above…

Confirm when trying to run the command from ssh you are logged in as user openhab, on a openhabian installtion that would rather be openhabian and the user openhab would run openhab only.

I’m sure that I’m running as openhab (sudo -su openhab).

So if someone wants to have Chart items in png, you can do this.

Create a file and insert this:

sudo xvfb-run -a --server-args="-screen 0, 1920x1080x24" cutycapt --min-width=400 --min-height=200 --smooth --url="http://localhost:8080/chart?groups=gYourGroup&period=D" --out=/etc/openhab2/html/filename.png

Where you fill in the groupName and the filename and path you want.

You also have to install xvfb and cutycapt for this to work.
However sending picture snapshots of charts are easier with Grafana (and also prettier), but it will barely work with OH on the same Raspberry Pi.
This will work, however this also needs time to provide output. For me it takes 20-30 secs to write the current png.