IpCamera: New IP Camera Binding

Hi Matt,

I am viewing from sitemap from phone and laptop. Inside and outside my local network, at work, at home, WiFi or mobile connection. I don’t bother about the data usage as its small. The camera images are located on the top level of my site map and sometimes I leave it open. Mostly I don’t specifically check the images but as I use the app for other things I pass over them and take a glancing view.

The 15mins interval is just so I get a quick check all is OK as I use the openHAB app for other things without specifically checking cams all the time. eg if Someone parked on my drive, Blinds failed to open, for example I would see while going about my normal business. The images from the cams are also uploaded to my own web page every 15mins. I can see the whole day in 15min intervals. So, part of my thinking came from that.

I tried your 10s poll idea and that works too but I need a poll of 2sec to get an image every 10sec. I see in the log images being updated every 10sec until I turn the image update switch is off.

GarageCamImage changed from raw type (image/jpeg): 768000 bytes to raw type (image/jpeg): 768000 bytes

If leave it off then I need to switch it on manually to update the images. So that defeats the casual viewing. Turning it on/off automatically works eg when the garage door opens and every 15mins. Then the images are up to date without having to manually activate the update.

IMAGE_UPDATE_EVENTS=0, is needed to reduce traffic. I am not sure what =1 does yet. Readme wasn’t clear enough for a dummy :slight_smile:

Hi @matt1
Did you notice there is a new option in the openhab GA integration, which had been deployed to use Metadata now…
There is a trait for camera string available now…

String { ga="Camera" [ protocols="hls,dash" ] }

May this could come in hand for directly parsing a camera feed to a Google Hub/chromecast device.
I havn´t yet tried, as I´m still struggle getting my cam setup for video (ffmpeg)… Hopefully soon…

Just thought this might be worth mentioning.

@Kim_Andersen
Does your camera now go online with latest build and get snapshots? Yes I heard it was getting added soon, do you know if this requires anything to change on our server ends other than the string line? Is it purely an upgrade already done in the myopenhab cloud?

Hi @m4rk,

Your situation does challenge my thinking which I like, so thanks for the extra info. The next build the Image will update at the poll rate if it is 5 seconds or higher, under 5 seconds it is limited. The ipcamera.jpg method is not limited and is the most efficient way to get an image (if the camera can not serve the file directly).

I wish to stress the difference between the traffic on your internal network VS the traffic that potentially leaves and can head to your devices that are away from home. Having a shorter polling time does not mean it leaves the internal network. It only leaves if you have the picture showing on a UI and the picture is changing on the UI, so if you close the page showing the picture it stops or you can limit it by the refresh options in the sitemap.

There are a few approaches you can take to keep traffic to a minimum. Consider these…

  1. Set the poll time to 10 seconds. Then follow the method here using WebView and html files that refresh every 15 minutes in the html code. The UI can then be pulled down and let go in both the ios and android apps and it will refresh and give updated content at any time. In basic UI just use the browsers refresh ability (F5). Note you will need to use a VPN as WebView does not pass through myopenhab which is why you need a VPN or another method. Even though the internal server is updating every 10 seconds, the image only updates every 15 minutes or when you manually drag and let go.
  1. Change to using Pushover to send an animated GIF when your door is told to open or close. Pushover does not use the myopenhab server and the GIF is pretty small and can fast forward in time showing the door movement. Pushover also can be told to keep the last X messages so unlike email it keeps things tidy automatically and gives a history of the last X messages and gifs.

  2. Use the gif feature and display that in your sitemap with

Webview url="http://192.168.0.999:54321/ipcamera.gif" height=9

You can trigger its creation with motion alarms or the door closing can trigger it. WebView needs VPN to leave internal network.

  1. The way you were doing it is another way to change the refresh time “on demand” and perhaps I need to re-add some code to make it possible again. I just don’t like the idea of using a rule to toggle the switch.

  2. Using an Image item, you can use multiple links in your sitemap like the below, One has a 15minute refresh and a link opens to a page with a 10 second refresh. Fingers crossed I go the syntax right…

