Display local images

Hi guys,

I’ve got a network monitoring software which exports an image. This image should be displayed on a sitemap.
Picture is updating every 10 sec on a local Windows running PC which have OpenHub server also.

So the question is how can I do that?
As I understood you can display an image only from a web server.

Image [item=<itemname>] [icon="<iconname>"] url="<url of image>" [label="<labelname>"] [refresh=xxxx]

Thank you very much in advance!
Sasha

I have not tested it, but you could try to let the url point to the local file, e.g.

url="file://<path><filename>"

BR
Kjetil

Hi Kjetil,

Thanks for reply but it doesn’t work. Tried it on a remote and local address. Any other ideas?

I’ve aslo found a software which can automatically copy files to a different folder so I’m copying the image to the habmin directory and I can access it by a simle url, but another problem is that openHAB probably locks this file so I cannot rewrite it after…

I’m using

Image url="/cameras/plac.png" label="Plac" refresh="4000"

plac.png is in $OPENHAB_ROOT/webapps/cameras/ folder - monitoring software uploads it.

Max,

No, it doesn’t work… But I can see the file with browser.

Do you have an item for it?

1 Like

No I have no item. Image is only defined in sitemap.

It works for me:

Frame label=“Bartek room” {
Image url=“http://localhost:8080/cameras/room.png” height=10 refresh=1000
}

room.png is stored on $OPENHAB_ROOT/webapps/cameras/room.png

Showing the local image is not an issue. But when you want to update file stays locked and you cannot rewrite it.
Any solutions for that?

Thanks!
Sasha

Bumping this thread as I’m also wondering how an image can be updated while OH is running. Seems like once it is loaded, regardless of whether it is actively being shown anywhere or not, you can’t update it without exiting out of OH.

I would like to refresh topic regarding openHAB2. In “old” openHAB there were $OPENHAB_ROOT/webapps directory and it works. In openHAB2 I cannot find such place. Do anyone know how to display local images in openHAB2?

I’ve tried a little bit and could get it working the following way:

  • place the image file in the conf/icons/classic folder of your openhab2 installation (see Iconset (where is in OH2?)

  • created the following sitemap entry:
    Image label="test" icon="camera" url="http://serverip:8080/icon/filename.png" refresh=60000'
    where you just have to change serverip regarding the ip of your OH2 server and the correct filename.

as an alternative you could also use the WebView Item in you sitemap:

Webview url="http://serverip:8080/icon/filename.png"

but there you go without the automatic refresh.

Hope that helps :slight_smile:

Yes that’s working. Thanks!

But it turns out that on the url address file extension is ignored and assumed to be only png is shown. I have tried even situation when I have to files: image.png and image.jpg and there is no difference in following lines:
Image url="http://localhost:8080/icon/image.png" refresh=60000'
Image url="http://localhost:8080/icon/image.jpg" refresh=60000'
Image url="http://localhost:8080/icon/image" refresh=60000'

in all cases image.png appears. Webview way won’t work neither for png nor for jpg:
Webview url="http://localhost:8080/icon/image.png"

Is there any other way to show .jpg files?

Yes, you’re right. I’ve tested it only with png, and jpg also doesn’t work here with me either. I think only png is supported as they say in the icons thread :unamused:

I ran into this file locking issue again after upgrading my openhab runtime to 1.8.3. @scooter_seh gets the credit for the ‘fix’ for this, but the issue is that the Jetty webserver has a default setting that locks files.

In the OPENHAB_ROOT/etc/webdefault.xml file, change the ‘useFileMappedBuffer’ setting to ‘false’ and restart the runtime.

Jetty’s website has more detail on this.

1 Like

Hello!

Do you know if there is a similar fix for OpenHAB2? Right now I’m using separate installation of Apache Web Server to accomplish this.

Best regards,
Davor

There is now an alternate approach possible in openHAB 2 (not 1.x) where your Image and Video sitemap widgets can have an optional item= that references a String item. If the item’s state is a URL, the widget will proxy to that URL instead of the mandatory-supplied URL in the url= parameter. Whenever the item referenced by item= changes state, the Class UI, Basic UI and mobile apps will show the image or video referenced by the item.

1 Like

Hello!

These are a really good news. Last thing I’ve heard was a discussion about safety issues with that approach. Didn’t know it was implemented in the meantime. Thank you for this information.

Best regards,
Davor

There are no new security issues with support for item= because it is a choice you make to include item= in your sitemap. Check out the demo configuration for an example. You could even implement a rotating display of security cameras by having a rule periodically update the item to point to the next camera in the list every X seconds. Of if a binding updates an item to be some dynamic URL only known via the binding, etc.

Hello!

I was referring to some old discussion between Kai and Chris, and Kai said using String item as Image URL was a security hole, so he rejected the idea. I haven’t looked at this solution for a pretty long time, since I’ve used Apache. Anyway, this is definitely much easier way to show dynamic images (i.e. Plex cover image). My home network is not open from the outside, so I don’t have that kind of concerns, it was just the reason it was not implemented before (the thread was from 2013 if I recall correctly). Once again, thank you for your help.

Best regards,
Davor

In openhab 1.8.3 you can place you .png or .jpg in the webapps/media dir. Make a new media dir inside there.

Put the folowing line in your sitemap

Frame label=“label” Image url=“http://serverip:8080/media/image.png” height=10 refresh=1000

serverip can be or localhost or your ip number. Both work.

I also tested jpg and png. Both did work. Also with android, and myopenhab it works.

1 Like