I’m using openHAB version 3.3.0 and want to upload a image to a item of type ‘image’ using python and the REST API. I searched the forum, but couldn’t find the solution.
What I learned, is that the image has to be base64 ecnoded, I did that. And I tried via command and state to transfer the image.
Often there will be additional information in openhab.log.
According to the REST API Docs (in MainUI go to Developer Tools → API Explorer) the content-type should be text/plain. That’s why you get the 415 error code when you try to use image/jpeg.
Beyond that . It’s somewhat unusual of a use case to push an image to an Item through OH’s REST API. Usually if you have an image, instead of using an Item you’d drop that file in $OH_CONF/html and access the image in your widgets using /static/<name of image>.
The image is already in $OH_CONF/html and I link to it via my local ip - but I also want to access the image via home.myopenhab.org so from outside of my network! Therefore I thought this is the right way to push the image to an item and the items should be available also from remote.
Am I off course here?
PS_ I did this to the logs, log:set INFO org.openhab.core.io.rest but I do not see any useful logs. Not sure if that is the right module either.
Yes. Because you’ll be accessing the image through openHAB itself, myopenhab.org can serve it. It’s only if that image were served by some other service on the LAN that you’d run into problems. As long as the image is in $OH_CONF/html, you can get to it through myopenhab.org.
To use a relative path that will work both locally and through myopenhab.org, make sure to use /static/<nameoffile>. Nothing more. No “http://” or anything like that. The browser will fill in that part for you.
Weird, using the short version (static/mypicture.png) isn’t working for me, not even in the LAN. I tried it on an oldstyle filebased sitemap as well as a OH3 UI-created sitemap.
The used line in the sitemap-file is: Image url="http://opuspi4:8080/static/meteogramm.png"
Which looks the same as stated in the example in the Sitemap Documentation.
Am I missunderstanding something completly or is my system somewhat corrupted?
Then I’m not sure why it wouldn’t work. I know for sure it can work that way, at least in MainUI. I used to use something similar in my sitemaps back on OH 2 as well (I’d generate snapshots of my Grafana charts as images).
All the images you see here used as the background of the locations cards come from the $OH_CONF folder and are configured using /static/imagename.png/
My usecase is a MainUI created Sitemap, the code is:
sitemap page_7dc56fe3dd label="Wetterkarte" { Image icon="temperature" label="Wetter" url="http://opuspi4:8080/static/meteogramm.png" refresh="60000" }
Which gets sort of parced by the system to: