Update of ZoneMinder bindings

Finally I have started looking into a update of the ZoneMinder Binding.The Binding seems to have some problems conencting and/or stay conencted to the ZoneMinder Server. There is also reports that there seems to be problems using development version 1.31 of ZoneMinder server. It all ends more or less in the same piece of code, which is the authentification algorithm, which seems to have some general issues. Therefore I plan to rewrite that and hopefuly get a stable Binding.

I will rework the authentification process, in the mean time it would be interesting to start a discussion of ideas to improvement (besides from the above)

2 Likes

Thanks for doing this. I don’t use it yet but am planning on getting a zm server set up soon.

PTZ support would be great!

Thanks for the input.
Unfortunately I don’t have caneras with PTZ control, so I would need some help for testing…

I have now published an updated ZoneMinder Binding in the Market place.
The main change is that the establishment of connection to ZoneMinder server has been rewritten.
It goes ONLINE / OFFLINE a couple of times in the connection process, but it should remain online once connected.

The only request for improvement so far is PTZ support, if I should look into that, I need somebody whom are willing to test/help - since I don’t have that on my cameras :frowning:

I will look into stabilizing the above changes before a final release.

Awesome! I’m waiting for a bit more hardware before I set up my zoneminder server. I’m running the snapshot so I should be able to run the new version of the binding.

If I’m successful, I’ll look into getting a PTZ camera, at which point I’d be very willing to help test.

After a while of inactivity, due to things with higher priority . I am now ´ready to finalize the next release. Status is that I have pushed an update to the market place, which handles some of the problems. After I published the binding I found and correcetd one of the main causes of instability. That is running in my own setup for test right noe. If that continues to behave well, I will upload the jar to the marketplace .

I have got a contribution from @captndelta, so that the monitor will offer two new channels (one with a still image and also an string containing an url to the video stream). The main problem with the latter is that we have to expose user name and password to zoneminder server. therefore I have decided to look into creating a hash authentification key. That seems also possible, but there is some settings in ZoneMinder that needs to be set in a special way for that to work.

While working with the improved sessionhandling, and the authentification mentioned above. I have writen a lot of code snippets to check for certain settings in ZoneMinder. I plan to put that into a check tool that can verify the ZoneMinder configuration in openHAB. It will be a small commandlien toll that simply loads the openHAB settings and verifies that API is enabled and so on.

Last but not at least, @Dome has suggested PTZ camera support.

Hopefully I will be able to include that as well before creating a pull request.

1 Like

As mentioned earlier, I would like to add PTZ support to the ZoneMinder Binding but need a little help:

Would somebody like to share their PTZ settings, I would appreciate to see the following two files: https://YOUR-ZONEMINDER-SERVER/zm/api/monitors.json, and https://YOUR-ZONEMINDER-SERVER/zm/api/controls.json?

Please be aware that the files might contain password, which is off no interrest to me, so that can safely be deleted.

Also I would like some ideas of how PTZ controls is best represented in the Binding. A Couple of Dimmer channels?

I have a PTZ camera, but I never got PTZ to work through ZM (just didn’t spend the time on it). But this is a feature I would really enjoy having. I’ll give it a go and see if I can get PTZ working in ZM. Can’t really promise anything but if I’m successful I’ll post them here for you.

Also I like your idea of using dimmer channels for PTZ position. I’m not sure my camera is at all aware of its actual position so this may not work in my configuration, but the idea is good none the less.

1 Like

@mr_eskildsen : Just a small correction: The user/pass is not exposed to the outside of the OHAB installation, the OHAB proxy remaps the URLs to something that doesn’t contain the originating URL at all. (Unless someone creates a Text widget of the String URL item, which is not something that’s required for this to work). However, it may be exposed in the OHAB log files (at debug level settings) when the URL value changes.

IIRC, the zoneminder hash key was introduced b/c the zoneminder web UI does indeed expose the full URL (inc. user/pass) in the client html code.

However, we could still use that in OHAB, it would make the user/pass stuff go away in the logs. The hash as used in ZM is created from (among other things) user/pass + hash secret + date/time, so for this to work the time set on both the ZM and OHAB computer has to line up within a few minutes (I think 59 max), just as a heads up for future trouble shooting.

If you want to, I can take a look at implementing the ZM auth hash. I’d just need a few more config selections from the ZM side.

Cheers,
-Th

Well, just learned something new :slight_smile:

Already got that working, so the implementation will allow both approaches (at least for the image) :slight_smile:

Cool! :sunglasses:

BTW, I wouldn’t mind if you’d mark the video stuff a experimental/advanced or something like that, since for video we still have to deal with this bug:

Cheers,
-Th

Just send you ine in a PM, there’s one cam in there that has PTZ controls.

As mentioned, dimmer channels have abs values, which don’t map well to cam controls, since they tend to be relative ( “move x by 20”). The single cam I got which allows abs positioning moves first to the channels home value, then moves to the new abs position in that dimension, which wouldn’t do well when you just move the dimmer slider from 50% to 55%.

I tend to think that for live positioning, a new GUI control widget would need to be created, which knows about data types that send the corresponding commands to move a cam. It’s not like there aren’t already specialized widgets/types for other applications (there is a color wheel, rollershutters, etc), so for this case the folks in charge would probably be even receptive for creating such a thing (maybe @kai is listening), however the onus would be on us to create that (which is quite a bit of work outside of this plugin).

