Zoneminder binding

@mr_eskildsen Rather than restarting zmserver each time the camera operating mode changes, I wanted to only restart it if it has gone offline. However, I noticed that even when the bridge goes down like this

[INFO ] [andler.ZoneMinderServerBridgeHandler] - [BRIDGE (582d1d4a)]: Bridge status changed from 'OFFLINE' to 'OFFLINE'

I see that the ZoneMinder Server State is still online? It should go offline if the bridge dies. I wanted to use the following code to bring the ZM server up, but it doesnt work due to above issue.

rule "Zoneminder Restart"
when
    Item ZoneMinderServer_Online changed
then
         logInfo("Zoneminder", ZoneMinderServer_Online.state)
         if (ZoneMinderServer_Online.state==OFF)
         {
                Thread::sleep(10)
                 logInfo("Zoneminder", "Restarting ZM server")
                 executeCommandLine("sh /home/openhab/restart_zm.sh",10000)
         }
end

Any comments?

Hello eskildsen,

I just installed the Zoneminder binding and running also into Status: OFFLINE - COMMUNICATION_ERROR Error occurred (Check log). The bridge doesn’t come ONLINE.

Debug:
Exception occurred in updateAvailabilityStatus Exception=‘null’
11:59:24.426 [INFO ] [andler.ZoneMinderServerBridgeHandler] - [BRIDGE (1311ee20)]: Bridge status changed from ‘OFFLINE’ to ‘OFFLINE’
11:59:24.428 [INFO ] [smarthome.event.ThingStatusInfoEvent] - ‘zoneminder:server:xxxxxx’ updated: OFFLINE (COMMUNICATION_ERROR): Error occurred (Check log)
11:59:24.431 [INFO ] [me.event.ThingStatusInfoChangedEvent] - ‘zoneminder:server:xxxxxx’ changed from OFFLINE (CONFIGURATION_ERROR): Cannot access ZoneMinder Server. Check provided usercredentials to OFFLINE (COMMUNICATION_ERROR): Error occurred (Check log)
Credentials are okay

Went through the troubleshooting steps and noticed a flaw on the “I have tried all of the above, it still doesn’t work” part. When I issued the command given “curl -d “=XXXX&=YYYY&action=login&view=console” -c cookies.txt http:///zm/index.php” it will proof that connectivity is working, but actual login failed.
When using “curl -d “username=XXXX&password=YYYY&action=login&view=console” -c cookies.txt http:///zm/index.php” it does login successful.

Would be good to have that changed on the Github and document page.
(there’s a typo anabled instead of enabled in the top, next to some table <tags> on the document page)

Running the 2.1.0 release build with standard bindings, but guess I need to obtain and load a later zoneminder-binding, correct?

Have you tried to enable DEBUG logging? The log indicates a configuration error.
A valid configuration should look something like that:

There has been reported some issues, so whenever get the time I will dig into it.
I might have an idea about the problem. As far as I remember the API has it’s own path, Normally zoneminder is http://zoneminder.mydomain.org/zm and thus API is based at http://zoneminder.mydomain.org/zm/api
From what you post it looks like you have redirected to NOT using /zm. I briefly tried this setting in ZoneMinder and it seemed like the API still located at http://zoneminder.mydomain.org/zm/api (in my test) - and thus things failed.
I gues that could cause the problem you describe

Nope, just use the binding deployed with openHAB, haven’t changed for a long time - unfortunately.

To be sure I created a symbolic link in the zoneminder director for zm pointing upwards. That should allow any external queries including /zm to work as well.

/var/www/zoneminder
/var/www/zoneminder/zm -> /var/www/zoneminder.

Than /var/www/zoneminder/zm/api just works, which was needed to get zmNinja running.

Did a reinstall of the zoneminder-binding and kept the /zm path config. That worked.

Noticed that disk usage is reported in actual GB rather then %. Is that correct? Would prefer %

I found a solution for me with the apc_fetch() / API error.
Checkout your apache error log /var/log/apache2/error.log.
See if there is something that says:

 PHP Fatal error:  Call to undefined function apc_fetch() in /usr/share/php/Cake/

Also, check if you can access the zm API: (Zoneminder API Documentation)

Type this in your Browser after you logged on to your zoneminder:

http://your-server-ip/zm/api/host/getVersion.json

If you got an http error 500, the api is not working.

So if this is true, check your PHP Version.
In my case, i was running on 5.6, but also got 7.0 installed but not activated.
But all important php modules (like ACPU, APC) where activated in the 7.0 config :man_facepalming:. (howto install acpu)
To switch to php 7.0 do the following in your shell:

a2dismod php5
a2enmod php7.0
service apache2 restart

After that, the Zoneminder API starts working fine.

Good luck!
:slight_smile:

This post is a few years old, but whats the latest with this binding?

I installed the binding in OH2.2, added the ZM server and all the items auto discovered. WOW.

