ZoneMinder Binding in Marketplace (Beta)

It seems in the newest version of ZoneMinder the url to call is /zm/api/configs/viewByName/ZM_PATH_ZMS.json

Another factor… if you want to upgrade to PHP7, then you need the latest Zoneminder because of a required change in the cakePHP framework (bundled with ZM)… and obviously, the latest ZM requires PHP7 too.

I don’t understand why ZM would put in a breaking API change like this (view_>viewByName). The documentation still references view. Maybe the binding could detect ZM versions in order to use the appropriate API locations (/zm/api//host/getVersion.json)? But I think there’s already a call to this. Decompiling the jar and comparing to the code submitted in the PR, there appear to be a lot of files missing? @mr_eskildsen, can you help explain where the missing files are? For example, where is this?

at name.eskildsen.zoneminder.IZoneMinderResponse.createFromJson(IZoneMinderResponse.java:24) ~[277:org.openhab.binding.zoneminder:2.3.0.201805211219]

Unfortunately I have had some private matters that I have had to deal with the last couple of months, so I haven’t really spent some time on openHAB / ZoneMinder lately.

What version of ZoneMinder do you refer to as newest version? As far as I can see, the download page refers to 1.30.4, which is the version I run, and it should work fine (at least for me :slight_smile: )

I just checked the code. It shouldn’t be a big problem (besides from time), to have different appraches deopending on the version. But I really need some advice on what to use for which versions (again time is a factor for me)

@mr_eskildsen I’m running ZoneMinder in a docker container. Tried both https://hub.docker.com/r/quantumobject/docker-zoneminder/ and https://hub.docker.com/r/linuxserver/zoneminder/ (Second one is easier if your new to docker)

The version is [zoneminder v1.31.44]

Let me know if I can help.

Thank you… I could not find any reference to this library in the PR!

In looking at this some more, I do not think changing the binding to make different API calls based on the ZM version will be enough. At ZM 1.31.1, some configuration settings were moved from the database to files. These settings are no longer available through the API. The ZM team has made a few of them available, but only through /zm/api/configs/viewByName. Of the configuration settings moved to the file, the only one that the binding uses is ZM_PATH_ZMS. In addition to this, ZM_OPT_FRAME_SERVER appears to have been completely removed.

To make the binding compatible with the updated version of ZM, my suggestion is to update the binding anywhere it uses the config details from the view call for ZM_PATH_ZM (name, type, category, readonly), and change the call for the value to use viewAsName. Or, we could request that the ZM team add it to view and not just viewByName. Also, any reference to ZM_OPT_FRAME_SERVER would need to be removed. Fortunately, I believe these binding changes would be compatible with previous versions of ZM too.

My wife (always my hero!) came up with a workaround for using the binding (2.3.0.201805211219) with the current ZM master snapshot build (ZM 1.31.45). Basically, put the ZM_PATH_ZMS and ZM_OPT_FRAME_SERVER records back into the Config table, and then modify the config.php to ignore them.

1 Like

I really hoped that the API finally was getting stable :frowning:

Thanks for the fix. I have been down for a while and would like to get ZM back into my OH setup. I don’t know much about SQL syntax or whatever, but I seem to be having difficulty inserting those records into the table. Not sure if it is a character set problem from copying and pasting off your wife’s page or what. Any ideas? Thx.

Database changed
MariaDB [zm]> INSERT INTO `Config` VALUES (225,’ZM_PATH_ZMS’,’/cgi-bin-zm/nph-zms’,’string’,’/cgi-bin-zm/nph-zms’,’relative/path/to/somewhere’,'(?^:^((?:[^/].*)?)/?$)’,’ $1 ‘,’Web path to zms streaming server’,’ The ZoneMinder streaming server is required to send streamed images to your browser. It will be installed into the cgi-bin path given at configuration time. This option determines what the web path to the server is rather than the local path on your machine. Ordinarily the streaming server runs in parser-header mode however if you experience problems with streaming you can change this to non-parsed-header (nph) mode by changing \’zms\’ to \’nph-zms\’. ‘,’hidden’,0,NULL);
    '> ';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'to/somewhere’,'(?^:^((?:[^/].*)?)/?$)’,’ $1 ‘,’Web path to zms streami' at line 1
MariaDB [zm]>

It looks like she forgot a semicolon at the end of the first one (fixed)… but you caught that. Try again… the formatting was getting mixed up because it was not posted as preformatted text (apostrophes were being converted to right and left single quotes). Same problem with the PHP code. Sorry about that!

That did it. Thanks to you and your lovely wife :slight_smile:

I figured it was something to do with that, but got reading about curly quotes, smart quotes, apostrophes, etc, etc and figured I would ask for a little help!

1 Like

Just in case anyone’s interested, after a couple of years I have finally given up on zoneminder. A frustrating experience trying to recover video from an event did it for me. That and monitors occasionally stopping working for no bloody reason at all.

Quite hard to find linux alternatives - the other open source ones all have their own problems (mostly rubbish motion detection). I ended up with Xeoma.

Downsides: not open source, costs £, made by a Russian company nobody has ever heard of, has server/client model but client has to run their software rather than just accessing through the web, very few resources to help if you run into trouble.

Upsides: works reliably, decent support from company, has robust motion detection, takes up 1/3 the CPU and 1/10th the disk space of zoneminder, whilst recording in higher resolution and including audio. Client runs on just about anything. Integrates easily with OH2.

Happy to give more details if anyone is interested.

(Full disclosure: Xeoma apparently has the very naughty habit of giving free licenses to people in exchange for favourable reviews. I paid for my licence!)

1 Like

Looks like it doesn’t work for ZM 1.32.0 :confused:

This has been reported in Github too. I plan to look into another workaround, but I’ve been focused on JSR223-Jython modules.

@mr_eskildsen With the latest ESH changes to how the inbox works (I’m on build 1374), my openhab.log now is being spammed with messages like this every 10-15 seconds. Is there any way to disable discovery? Alternatively, would you consider reducing some of the INFO level logging to DEBUG?

I can change my logging level to WARN in the meantime, but that’s probably not a good long term solution.

2018-09-28 07:00:19.070 [INFO ] [discovery.ZoneMinderDiscoveryService] - [DISCOVERY]: Monitor with Id='1' and Name='AAAA' added to Inbox with ThingUID='zoneminder:monitor:zm:monitor-1'
2018-09-28 07:00:19.071 [INFO ] [discovery.ZoneMinderDiscoveryService] - [DISCOVERY]: Monitor with Id='2' and Name='BBBB' added to Inbox with ThingUID='zoneminder:monitor:zm:monitor-2'
2018-09-28 07:00:19.072 [INFO ] [discovery.ZoneMinderDiscoveryService] - [DISCOVERY]: Monitor with Id='3' and Name='CCCC' added to Inbox with ThingUID='zoneminder:monitor:zm:monitor-3'
2018-09-28 07:00:19.072 [INFO ] [discovery.ZoneMinderDiscoveryService] - [DISCOVERY]: Monitor with Id='4' and Name='DDDD' added to Inbox with ThingUID='zoneminder:monitor:zm:monitor-4'
2018-09-28 07:00:19.073 [INFO ] [discovery.ZoneMinderDiscoveryService] - [DISCOVERY]: Monitor with Id='7' and Name='EEEE' added to Inbox with ThingUID='zoneminder:monitor:zm:monitor-7'

Sounds like a good idea. Unfortunately I am bit stucked with the Binding. I haven’t looked at it lately, I hope to get the time to finish the pullrequest soon, this one would be obvious to handle

@mr_eskildsen Not sure of you are still maintaining the binding…

When forcing an alarm, I see this error in the log file.

2018-12-13 11:53:54.209 [ERROR] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]:  context='onTrippedForceAlarm' Exception occurred inTrippedForceAlarm() Exception='null'

In debug mode, this is what I see leading up to the error.

2018-12-13 11:53:53.100 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: Channel 'zoneminder:monitor:zm:monitor-3:force-alarm' in monitor '3' received command='ON'
2018-12-13 11:53:53.100 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: 'handleCommand' => CHANNEL_MONITOR_FORCE_ALARM: Command 'ON' received for monitor 'force-alarm'
2018-12-13 11:53:53.100 [DEBUG] [der.internal.state.MonitorThingState] - : Recalculate channel states based on Function: Function='Nodect' -> alarmState='false', recordingState='true'
2018-12-13 11:53:53.100 [DEBUG] [der.internal.state.MonitorThingState] - : Recalculate channel states based on Detailed State: DetailedState='IDLE' -> alarmState='false', recordingState='false'
2018-12-13 11:53:53.100 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: context='onStateChanged' channel='zoneminder:monitor:zm:monitor-3:force-alarm' - State changed to 'ON'
2018-12-13 11:53:53.100 [INFO ] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: Activate 'ForceAlarm' to 'ON' (Reason='openHAB', Timeout='60')
2018-12-13 11:53:53.101 [DEBUG] [r.handler.ZoneMinderBaseThingHandler] - [MONITOR-3]: context='startAlarmRefresh' Starting ALARM refresh...
2018-12-13 11:53:53.201 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: context='onFetchData' tag='monitorData' URL='http://hostname/zm/api/monitors/3.json' ResponseCode='200' ResponseMessage='OK'
2018-12-13 11:53:53.302 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: context='onFetchData' tag='detailedStatus' URL='http://hostname/zm/api/monitors/alarm/id:3/command:status.json' ResponseCode='200' ResponseMessage='OK'
2018-12-13 11:53:53.302 [DEBUG] [der.internal.state.MonitorThingState] - : Recalculate channel states based on Function: Function='Nodect' -> alarmState='false', recordingState='true'
2018-12-13 11:53:53.303 [DEBUG] [der.internal.state.MonitorThingState] - : Recalculate channel states based on Detailed State: DetailedState='PRE_ALARM' -> alarmState='true', recordingState='true'
2018-12-13 11:53:53.303 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: context='onStateChanged' channel='zoneminder:monitor:zm:monitor-3:recording' - State changed to 'ON'
2018-12-13 11:53:53.304 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: context='onStateChanged' channel='zoneminder:monitor:zm:monitor-3:detailed-status' - State changed to 'Pre-Alarm'
2018-12-13 11:53:54.107 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: context='onTrippedForceAlarm' Received forceAlarm for monitor 3
2018-12-13 11:53:54.135 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-7]: context='onFetchData' tag='monitorData' URL='http://hostname/zm/api/monitors/7.json' ResponseCode='200' ResponseMessage='OK'
2018-12-13 11:53:54.208 [DEBUG] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]: URL='http://hostname/zm/api/events/index/Id:3494.json?page=1' ResponseCode='200' ResponseMessage='OK'
2018-12-13 11:53:54.209 [ERROR] [andler.ZoneMinderThingMonitorHandler] - [MONITOR-3]:  context='onTrippedForceAlarm' Exception occurred inTrippedForceAlarm() Exception='null'