Image url="http://192.168.0.999:54321/ipcamera.jpg" refresh=900000
Text label="Camera 10 sec" icon="camera"{Image url="http://192.168.0.999:54321/ipcamera.jpg" refresh=10000}
  1. I just ran a test and mjpeg streams work with up to 9 seconds between picture changes. I could then change the refresh rate at any time inside the binding, a variable refresh so if an alarm goes off you can get higher rate that auto drops back to 9 seconds when the alarms stop, would be a cool feature but it seems to be limited at 9 seconds between pictures so for your use case not good enough.

No, still the same issue, so I´d let it rest untill I had more time to deal with it.
I will try to see if I can get it to work today. And hopefully I have figured out how to setup this ffmpeg… I honestly simply dont get it :frowning:

Just server side changes, so we dont have to change anything, except using metadata ofcouse…

If I manage to get my cam to work today, I´ll play with the new metadata as well…

Thanks Matt, I appreciate you spending some time on my use case. There is a lot to think about in your reply.

The basic idea was to make a easy to happen upon, top view, relatively up to date image without having to do anything like refresh, activate VPN, dig through sub sections, menus etc. I try to make this stuff as easy as possible to use usefully.

I have achieved this now with the current binding and will post the code for completeness at the bottom.

One thing I have noticed with higher refresh rates is my openHAB log filling up with

GarageCamImage changed from raw type (image/jpeg): 768000 bytes to raw type (image/jpeg): 768000 bytes

I try to avoid too much normal business stuff appearing in the logs because the problems and errors get easily missed.

I have three cameras. Here is the garage camera example

.thing

Thing ipcamera:HTTPONLY:001 "Garage camera" @ "Cams"
[
    IPADDRESS="192.168.x.x",
    USERNAME="x",
    PASSWORD="x",
    SNAPSHOT_URL_OVERRIDE="http://192.168.x.x/live/0/jpeg.jpg", 
    POLL_CAMERA_MS=2000,
    IMAGE_UPDATE_EVENTS=0,
    UPDATE_IMAGE=false,
    PORT=80
]

.items

Switch UpdateAllImages "Update images" <camera>
Switch IPCameraImageUpdate_Timer "Update IP camera images timer" <time> {expire="15m,command=ON"}
Image GarageCamImage "Garage camera image" <camera> { channel="ipcamera:HTTPONLY:001:image" }
Switch GarageCamUpdateImage "Get new image" <camera> { channel="ipcamera:HTTPONLY:001:updateImageNow" }

.rule
For manual activation of image update and automatic update every 15mins

rule 'Start updating camera images'
when 
    Item UpdateAllImages changed to ON or
    Item IPCameraImageUpdate_Timer changed to ON
then
   GarageCamUpdateImage.sendCommand(ON)
    TerraceCamUpdateImage.sendCommand(ON)
    PorchCamUpdateImage.sendCommand(ON)
    IPCameraImageUpdate_Timer.sendCommand(OFF)
    logInfo("Camera", "Updating started" )
    if (UpdateAllImages.state != ON) {
        if (ImageTimer === null) {
                ImageTimer = createTimer(now.plusSeconds(10)) [|
                        IPCameraImageUpdate_Timer.sendCommand(OFF)
                        GarageCamUpdateImage.sendCommand(OFF)
                        TerraceCamUpdateImage.sendCommand(OFF)
                        PorchCamUpdateImage.sendCommand(OFF)
                        logInfo("Camera", "Scheduled updating ended" )
                ImageTimer?.cancel()
                ImageTimer = null
            ]
        }
    }
end

For turning off manual activation of image updating

rule 'Stop updating camera images'
when 
    Item UpdateAllImages changed to OFF
then
    GarageCamUpdateImage.sendCommand(OFF)
    TerraceCamUpdateImage.sendCommand(OFF)
    PorchCamUpdateImage.sendCommand(OFF)
    logInfo("Camera", "Manual activated updating stopped" )
end

For garage door monitoring when commanded to Open or Close

rule 'Start garage camera image update while garage door is moving'
when
    Item GarageDoorMoving_Sensor changed to ON
then
        GarageCamUpdateImage.sendCommand(ON)
        logInfo("Camera" , 'Garage door moving >>> Garage image update started')
end

rule 'Stop garage camera image update  '
when
    Item GarageDoorMoving_Sensor changed to OFF
then
        GarageCamUpdateImage.sendCommand(OFF)
        logInfo("Camera" , 'Garage image update Stopped')
end

I am not sure if this needed but it makes sure the 15min timer is running at restart

rule "On restart"
when 
    System started
