IpCamera: New IP Camera Binding

Yes all must be in the addons.
You will also need to clear tmp and cache folders.
If you have not done textual config (things file) you need to delete and readd the camera.
There are breaking changes to be aware of especially if you override urls with textual config.

Using the search on this thread will answer these for you.

@Sascha_
Very Cool let me know how it goes.

@matt1: can i somehow display these prefetch images through use of a URL? For me the new animated gif creation (pre- and postroll) work perfectly; i send that to my phone. But i want to display camera images on my kodi systems using Security camera overlay. This uses a URL for image retrieval refreshed every second. As i have 3 Kodi streamers and am using image refresh every second for animated image creation, i get too much calls to my camera and the images are not dispayed. If i can serve the images already retrieved by your binding this will take out any additional stress on the camera; openhab will serve these images to all 3 streamers.

Not currently but it would be possible for the binding to pass them on without being saved to disk if the feature was added. I already do a similar thing for the mjpeg stream for similar reasons.

I would normally say use the camera to serve the files directly but you gave a good description of why that won’t work.

This method may work if you save the file to the HTML folder and use openhabs serving ability.

Just to be clear about the way it works now; does the image channel save the image to disk every poll interval? it doesn’t seem to do that. It would be a welcome addition to have a switch channel available to be able to to just that. If the switch is on the fetched image is also saved to the FFMPEG_OUTPUT location (and thus overwritten every poll), if it is off it behaves as current behaviour. THis way i can save the images to the opehad html folder for some seconds as long as the kodi streamers show the camera overlay…

No the binding tries to keep loads on the openhab server as low as possible and as most users have a raspberry pi with possibly a sd card I don’t believe that is a good idea. The way would be to allow this url to be used which keeps things consistent with how the rest of the binding works.
Openhabip:54321/ipcamera.jpg
Then it only places a load on the server when kodi asks for the file and it does not use the disk, only ram.

Could you do a guide on how u setup kodi to do the overlay?

Not to spam this topic, I’ve created a seperate thread for my development

1 Like

The Kodi Security Cam Overlay can be found here. After installation you can configure up to 4 camera feeds (image URL) and some other stuff like refresh time etc.

within openhab i created a rule which is used to send an animated gif to my phone with pushover, and display image feed onto kodi:

rule "DoorBell"
when
    Item Doorbell changed to ON
then
    if (FrontDoorButtonPressed.state != ON) {
        FrontDoorCreateGif.sendCommand(ON)
        FrontDoorButtonPressed.sendCommand(ON)
        var String content = '{"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam"},"id":"1"}'
	    sendHttpPostRequest("http://192.168.x.x:8080/jsonrpc",'application/json',content)
        sendHttpPostRequest("http://192.168.x.x:8080/jsonrpc",'application/json',content)
        sendHttpPostRequest("http://192.168.x.x:8080/jsonrpc",'application/json',content)
    }
end

So it would be very welcome the ipcamera binding could host a snapshot available through an url so i have to configure one URL only, not having multiple requests to the camera.

You could always mount a tmpfs directory and just store it there.

Thanks for your amazing work on this, Matt. I recently rebuilt my OH server which had been upgraded from 2.0->2.1->2.2->2.3-2.4 and was frequently crashing due to running out of Java heap space so I took the opportunity to upgrade to the latest version of your binding.

I’m using several Hikvision 2085 cameras and I noticed that the snapshot capture URL override and the stream URL override needed to be filled in the latest version. I’m fairly sure I didn’t need to specify these with the earlier version of the binding. I say I’m fairly sure but I have a bad memory and never take notes when I configure stuff…

I also got the GIF capture working and can see a ipcamera.gif file in the tmpfs directory. How can I use this file with Telegram. I already have a rule that sends a couple of snapshots:

    rule "Send telegram with fixed message when front door camera intrusion detected"
when
    Item CameraFrontDoor_IntrusionAlarm changed from OFF to ON
