Page 1 of 1

Zoneminder plugin

Posted: Monday 29 October 2018 21:29
by Daylights
I found this project for integrating Zoneminder into Domoticz, but the developer seems to have abandoned it and I am very interested in getting this to work, so that I can for instance disable camera's when I'm at home:

https://github.com/sasu-drooz/Domoticz-ZoneMinder

Zoneminder makes use of a Json API of which zmNinja makes great use of. As of now the Domoticz plugin is recognised, logging in Domoticz is showing it does... 'something', although I don't see any devices or whatsoever being created in Domoticz or any logging on my Zoneminder server passing by. Mind you, I am no developer. I do understand a little of coding and I could reverse engineer this, but I wanted to make sure that the basis for Domoticz is good now and that it just needs more Zoneminder related things to it.

Can someone help me out pointing into the right direction? Thanks!

Re: Zoneminder plugin

Posted: Thursday 01 November 2018 17:56
by dextm80
i follow, i'm already interested

Re: Zoneminder plugin

Posted: Thursday 01 November 2018 18:09
by jannnfe
This would be very interesting.
I already forked a other Project to trigger Zoneminder Events in Domoticz:
https://github.com/jannnfe/zmeventserverDomoticz

Re: Zoneminder plugin

Posted: Sunday 04 November 2018 11:27
by Daylights
Well, I've managed to get it to work, but not entirely as expected. 3 Devices are created, but there are a few flaws in the buttons:

Zoneminder - Monitor 1 Function
None = (does nothing)
Monitor = None
Modect = Monitor
Record = Modect
Mocord = Record
Nodect = Mocord

Zoneminder - Status
Start = (does nothing)
Stop = Start
Restart = Stop

Zoneminder - Monitor 1 status
Enables a disabled monitor, but since the status in Domoticz is not changed, it cannot disable it.

Also logging doesn't work for the devices.

Looking at the API docs (https://zoneminder.readthedocs.io/en/stable/api.html) it looks like the right commands are used, but the button alignment is off?

I found out that the first button is actually level 0 in stead of 10. So I started with:

Code: Select all

if Unit == 1:
			if Level == 0:
				urlConnect = 'http://'+ Parameters["Mode1"] +'/index.php?username='+ Parameters["Username"] +'&password='+ Parameters["Password"] +'&action=login&view=console'
				url.call(urlConnect)
				urlConnect = 'http://'+ Parameters["Mode1"] +'/api/states/change/start.json'
				url.call(urlConnect)
			
			if Level == 10:
				urlConnect = 'http://'+ Parameters["Mode1"] +'/index.php?username='+ Parameters["Username"] +'&password='+ Parameters["Password"] +'&action=login&view=console'
				url.call(urlConnect)
				urlConnect = 'http://'+ Parameters["Mode1"] +'/api/states/change/stop.json'
				url.call(urlConnect)
			
			if Level == 20:
				urlConnect = 'http://'+ Parameters["Mode1"] +'/index.php?username='+ Parameters["Username"] +'&password='+ Parameters["Password"] +'&action=login&view=console'
				url.call(urlConnect)
				urlConnect = 'http://'+ Parameters["Mode1"] +'/api/states/change/restart.json'
				url.call(urlConnect)
Now the buttons are aligned. Next I am interested to know how Zoneminder can report back on the status/logging. Perhaps you know something about this jannnfe?

Re: Zoneminder plugin

Posted: Thursday 08 November 2018 9:53
by Daylights
Can somebody point me in the right direction on how to get the Zoneminder device status updatet on changes?
- Is better to let Zoneminder push the information of let Domoticz pull the information (if even possible?)
- Is MQTT the best approach, or are there easier options?

Thank you :)

Re: Zoneminder plugin