I tried to create a rule to turn on a light if an alarm (motion) is triggered, but I could not get it work.

Is this supported or does my newbie skills need more work?

thx

binding works perfectly - please share your items/rules

Well its working perfectly today, dont understand why it wasn’t working last night. I created the rules in paperui, not sure where to find the actual rules. In the log file Im seeing all my cameras sending motion triggers now.

2017-12-23 10:37:48.589 [vent.ItemStateChangedEvent] - zoneminder_monitor_94da2af1_monitor_2_alarm changed from OFF to ON

I suggest you start with the samples here.
This should give you a good starting point. If you create a rule that triggers on the alarm channel for monitor 1 in the sample it would be the Item called zmMonitor1_EventState.
Hope that clearifies things…

Sorry for the late answer :blush:

Got around to playing with the binding, and found (one of) the reason for “refreshThing()” failing with a NPE, as reported on a few occasions (see for example ZoneMinder Binding: Method ‘refreshThing()’ for Bridge failed for thing)

When using ZM 1.29, that version doesn’t support the “http://zm:80/zm/api/monitors/alarm/id:11/command:status.json” alarm status API. The zoneminder4j library (used by the binding) has a bug in ‘ZoneMinderMonitorProxy.getMonitorDetailedStatus()’ in that it attempts to access the status object, which is null, and thus creates a NPE. The exception prevents any other data points in that zm monitor to be updated.

I’ve created a fix, which is here: https://github.com/HentschelT/zoneminder4j/blob/8afab308319987e5570cf64ee501df7bdc0fa2bc/zoneminder4j/src/main/java/name/eskildsen/zoneminder/internal/ZoneMinderMonitorProxy.java#L293 , which made the binding work for me.

One problem I encountered is that the zoneminder4j repo (https://github.com/Mr-Eskildsen/zoneminder4j) doesn’t appear up to date, it wants to build version 0.9.4, but the OHAB2 plugin has version 0.9.7 of the jar. There is also API’s missing in 0.9.4, which I stubbed out for testing. I’d assume there are other things that are missing too.

@mr_eskildsen : any chance you could update the zoneminder4j repo to what’s used in the OHAB2 binding?

Cheers,
-Th

1 Like

Sure. Actually I have given it a general overhaul last year. Unfortunately I havn’t committed things yet, I had planned to do the final stuff in the Zoneminder Binding in my christmas holiday. Unfortunately I had a leak in my heating system (water - :rage: :rage: :rage:), so my office space was converted to living room…
But there is hope today the concrete layer was finished. This means I get my office back and hopefully a few minutes to correct what you describe above. I really aprreciate the detalied description.

Since a lot has changed in the marketplace binding of ZoneMinder, you might hav luck changing to that (I haven’t checked if it is so).

I have added the fix to my rework branch. I will try to get it into a decent state, so I can release something to the marketplace.

Thx for your contribution!

Dang, glad you got your place back in shape.

The reason I rather dabble in the source is that I want to add the image stream to each monitor handler - reason being:
(1) zoneminder gives a uniform API to all installed cam’s, all cam config is done in one place
(2) zoneminder (at least when you do motion detection) needs to run on a bit beefier box anyways, so scaling/transforming/overlaying images is done on the ZM computer and won’t affect OHAB2 performance.

This is what I got so far:

This is a updated jpeg image each time the monitors update, so still gonna need to do actual streams, some cleanup and finalize the config options.

Would you be up for accepting this into the mainstream zoneminder binding? If you’re ok with it, I’ll send you a pull request once I got it to a point where it’s a bit more polished.

Cheers,
-Th

1 Like

I would be glad to accept any contribution. I suggest that I do a checkin of miy changes to the zoneminder4j API, Then create two branches, one for bugfixes and one for development. Then you should be able to contribute in a somewhat meaning full way.

Status of the API is that the session handling has changed quite a bit. Also error handling has changed, though I would still like a better approach.

Yep, sounds like a plan!

The good news (for me at least) is that the stream/image additions I’m creating for the OHAB ZM binding don’t even require much of the zoneminder4j lib (the reason I traced the NPE down was just that I was annoyed not seeing updates on the zm monitor channels).
The image/stream stuff doesn’t use the session-based ZM REST API (there is nothing there for streams), but uses the nph-zms streaming server of ZM that only requires the credentials as part of the request. All I really needed for that is the credentials and the monitor ID from the config, and an additional (raw/image) channel in the MonitorHandler.

Cheers,
-Th

1 Like

@mr_eskildsen: it’s probably better to use github to communicate bug/issues/features than this forum, so I just started here:

If you’re ok with that, I’d rather use GH for bugs going forward, and keep design/architectural stuff here on the forum for a broader audience.

Cheers,
-Th

GH would be a better solution, rather than describing issues in a thread :slight_smile:

1 Like

Got the new ZM installed today. So very sexy. Added all my cameras as motion sensors for my lighting. Works much more reliably than my battery powered motion sensors.