then
    logInfo("Dev", "Front door camera intrusion detected.")
    CameraFrontDoor_UpdateTheImage.sendCommand(ON)
	AVTVLGWebOSTVOLED55B6V_1_Toast.sendCommand("Front door camera intrusion detected")
    sendTelegram("Bot", "Front door camera intrusion detected")
    Thread::sleep(100)
    CameraFrontDoor_UpdateTheImage.sendCommand(OFF)
    var String base64Image0 = CameraFrontDoor_SnapshotFromCamera.state.toFullString
    sendTelegramPhoto("Bot", base64Image0, "Intrusion detected at front door")
    Thread::sleep(1000)
    CameraFrontDoor_UpdateTheImage.sendCommand(ON)
    Thread::sleep(100)
    CameraFrontDoor_UpdateTheImage.sendCommand(OFF)
    var String base64Image1 = CameraFrontDoor_SnapshotFromCamera.state.toFullString
    sendTelegramPhoto("Bot", base64Image1, "Intrusion detected at front door")
end

The line

var String base64Image1 = CameraFrontDoor_SnapshotFromCamera.state.toFullString

gets the snapshot into an item that can be passed to the Telegram binding. How can I do the same thing with the GIF file?

The documentation looks very good… See this link as it could be done by the file or by the URL. NOTE: I have not done it yet so the below rule is just a guess.

rule "Send telegram with local image and caption"
when
    Item CameraFrontDoor_CreateGif changed from ON to OFF
then
    sendTelegramPhoto("bot1", "file:///path/to/local/ipcamera.gif", "sent from openHAB")
end

I had no idea the Telegram binding could access files. Thanks for the info.

I’ve updated my rule to these two:

rule "Create front door camera GIF when front door camera intrusion detected"
when
    Item CameraFrontDoor_IntrusionAlarm changed from OFF to ON
then
    logInfo("Dev", "Front door camera intrusion detected, triggering camera GIF creation...")
    CameraFrontDoor_CreateAnAnimatedGIF.sendCommand(ON)
end

rule "Send front door camera GIF via Telegram"
when
    Item CameraFrontDoor_CreateAnAnimatedGIF changed from ON to OFF
then

sendTelegram("Bot", "Front door camera intrusion detected")

sendTelegramPhoto("Bot", "file:///etc/openhab2/html/tmpfs/ipcamera.gif", "Intrusion detected at front door, GIF sent")

end

This works as far as sending an image to Telegram but it’s not animated. The ipcamera.gif file on the OH server is around 800k but the file saved to the gallery on my phone is about 50k. This must be a limitation of the Telegram binding, maybe it’s pulling only the first frame from the GIF and sending that?

Have you managed to send animated GIF files via Telegram? Maybe I’m missing something important…

It is possible the Telegram binding/action does not support the feature. The telegram API does support the sending of animations and also mp4 video files which the binding could be made to support if it does not already, see here…

I know people are doing it with Pushover and having a moving picture in the push messages. See if you can ask this question to the telegram binding maintainer @ZzetT (?) if it is supported and if not if it can be added for both gif and mp4.

If you are running a PI the default amount of memory Openhab can access is way too small in my opinion when all the device is doing is running Openhab and no other major system processes. By default I think the heap size is 1/4 of the ram in your system and that is all Openhab can use unless you make the change in this post. You need to leave some ram for Linux and other processes like Mosquitto that do not run in the Java virtual machine.

I did make a change recently due to a user request as their camera did not work with ISAPI urls, can you confirm this is the issue by trying these two in a web browser please? Ip of your camera comes first. Otherwise it may be the NVR channel is set wrong and overriding the url removes the effect of the nvr setting.

/Streaming/channels/101/picture

/ISAPI/Streaming/channels/101/picture

1 Like

New build 2019-06-22 has these changes:

  • Binding can now respond to requests for a current snapshot ipcamera.jpg if you use this url: http://192.168.xxx.xxx:54321/ipcamera.jpg
    @posixx you requested this feature, let me know if it fixes your use case.
    @Kim_Andersen this feature should make casting a static picture very easy if it does not work direct from a camera.

  • Changes to Instar to give correct default ONVIF port and snapshot url.

  • Huge clean up of the code that means all cameras were touched. This was to make the binding closer to merge to the project and make it easier to maintain the code. Look for bugs and any changes in performance.

1 Like

@matt1 tnx for the feature. i will install an test tomorrow. To prepare for that; how does this url determine which ipcamera to use for the shapshot? I have 7 camera’s and need a way to select the frontdoor camera?

Each camera will have its own port that the binding is serving the files on. So just change the number 54321 to something unique for each camera.

Ok, which configuation parameter is used for this port? It seems i’m not able to determine which one…

EDIT: oh i think it’s the default port configured in things file. I get an image when i open this URL but it’s the animated image from the last animated gif creation. I would expect the same image as the image channel content (ipcamera:HIKVISION:FrontDoor:image)…