Posted: Tuesday 31 December 2019 11:00
by peerkersezuuker
Hi,
After some digging around I went the jannnfe way.
I am not a perl expert, but have a little understanding of programming and python, so I dug in.
I had setup a MQTT broker and connected it in domoticz (https://www.domoticz.com/wiki/MQTT) I only installed the mosquito and mosquito client tools.
Created an dummy switch named "Camera Motion Dummy" and noted the IDX of it.
The IDX comes in the zmeventnotification.ini in /etc/zm
After installing the zmeventnotification.pl provided by jannnfe, it did not work. The path to the ini was not correct in the script. After fixing that I noticed MQTT errors in the domoticz log when an event was sent from zoneminder via the MQTT broker.
Started to dig around a little in the zmeventnotification.pl script, enabled some logging I noticed that the IDX (as provided in the ini file) was sent as string, this should be an integer.
Also the zmeventnotification.pl was old.
I downloaded a new zmeventnotification.pl from https://github.com/pliablepixels/zmeventnotification and made the modifications which jannnfe provided.

( I can not post the whole script here as it exceeds the max characters)

added line :
106 after

Code: Select all

DEFAULT_SEND_EVENT_END_NOTIFICATION        => 'no',
insert :

Code: Select all

  DEFAULT_DOMOTICZ_DUMMY		                  => 0,
200 after

Code: Select all

my $prefix = "PARENT:";
insert :

Code: Select all

my $domoticz_dummy;
244 after

Code: Select all

"check-config" => \$check_config,
insert :

Code: Select all

  "domoticz_dummy=i" => \$domoticz_dummy,
391 after

Code: Select all

DEFAULT_EVENT_END_NOTIFY_ON_HOOK_SUCCESS
);
insert :

Code: Select all

$domoticz_dummy //= config_get_val($config, "domoticz", "domoticz_dummy", DEFAULT_DOMOTICZ_DUMMY);
563 after

Code: Select all

Picture password .............. ${\(present_or_not($picture_portal_password))}
insert :

Code: Select all

Idx ........................... ${\(value_or_undefined($domoticz_dummy))}
and modified the sub sendOverMQTTBroker from line 1123 to 1180
Spoiler: show

Code: Select all

sub sendOverMQTTBroker {

  my $alarm      = shift;
  my $ac         = shift;
  my $event_type = shift;
  my $resCode    = shift;

  my $json;
  my $mqtt;

# only remove if not removed before. If you are sending over multiple channels, it may have already been stripped
  $alarm->{Cause} = substr( $alarm->{Cause}, 4 )
    if ( !$keep_frame_match_type && $alarm->{Cause} =~ /^\[.\]/ );
  my $description =
    $alarm->{Name} . ":(" . $alarm->{EventId} . ") " . $alarm->{Cause};

  $description = "Ended:" . $description if ( $event_type eq "event_end" );

  if ($domoticz_dummy == 0)
    {
	  $json = encode_json(
	    { monitor   => $alarm->{MonitorId},
	      name      => $description,
	      state     => 'alarm',
	      eventid   => $alarm->{EventId},
	      hookvalue => $resCode,
	      eventtype => $event_type
	    }
	  );

	  # based on the library docs, if this fails, it will try and reconnect
	  # before the next message is sent (with a retry timer of 5 s)
	  $ac->{mqtt_conn}
	    ->publish( join( '/', 'zoneminder', $alarm->{MonitorId} ) => $json );

	# avoid connection drops - see https://github.com/pliablepixels/zmeventnotification/issues/191
	  $ac->{mqtt_conn}->disconnect() if $mqtt_close_on_send;
    }
    else
    {
        $json = encode_json ({
                idx => int($domoticz_dummy),
                nvalue => $alarm->{EventId},
                svalue => $alarm->{MonitorId},
                Battery => 57,
                RSSI => 6
            });

        printInfo ("Domoticz being sent is: $json");
        if (defined $mqtt_username && defined $mqtt_password){
            $mqtt = Net::MQTT::Simple::Auth->new($mqtt_server, $mqtt_username, $mqtt_password);
        }
        else{
            $mqtt = Net::MQTT::Simple->new($mqtt_server);
        }
        $mqtt->publish(join('/','domoticz','in') => $json);
    }
}
Now when an event is raised by an camera via zoneminder the dummy switch is set on with the s_value = monitor-id an n_value is event-id.
(in the new script only the monitor id is sent, so only 1 or 2 or .. and not Monitor1 and so on)
I have a python script (but it could be easily an other event script) which reacts on the switch on command, it reads the s_value and n_value and does some actions.

thanks to jannnfe

Hope someone else can profit from this post.

Regards
Peer

Re: Zoneminder plugin

Posted: Thursday 09 January 2020 11:03
by EldigoR
peerkersezuuker wrote: Tuesday 31 December 2019 11:00 Hope someone else can profit from this post.
Just what i needed.
Thank you very much!