It also would be great to get these discovery messages set to debug mode to eliminate the log spamming.

Another thing I noticed…

If I try to change the ForceAlarm timeout config parameter to 0 to disable the timeout, the change is not applied. In fact, setting it to any value has no effect. It remains at the default of 60.

You’re not alone. I get these whenever the alarm channel is triggered. I don’t use force alarm.

2018-12-13 12:00:33.543 [ERROR] [org.openhab.binding.zoneminder.handler.ZoneMinderThingMonitorHandler] - [MONITOR-11]:  context='onTrippedForceAlarm' Exception occurred inTrippedForceAlarm() Exception='null'

Yeah, I started to use my motion detectors to trigger rules that use the force alarm channel to turn recording ON and OFF. I got disenchanted with the quality of Zoneminder’s motion detection. I know it’s quite powerful, but no amount of tuning and tweaking would prevent lighting changes, rain, snow, etc. from triggering the motion detection. I was starting to hate waking up to dozens of bogus events just because it rained heavily during the night. I suppose it can be done, but it’s beyond me. :roll_eyes:

If I could figure out how to pull the PR into my local openhab2-addons repo, I’d make a few changes to reduce the logging level, fix the config changes, and handle some of these exceptions differently.

I would be glad if somebody could help finishing the pull request. Right now I don’t have the time for finalising it. I also see the need for a major rework, first of all since ZM API seems to change, but also to make the Binding more clean.