Persistance type for Image item?

Hi All,

I couldnt find in the documentation which is used to persist image items, is there one?


Probably no because why would you want to do THAT?
Sound like an XY problem. Persist a String type item with the filename if you really need that.

Because when used as visitor history and you reboot the system, it saves bring up X’s in your UI .

Good answer.
I’ve got a last-six-snapshot arrangement going, but storing separate photo files in folders which survive a reboot of course. So I’ve never thought of persistence.
This is something MySQL could do isn’t it? If OH persistence extension supported it, which I doubt. Have you tried?

I guess you only want to store the last value of each of a set of Items, where Mapdb would be best suited otherwise.
If you got MySQL working, you’d probably need some external scripts to purge old images and stop it growing. In which case, you might as well do the whole thing with external scripts … or simply save images to files.

Hi rossko57, how do you save the images to files with the snapshot setup? Storage isnt a concern, I’ve got 8TB on hand.


Well my exact scripts probably wouldn’t help as it runs on a windows host. But I’ll summarise.

I actually take snapshots from various CCTV cameras, in response to e.g. gate opening or motion detect. The CCTV server allows capture by a simple HTTP request like http://my-ip/camera09 and responds with a jpeg.

So a rule gets triggered, and execute command line calls wget to fetch the image to a temporary file.
Next, run a little batch script that deletes camera09-6.jpg, then renames camera09-5.jpg to camera09-6.jpg etc. etc. (Obviously his step needs to handle missing files for the first few runs.)
Next I use Imagemagick via command line to resize and caption the snapshot with a timestamp and output to camera09-1.jpg.
Finally delete the temporary input file.

In reality that’s all in a lambda function that the rules can call by supplying the target name e.g. “camera09”.

Ending with a handful of files 1 - 6 in openHAB conf/html folder.
Displayed in a sitemap with Image widget pointing to image URLs.

The triggering rules manage not taking a flurry of snapshots from any one camera in a short time.
The lambda has a reentrant lock just because I’m not sure what might go wrong with multiple works in progress.

It’s all put together and adapted step by step from bits and pieces on the web and this forum, no special skill on my part.


I do think this a valid use case for persisting images, and there will I’m sure be other good reasons for at least a restore-on-startup capability for images.
I’d suggest you create an enhancement request for Mapdb at least.

It may never happen in the current persistence, which is essentially still version 1.x, but that could get it considered for OH3.

1 Like

Thanks rossko, I will.

For now, i think ill put some code, if item type = null, then display a static image.


haha! eww!