then
    logInfo("Startup" , "System startup time = " + now.toString("HH:mm dd-MM-yyyy"))
    IPCameraImageUpdate_Timer.sendCommand(OFF)
end

New build 2020-01-19 has these changes:

  • Now all the different mjpeg streams can be opened many times and the camera only sees 1 stream.
  • Snapshots can be generated from RTSP feed for httponly cameras. Only uses keyframes so depends how often your camera sends a keyframe as to how often it updates.
  • Changes for @m4rk so Image updates at poll rate if 5 seconds or more and updateimagenow should trigger an update. See the readme file on how to deal with the logs filling up with Image changes.
1 Like

Just downloaded and installed the latest version (as of today).
My Reolink RCL410 (added through PaperUI as Http only) went online and snapshot seems to work just fine, without using the override url…

I linked a few channels to items, and used PaperUI controlpanel to see whats happening:
Linked channels sofar:
Update the image (Switch). It works, but only if I set the option (1) in Snapshot/image update to always. Then I can turn on/off the image update… I believe this is not correct according to the text, the option (0) is said to update, only when the Switch is ON. (It doesnt).
Snapshot from camera - Works just fine. The image update every 2 seconds.
RTSP Url does not seem to show any stream in controlpanel. I´m not sure if it´s suppose to do that. I do have installed ffmpeg. But I have not changed or done any configuration. Just used the default.

Thats as far as I´ve got for now.

The newest version also doesn’t work for me.
I get the same error/warnings as in the older versions.

With the ONVIF Thing:

==> /var/log/openhab2/events.log <==

2020-01-19 18:28:31.237 [hingStatusInfoChangedEvent] - 'ipcamera:ONVIF:KGV' changed from INITIALIZING to ONLINE

==> /var/log/openhab2/openhab.log <==

2020-01-19 18:28:31.279 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - We got an ONVIF error400:<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:ns1="http://www.onvif.org/ver10/actionengine/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:ns10="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:ns11="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:ns12="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:ns13="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding" xmlns:ns14="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:ns3="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" xmlns:ns4="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:ns5="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:ns6="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:ns7="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:ns8="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:ns9="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:tad="http://www.onvif.org/ver10/analyticsdevice/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tls="http://www.onvif.org/ver10/display/wsdl" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><SOAP-ENV:Body><SOAP-ENV:Fault SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><SOAP-ENV:Code><SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value><SOAP-ENV:Subcode><SOAP-ENV:Value>ter:NotAuthorized</SOAP-ENV:Value></SOAP-ENV:Subcode></SOAP-ENV:Code><SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en">Sender not Authorized</SOAP-ENV:Text></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

And with the HTTPONLY Thing:

2020-01-19 18:25:25.825 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !!!! Camera has closed a channel 	URL: Cause reported is: {}

java.lang.ArrayIndexOutOfBoundsException: null

2020-01-19 18:25:47.868 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !!!! Camera has closed a channel 	URL: Cause reported is: {}

java.lang.ArrayIndexOutOfBoundsException: null

Try remove the override URL and use Http only.

Thanks. The warning message is gone.
But I don’t get an Image.

Try insert the RTSP URL.

Main Stream: rtsp://username:password@ip_address:554//h264Preview_01_main

Sub Stream: rtsp://username:password@ip_address:554//h264Preview_01_sub

New version works great, now i can see a mjpeg video from my cheap china cam which only provides rtsp-stream.

Anybody already has a working setup with sending a gif in an email, when there is movement?

Hi @ all
running this binding quite a while now, works perfect internally, but I am not able to setup mjpg stream at all…just no success.
The HLS stream is working, but I wonder if somebody is willing to give me his / her things configuration for foscam resp. the http thing?
Thanks for your effort

@Kim_Andersen
I got the new google metadata working. Just add and ask Google to ‘sync devices’. Info being added to readme at the moment.

String FrontDoorCamHlsUrl "Front Door" { channel="ipcamera:DAHUA:FrontDoor:hlsUrl", ga="Camera" [ protocols="hls" ] }

@halloween
See the readme for a pushover example should be easy to adapt it to email. I recommend using pushover as you can tell it to keep X number of messages as a history and it auto deletes them for you, plus the sound is different on your phone to an email.