As far as a low-hanging fruit for PTZ: Many PTZ cams (most?) allow pre-programmed positions (set up via the ‘native’ cam interface), which can be called up via a URL that just maps a pre-programmed position to a number or string pattern in the URL. It could be relatively easy to map this to OHAB via the ‘Switch’ widget and its mappings (see: https://docs.openhab.org/configuration/sitemaps.html#element-type-switch , instead of TV channels think pre-programmed cam positions that the ZM plugin can supply). I haven’t delved too deep into that, but the ZM interface provides those presets on their web API.

Should we try this first? I’d be interested…

Cheers,
-TH

The reason that I was asking for especially the controls file, was that I would like to see how data looks for a camera with PTZ abilities. In my own setup I saw Min / Max for each direction, so I thought that could be used for mapping it to a relative scale (eg. dimmer). After looking at the file @captndelta have sent me, I can see that the dimmer approach simply won’t work. The camera is not providing any min / max values, so it is impossible to map values to a relative scale.

That might be a possibility, but the problem is still that I have to handle the presets in a meaning full manner. As far as I see the number of presets wouldn’t be static. The one camera I have seen has twenty options for presets. So the question is how to represent that as a channel. As far as I see the options right now, a channel with a number would be the possible solution. Then the user has to map to whatever representation (Switch or whatever) he/she wants in a sitemap. The problem with a Number is that it is technical possible to set it to an invalid value (eg. ‘21’), since what is valid is dynamic for individual cameras. For that purpose a Range would be great, I am not sure if there is any plans for that.

I would still be interested in seeing configuration files for a working ZoneMinder PTZ camera. My best bet with the available datatypes in openHAB, is to provide a Number channel containing the position of the camera (in X, Y and Z).
But it would leave error handling close to none, since I can’t prevent the user from assigning invalid values to the number item.

From what I have seen until now, I believe @captndelta suggestion with exposing presets is a possible way to go. It is less complex, but still the data is represented somewhat the same in ZoneMinder, so a base would be established.

EDIT:
ZoneMinder has a list of all possible controls here
I also found some description on how to control it, allthough it can’t be done through the API, look here

After attaching my brain to the process… :scream: - I remebered that there already is two channels in the Monitor that acts somewhat in a manner that would be apropriate:

  • Detailed Status (Idle, Pre-Alarm, …)
  • Function (None, Modect, Monitor…)
    I have to figure out if this can be done programatically, I saw a discussion some time ago, regarding dynamic adding channels. So I believe it can be done, though I am uncertain if the options can be set programatically.

With the above in mind, I will start a POC on PTZ support , using presets as the simplistic case.
Steps would be:

  1. Create a new (discoverable) Thing called ZonMinder PTZ Control (or something like that)
  2. Add a Number channel, that can be used to move the camera to presets
  3. Release to the marketplace
  4. Dynamically control the configuration of the channel, so that accepted values correspond to what the camera control is capable to do.
  5. Release to marketplace

The first two steps shouldn’t be that complicated as far as I see it.Allthough ZoneMinder is doing it in yet another way (eg. not via API), I believe most of the POST stuff already is there. So I “just” have to create a class for the Control “API”, with get/set functions. And off course the openHAB thing.

Is there any way to reduce the load the binding produces on the zoneminder server ?

Im running ZM on a banana pi with an attached SSD. With 4 Cams and only 2 fps monitor rate this solution is usable.
Load is around 2 with about 25% CPU utilization - upper edge for a 2-core system.

When I activate the binding, Load rises to 3.x with about 50% CPU utilization and I get errors like

ZoneMinderHostLoad dataset could not be obtained (HTTP Response: Code='401', Message='Unauthorized')

which do not occur on lower loads.

From the log entry it looks like you are using the version from the marketplace. At least the marketplace version is an alpha and there is a lot potential of optimising.
First you should look into the refresh rates, especially the diskload refreshrate could/should be more infrequent. I have read somewhere that it is/was implemented as a diskusage command running from the root. repeating that too often won’t do your ZoneMinder Server any good. Eventually try to disable that request by setting the refreshrate to zero…

I don’t think that the above suggestion will solve everything, I have to improve the session handling and also considder if data transfer could be more intelligent. It won’t be better when we add still images…

Your’re right - its the marketplace version. Obviously I misinterpreted that with OH 2.2 an updated marketplace version is available.

The binding is not vital for my home solution - it would be a nice enhancement. So im looking forward at new releases.
So take this post as a hint that the binding should not put additional load to the server because ZM is demanding enough. :slight_smile:

Thanks for that :-). I try to reduce load, since we all try to run openHAB and whatever we have on small machines…
Actually that is one of the reasons I have omitted image and video stream until now. Regarding Video and Images, it should be possiible to disable that feature - to reduce load on both openHAB and ZoneMinder. My hope is to produce a somewhat stable version of the binding, release it to the market place. And then work on what is left in a more experimental release. I suspect that would be video streams and PTZ control…

Yesterday evening I have build a new version of the binding for the marketplace. I just realised that it seems to be three tiems as big as it use to be. So obviously something went worng… I will look at that tonight.
It seems to behave better than the previous marketplace version, so for those who dare to try it click here. It is only testet for a few hours on my own system, so everthing might happen…
Besides from improved session handling it supports new channel with a still image (thanks to @captndelta for his contribution). I suspect that it can put some load on your ZoneMinder server, but try fiddling with the refresh rates. Still it should be better than previous, because it should not try to login again and again(which seems to push some load on the ZoneMinder Server - @rbausdorf you might wanna try how this works in your environment?) I am working on a better approach for this.
Be aware that a few things might change in the comming release…

Does the 2.3 version work with stable OH 2.2 ?

I always get

[BRIDGE]: 'ZoneMinderServerBridgeHandler' general configuration error occurred. Failed to initialize. Exception='Provided credentials not valid'

But the creds are ok. ZM version is 1.29