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 :
200 after
insert :
244 after
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