EDIT2: Sorry, i used ipcamera.gif which is the animated gif ofcourse. using ipcamera.jpg gives me the current snapshot! Looks very gooed will try on my kodi systems tomorrow.

@matt1 it works perfrectly. Many many thanks for your great work!

1 Like

It appears that rebuilding my OH system on a new VM has fixed (or hugely reduced) the memory leak I was experiencing. I’d already had to increase the Java heap size to 1.5GB and even then I’d had to set up a cron job to restart OH every night. Since the rebuild I’ve not seen any OOM issues.

To answer your questions:

The output from /Streaming/channels/101/picture is a snapshot from the camera and the output from /ISAPI/Streaming/channels/101/picture is also a snapshot from the camera. This prompted me to check the config of the camera, it looks like a recent firmware upgrade must have unticked the ONVIF
checkbox. I’ve ticked both the ONVIF checkbox and the HIKVision-CGI checkbox and the binding no longer needs the stream and snapshot override URLs to be filled. Excellent! :slight_smile:

However…

I’ve noticed that the current version (2019-06-22) of the binding doesn’t seem to be detecting intrusion alarms. This was working with the previous version I had installed, I can’t remember which version that was. I think it might have been from around February or March.

Here’s an excerpt from the log:

24-Jun-2019 14:42:29.413 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Sending camera GET: http://192.168.0.68:80/Streaming/channels/101/picture
24-Jun-2019 14:42:29.414 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] -    Using the already open channel:0     GET:/Streaming/channels/101/picture
24-Jun-2019 14:42:29.414 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Sending camera GET: http://192.168.0.68:80/ISAPI/System/IO/inputs/1/status
24-Jun-2019 14:42:29.414 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] -    Using the already open channel:2     GET:/ISAPI/System/IO/inputs/1/status
24-Jun-2019 14:42:29.416 [DEBUG] [enhab.binding.ipcamera.internal.MyNettyAuthHandler] - 401: Mark to re-use,  the channel:0     GET:/Streaming/channels/101/picture
24-Jun-2019 14:42:29.417 [DEBUG] [enhab.binding.ipcamera.internal.MyNettyAuthHandler] - 401: Mark to re-use,  the channel:2     GET:/ISAPI/System/IO/inputs/1/status
24-Jun-2019 14:42:33.047 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - commonCameraHandler closed channel:1    URL:/ISAPI/Event/notification/alertStream
24-Jun-2019 14:42:34.413 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Sending camera GET: http://192.168.0.68:80/Streaming/channels/101/picture
24-Jun-2019 14:42:34.414 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] -    Using the already open channel:0     GET:/Streaming/channels/101/picture
24-Jun-2019 14:42:34.414 [WARN ] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - The alarm checking stream was not running. Cleaning channels and then going to re-start it now.
24-Jun-2019 14:42:34.414 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Sending camera GET: http://192.168.0.68:80/ISAPI/Event/notification/alertStream
24-Jun-2019 14:42:34.416 [DEBUG] [enhab.binding.ipcamera.internal.MyNettyAuthHandler] - 401: Mark to re-use,  the channel:0     GET:/Streaming/channels/101/picture
24-Jun-2019 14:42:34.419 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Have re-opened  the closed channel:1    GET:/ISAPI/Event/notification/alertStream
24-Jun-2019 14:42:34.419 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Sending camera GET: http://192.168.0.68:80/ISAPI/System/IO/inputs/1/status
24-Jun-2019 14:42:34.419 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] -    Using the already open channel:2     GET:/ISAPI/System/IO/inputs/1/status
24-Jun-2019 14:42:34.423 [DEBUG] [enhab.binding.ipcamera.internal.MyNettyAuthHandler] - 401: Mark to re-use,  the channel:1     GET:/ISAPI/Event/notification/alertStream
24-Jun-2019 14:42:34.424 [DEBUG] [enhab.binding.ipcamera.internal.MyNettyAuthHandler] - 401: Mark to re-use,  the channel:2     GET:/ISAPI/System/IO/inputs/1/status

Those 401 errors look like a password issue but I’ve checked the password in the binding for the camera user. I created an operator user on the camera and every privilege that can be turned on is turned on. Is there anything I can do to try and debug this?

I forgot to add that I’ve got Hikvision-CGI Authentication set to “digest/basic”.