@alkaline
See the readme file under the heading on what special steps are needed for Foscam, you need to use a url to enable mjpeg streams. Also not all Foscam models support mjpeg, recently they released some cheaper models that clearly state the feature is not in the firmware so check their website and contact their support. There is also a new feature only added in the last few days called ‘snapshots.mjpeg’ see the readme for more info as that gives higher resolution anyway and I prefer it over higher FPS and lower quality streams.

Perfect Matt…
I´ll still need to figure how to setup the hls streaming… But as soon as I get there, I´ll give it a shot… Would love to see it streamed to my Nest Hub on request.

I updated to the new version today.
But i have a problem with the “auto-update” of the snapshot.

Although i configured following in paperUI: image
It keeps updating (Same for all other settings)

Item definitions:

Image   cam_hof_snap                    "Kamera Hof Bild"                                               { channel="ipcamera:ONVIF:e5e853ce:image" }
Switch  cam_hof_update                  "Kamera Hof Update"                                             { channel="ipcamera:ONVIF:e5e853ce:updateImageNow", expire="2s,OFF" }

Log:

2020-01-20 13:30:27.336 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 732216 bytes to raw type (image/jpeg): 731392 bytes
2020-01-20 13:30:29.083 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 731392 bytes to raw type (image/jpeg): 731768 bytes
2020-01-20 13:30:31.214 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 731768 bytes to raw type (image/jpeg): 731696 bytes
2020-01-20 13:30:31.528 [ome.event.ItemCommandEvent] - Item 'cam_hof_update' received command ON
2020-01-20 13:30:31.541 [nt.ItemStatePredictedEvent] - cam_hof_update predicted to become ON
2020-01-20 13:30:31.551 [vent.ItemStateChangedEvent] - cam_hof_update changed from OFF to ON
2020-01-20 13:30:32.450 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 731696 bytes to raw type (image/jpeg): 732120 bytes
2020-01-20 13:30:33.172 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 732120 bytes to raw type (image/jpeg): 731568 bytes
2020-01-20 13:30:34.119 [vent.ItemStateChangedEvent] - cam_hof_update changed from ON to OFF
2020-01-20 13:30:35.213 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 731568 bytes to raw type (image/jpeg): 731944 bytes
2020-01-20 13:30:37.196 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 731944 bytes to raw type (image/jpeg): 732776 bytes
2020-01-20 13:30:39.283 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 732776 bytes to raw type (image/jpeg): 732872 bytes
2020-01-20 13:30:41.229 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 732872 bytes to raw type (image/jpeg): 732744 bytes
2020-01-20 13:30:43.281 [vent.ItemStateChangedEvent] - cam_hof_snap changed from raw type (image/jpeg): 732744 bytes to raw type (image/jpeg): 733504 bytes

Thanks, got it to work:

rule "send email when gif is ready - cam1"
when
    Item CamFrontdoor_CreateGif changed from ON to OFF
then
    logInfo("IP Cam frontdoor - GIF", "GIF ready and now sending email")
    val mailActions = getActions("mail","mail:smtp:myemail")
    mailActions.sendMail("myemail@mydomain.com", "Openhab IP-Cam frontdoor", "Openhab IP-Cam: ", "file:///tmpfs/camera/ipcamera.gif" )
end
1 Like

Thanks for providing the log. I can see that the control never gets sent the COMMAND to go OFF. Not an expert on the expire binding, you may need to ask in a new thread but control can be sent a state update which moves the control without sending the COMMAND. The binding needs the command to turn it off and since it is not sent the updates still occur.
So not a bug as it would work as intended if you used a rule or moved the control manually. Hopefully it is simple to fix with using the expire binding in a slightly different way.

Now it’s working.
I removed the expire definition in the item file and created a rule for the item:

var Timer cam_hof_timer = null

rule "cam hof update off"
when
    Item cam_hof_update changed to ON
then
    if (cam_hof_timer !== null) cam_hof_timer.cancel()
    cam_hof_timer=createTimer(now.plusSeconds(1), [ |
            cam_hof_update.sendCommand(OFF)
            cam_hof_timer = null
    ])
end

And i changed the setting in the PaperUI to:
image

Thanks for the help :grinning:

If i find some time today, i will give the mjpeg feature a try.

If you read the expire documentation it can send the command VS an update. Just a syntax change and it would have worked. If you update a control it is not the same as sending it a command, worth learning about when you get a chance as it will catch you out.