I like to receive notifications of my camera. I made the following testrule (OH5.2)
import java.net.URL
rule "Send camera snapshot"
when
Item TestButton3 changed to ON
then
val imageUrl = "http://192.168.178.221:80/cgi-bin/api.cgi?cmd=Snap&channel=0&snapType=sub&rs=9527000K7RR3HWHY&user=admin&password=*mypassword*"
val url = new URL(imageUrl)
val connection = url.openConnection()
val contentType = connection.getContentType()
val bytes = connection.getInputStream().readAllBytes()
val image = new RawType(bytes, contentType)
ImageAsString.postUpdate(image)
sendNotification("my@emailaddress","Test","camera","camera's","Camera zuidzijde",null,"ui:/basicui/app?w=1204&sitemap=default","item:ImageAsString",null,null,null)
end
When I execute the rule the notification is sent. However only when I am in the local network (or VPN) the image is displayed in the notification. So even though I have used the Image file (defines as Image ImageAsString) and not an URL, the image does not display remotely.
Looks to me like a bug in the IOS app I am using. Any ideas.
It’s not a big. The notification doesn’t include the actual image. It only includes the url so your phone can download the image. When you are not on your lan, your phone cannot reach http://192.168.178.221:80/ (obviously since that’s an internal address).
You either need to
host the image using OH itself (put the image in $OH_CONF/html, IP Camera binding, etc)
I take it ImageAsString is a Image item ? Just fyi there is already a built in action to set an image item from a URL see openHAB Cloud Connector - System Integrations | openHAB for more info but it looks like (single line vs the 7 lines you have)
where Apartment_Camera_Snapshot is your image item.
The app will try an pull the image item through myopenHAB if not on a local connection, if thats not working, then can you verify at least that you can access your instance from the app when outside? AS much detail as you can give about the item, myopenhab connections, etc… would be helpful.
Dan, thats the way I try to accomplish this. Using an image item and push it through the openHAB Cloud connection.
I know about the fact that pointing to an URL not reachable by the client, does not show an image. Thats exactly why I use the image-item to push and not the url way.
Sadly only, the image-item way only shows on the local connection either. Therefore I supposed it must be a bug in the IOS client. There is nothing more for for me to configure and get it to work.
The docs say clearly the image-item has to be used to remotely have the image available. Check out the last lines of the docs.
mediaAttachmentUrl: The URL of the media attachment to be displayed with the notification. This can either be a fully qualified URL, prefixed with http:// or https:// and reachable by the client device, a relative path on the user’s openHAB instance starting with /, or an image item with the format item:MyImageItem. If the media attachment URL is not reachable by the client device (ie. the URL is not available on the public internet), use the setImage action to set the image item to the URL first then use item:MyImageItem as the media attachment URL.
import java.net.URL
rule "Send camera snapshot"
when
Item TestButton3 changed to ON
then
val imageUrl = "http://192.168.178.221:80/cgi-bin/api.cgi?cmd=Snap&channel=0&snapType=sub&rs=9527000K7RR3HWHY&user=admin&password=mypassword"
val url = new URL(imageUrl)
val connection = url.openConnection()
val contentType = connection.getContentType()
val bytes = connection.getInputStream().readAllBytes()
val image = new RawType(bytes, contentType) ImageAsString.postUpdate(image)
sendNotification("my@email","Test","camera","camera's","Camera zuidzijde",null,"ui:/basicui/app?w=1204&sitemap=default","item:ImageAsString",null,null,null)
end
I was looking for the use of setImage for al long time (could not find any example of using it). Now you suggest me to use it with the correct syntax (which was not obvious to me).
Sadly this does not work. This was the first syntax I tried obvious because it was in the docs.
Script execution of rule with UID 'testbutton-3' failed: The name 'setImage' cannot be resolved to an item or type; line 61, column 2, length 162 in testbutton