Zoneminder plugin

Python and python framework

Moderator: leecollings

Post Reply
Daylights
Posts: 17
Joined: Monday 08 January 2018 10:55
Target OS: -
Domoticz version:
Contact:

Zoneminder plugin

Post 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!
dextm80
Posts: 117
Joined: Tuesday 24 October 2017 18:32
Target OS: Linux
Domoticz version: 4.10159
Contact:

Re: Zoneminder plugin

Post by dextm80 »

i follow, i'm already interested
Domoticz on AsRock j3455-ITX 8gb ram - Aeotec ZWave Usb Stick - RFLink 433Mhz
1x Fibaro Wall Plug
1x Fibaro Motion Sensor
x NeoCoolcam Wall Plug
Netatmo Weather Station - Netatmo Thermostat
Philips Hue Bridge
jannnfe
Posts: 30
Joined: Tuesday 30 January 2018 0:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:

Re: Zoneminder plugin

Post by jannnfe »

This would be very interesting.
I already forked a other Project to trigger Zoneminder Events in Domoticz:
https://github.com/jannnfe/zmeventserverDomoticz
Daylights
Posts: 17
Joined: Monday 08 January 2018 10:55
Target OS: -
Domoticz version:
Contact:

Re: Zoneminder plugin

Post 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?
Daylights
Posts: 17
Joined: Monday 08 January 2018 10:55
Target OS: -
Domoticz version:
Contact:

Re: Zoneminder plugin

Post 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 :)
peerkersezuuker
Posts: 70
Joined: Monday 14 December 2015 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Mierlo
Contact:

Re: Zoneminder plugin

Post 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
EldigoR
Posts: 41
Joined: Monday 12 October 2015 19:57
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Zoneminder plugin

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest