AlarmLocal on NVR
psyciknz opened this issue · 49 comments
Ok, I just tried and it works but not as I like.
I'm trying the NVR with one camera only and CameraEvents connects to it and to my mqtt broker.
But when I tryed a input alarm on the NVR I saw these command on mqtt:
CameraEvents/CAM-05/NVR = AlarmLocal
Now two things that I don't know:
- why the NVR is listed under the camera name?
- the alarm doesn't turn off when I close the alarm connected to the NVR input (but I see in the NVR log that alarm goes off)
This becomes useless because my domotic hub knows when an alarm starts but not when it ends.
Can you help me?
My config reflects your example: I haven't listed the camera channels and I don't add the snapshotoffset
Originally posted by @valepe in #4 (comment)
Little update. I'm using MQTT Explorer and I disconnect it then reconnected and all alarm are disappeared. Is this the behavior?
If yes, how can I integrate it in Home Assistant so it can know when an alarm is on and when is off?
But remains the issue of NVR under my camera name. What happens when I'll connect to the NVR all other cameras?
Little update. I'm using MQTT Explorer and I disconnect it then reconnected and all alarm are disappeared. Is this the behavior?
If yes, how can I integrate it in Home Assistant so it can know when an alarm is on and when is off?
I'll start with this one.
Unsure if I have retain turned on for the message. I'm assuming by what you say I don't. But if Home assistant is looking at it, it should hold the last state until it gets a change (ie when cameraeveents restarts and an alarm is posted. If no alarm is posted, then HA will continue to display the last state,
Ok, I just tried and it works but not as I like.
I'm trying the NVR with one camera only and CameraEvents connects to it and to my mqtt broker.
But when I tryed a input alarm on the NVR I saw these command on mqtt:
CameraEvents/CAM-05/NVR = AlarmLocal
Now two things that I don't know:
- why the NVR is listed under the camera name?
- the alarm doesn't turn off when I close the alarm connected to the NVR input (but I see in the NVR log that alarm goes off)
This becomes useless because my domotic hub knows when an alarm starts but not when it ends.Can you help me?
My config reflects your example: I haven't listed the camera channels and I don't add the snapshotoffset
Techinically if you only have one camera, and it's channel 1 (or 0), you don't tell to tell the "camera" it's an NVR. Thats said, I've not dealt with AlarmLocal as a state....is this an external alarm connected to a camera?
How would you expect to see it?
CameraEvents/CAM-05/AlarmLocal?
self.client.publish(self.basetopic +"/" + Alarm["channel"] + "/" + Alarm["name"],Alarm["Code"])
This could be it, which is part of a fall through of events, which looks like it's posted the channel name (CAM-05) then the name of the device (NVR - from the config.ini).
Where as an IVS event is
self.client.publish(self.basetopic +"/IVS/" + Alarm["channel"] ,regionText)
To be consistent, the fall through should be:
self.client.publish(self.basetopic +"/" + Alarm["Code"] + " /" + Alarm["channel"] ,true|false)
Little update. I'm using MQTT Explorer and I disconnect it then reconnected and all alarm are disappeared. Is this the behavior?
If yes, how can I integrate it in Home Assistant so it can know when an alarm is on and when is off?I'll start with this one.
Unsure if I have retain turned on for the message. I'm assuming by what you say I don't. But if Home assistant is looking at it, it should hold the last state until it gets a change (ie when cameraeveents restarts and an alarm is posted. If no alarm is posted, then HA will continue to display the last state,
Is It possible to have an alarm on and an alarm off topics? I saw in the log that cameraevents receives the start and stop messages
Ok, I just tried and it works but not as I like.
I'm trying the NVR with one camera only and CameraEvents connects to it and to my mqtt broker.
But when I tryed a input alarm on the NVR I saw these command on mqtt:
CameraEvents/CAM-05/NVR = AlarmLocal
Now two things that I don't know:
- why the NVR is listed under the camera name?
- the alarm doesn't turn off when I close the alarm connected to the NVR input (but I see in the NVR log that alarm goes off)
This becomes useless because my domotic hub knows when an alarm starts but not when it ends.Can you help me?
My config reflects your example: I haven't listed the camera channels and I don't add the snapshotoffsetTechinically if you only have one camera, and it's channel 1 (or 0), you don't tell to tell the "camera" it's an NVR. Thats said, I've not dealt with AlarmLocal as a state....is this an external alarm connected to a camera?
How would you expect to see it?
CameraEvents/CAM-05/AlarmLocal?
No, this alarm is connected to alarm inputs of the NVR (not to the camera) so I'm expect to see a topic like CameraEvents/NVR/AlarmLocal and then the number of the alarm input (my NVR has 4 inputs and 2 outputs) and the start and stop states
Hmm any ideas how I would similate that, to look at it? Do I just need to jumper (make a circuit) the alarm input to trigger it?
Can you post this as a new issue. I think the mqtt authentication is done.
Hmm any ideas how I would similate that, to look at it? Do I just need to jumper (make a circuit) the alarm input to trigger it?
Yes, I wired so on my NVR input then I enabled the alarm setting the NO (normally open) or the NC (normally closed) type.
I add an extract of my log if it can help you.
The lastest (time sequence) elements are the start and stop of tripwire alarm started on the camera and routed by the nvr.
The first two elements are the start and stop of the input alarm started on the nvr itself.
I can't try an input alarm on camera because mines haven't such feature.
I might be able to do it off this. I’ll make it like a video motion event.
2020-02-12 22:53:23,stdout,"2020-02-12 22:53:23,836 - main - INFO - dahua_event_received: NVR Index: CAM-05 Code: AlarmLocal
2020-02-12 22:53:23,stdout,
2020-02-12 22:53:23,stdout,
2020-02-12 22:53:23,stdout,Code=AlarmLocal;action=Stop;index=0
2020-02-12 22:53:23,stdout,
2020-02-12 22:53:23,stdout,Content-Length:35
2020-02-12 22:53:23,stdout,Content-Type: text/plain
2020-02-12 22:53:23,stdout,"2020-02-12 22:53:23,836 - main - DEBUG - [NVR]: --myboundary
2020-02-12 22:53:16,stdout,"2020-02-12
In your log I don’t see a action=start, which I use the start the event.
I might be able to do it off this. I’ll make it like a video motion event.
2020-02-12 22:53:23,stdout,"2020-02-12 22:53:23,836 - main - INFO - dahua_event_received: NVR Index: CAM-05 Code: AlarmLocal
2020-02-12 22:53:23,stdout,
2020-02-12 22:53:23,stdout,
2020-02-12 22:53:23,stdout,Code=AlarmLocal;action=Stop;index=0
2020-02-12 22:53:23,stdout,
2020-02-12 22:53:23,stdout,Content-Length:35
2020-02-12 22:53:23,stdout,Content-Type: text/plain
2020-02-12 22:53:23,stdout,"2020-02-12 22:53:23,836 - main - DEBUG - [NVR]: --myboundary
2020-02-12 22:53:16,stdout,"2020-02-12In your log I don’t see a action=start, which I use the start the event.
It is at the bottom of the file:
2020-02-12 22:53:16,stdout,Code=AlarmLocal;action=Start;index=0
Is it that do you search?
I haven't tryed but I suppose that the index number is the number of the triggered alarm input.
My nvr has four inputs so I expected a index range from 0 to 3.
If you want thiis evening I'll try it attaching a second switch to trigger the second alarm input.
I might be able to do it off this. I’ll make it like a video motion event.
So Video Modion events have a start and stop mqtt topics?
Good for alarms but for IVS events? Can you make them like video motion so?
Yeah, so should trigger something like CameraEvents/AlarmLocal/CAM-05 payload true or false or on off. Whatever I have in videomotion events. Then in home assistant you can have a switch, or something to report on it.
Yeah, so should trigger something like CameraEvents/AlarmLocal/CAM-05 payload true or false or on off. Whatever I have in videomotion events. Then in home assistant you can have a switch, or something to report on it.
Good!
So it will like CameraEvents/AlarmLocal/CAM-05 if generated by camera and CameraEvents/AlarmLocal/NVR if generated by NVR?
Hmm that line
,Code=AlarmLocal;action=Start;index=0
Has a channel index. So that would try to link to a channel. Ie cam-05, not the nvr.
Hmm that line
,Code=AlarmLocal;action=Start;index=0
Has a channel index. So that would try to link to a channel. Ie cam-05, not the nvr.
I suppose that, for API compatibility, they are using the index of camera channel for reporting the alarm input number.
I think that because the alarm is hardware connected to the NVR not to the camera
Hmm that line
,Code=AlarmLocal;action=Start;index=0
Has a channel index. So that would try to link to a channel. Ie cam-05, not the nvr.
Or maybe the index 0 is for the NVR itself and from 1 for the cameras?
I haven't cameras with alarm input to try. My NVR has the latest firmware installed (black GUI).
Another thing I found on the log:
2020-02-12 21:57:04,stdout,"2020-02-12 21:57:04,453 - __main__ - INFO - Snapshot Url: http://IP_NUMBER:80/cgi-bin/snapshot.cgi?channel=0
Does this line should match a mqtt publish of a snapshot?
If yes, some issues with channel=0 because on the Image topic the base64 snapshot (triggered by IVS) was only of 20 or 30 chars. Too much few for a 2MP image.
I will try adding the snapshotoffset=1 in the config and see if something change
Found that on Dahua API:
`< handlerName> can be one of below four formats:
- Alarm[alarm channel].EventHandler
- MotionDetect[video channel]. EventHandler
- BlindDetect[video channel]. EventHandler
- LossDetect[video channel]. EventHandler
Example URL:
http:///cgi-bin/configManager.cgi?action=getConfig&name=Alarm[0].EventHandler
can get EventHandler settings of alarm channel 0. `
Link to API v1.67 pdf:
http://www.telecamera.ru/bitrix/components/bitrix/forum.interface/show_file.php?fid=1022477&action=download
Ok. So that mean it should be cameraevents/alarmlocal/0 or 1 with on/off
Since it’s not the camera channel.
Ok. So that mean it should be cameraevents/alarmlocal/0 or 1 with on/off
Since it’s not the camera channel.
Exactly, 0 - 1 - ... - X are the alarm input indexes. My NVR has only four inputs but other models can have up to 16 inputs.
Is it possible to drive the alarm outputs also?
Sorry, I made a mistake. Output alarms can't be driven directly but you can drive the alarm inputs remotely with netalarm function. Then you can set an input to drive the output.
I found this page about netalarm:
https://gist.github.com/hdo/598f56a23d360164c3fbf60012902a88
Do you think that is it possible to add this functionality?
So looking at this now, I'm not sure pulling an image or going to work, since the alarm channel does not relate to a camera.
So I will remove that. If want a snapshot, I think you can send a
CameraEvents/[index]/picture
with any payload (I don't look at it).
I think it will get the index wrong - ie should start at 1 and it doesn't use the snapshot offset.
I've pushed a new branch alarm-local which will add the alarm local message with a payload on ON and OFF when an event is received. I will be posted to:
CameraEvents/AlarmLocal/
There is potential at the moment if the Alarm local index is greater than the number of cameras that it will crash.
EDIT: just confirmed, it doesn't care, and will just post any index number of any alarm, regardless of the number of cameras.
Thank you!
How can I test it? I have it running in a docker container of my nas.
Or can you build a container (I don't know how to do that)?
Thank you!
How can I test it? I have it running in a docker container of my nas.
Or can you build a container (I don't know how to do that)?
Ok, yes. Can build one tomorrow.
Thanks a lot!
See if this works for you
docker pull psyciknz/cameraevents:alarm-local-latest
I had issues with travis tests, which I fixed today...and wjhile I was at it, got automated travis builds to docker (with multiarchitecture)
It doesn't work :(
The container reboots continuously. This is the error in log file:
`2020-02-15 10:07:22,stdout,ModuleNotFoundError: No module named 'requests'
2020-02-15 10:07:22,stdout, import requests
2020-02-15 10:07:22,stdout," File "CameraEvents.py", line 12, in <module>
"
2020-02-15 10:07:22,stdout,Traceback (most recent call last):
`
Cool, that was a good teaching lesson for me, so was able to add a docker test on the newly built image....and then i fixed the issue with the mossing requests. There's a new image to pull now.
I'll have to figure out the build when the repo is tagged, but it's running in this branch ok now.
It's online but nothing else.
It doesn't report IVS and alarm input.
Two events should be there, first a tripwire and then an alarm input.
This is the log:
`psyciknz-cameraevents
date,stream,content
2020-02-16 07:26:43,stdout,"2020-02-16 07:26:43,012 - main - DEBUG - Heartbeat: 2020-02-16 07:26:43.011918
"
2020-02-16 07:25:52,stdout,"2020-02-16 07:25:52,871 - main - DEBUG - Heartbeat: 2020-02-16 07:25:52.871832
"
2020-02-16 07:25:04,stdout,"2020-02-16 07:25:04,172 - main - DEBUG - [NVR] OnDisconnect(Success)
"
2020-02-16 07:25:02,stdout,"2020-02-16 07:25:02,717 - main - DEBUG - Heartbeat: 2020-02-16 07:25:02.716890
"
2020-02-16 07:24:58,stdout,"2020-02-16 07:24:58,905 - main - DEBUG - [NVR] OnDisconnect(Failed writing body (0 != 100) (23))
"
2020-02-16 07:24:58,stdout,AttributeError: 'bytes' object has no attribute 'encode'
2020-02-16 07:24:58,stdout," Data = data.encode().decode("utf-8", errors="ignore")
"
2020-02-16 07:24:58,stdout," File "CameraEvents.py", line 388, in OnReceive
"
2020-02-16 07:24:58,stdout,Traceback (most recent call last):
2020-02-16 07:24:31,stdout,"2020-02-16 07:24:31,572 - main - DEBUG - [NVR] OnDisconnect(Success)
"
2020-02-16 07:24:26,stdout,"2020-02-16 07:24:26,306 - main - DEBUG - [NVR] OnDisconnect(Failed writing body (0 != 101) (23))
"
2020-02-16 07:24:26,stdout,AttributeError: 'bytes' object has no attribute 'encode'
2020-02-16 07:24:26,stdout," Data = data.encode().decode("utf-8", errors="ignore")
"
2020-02-16 07:24:26,stdout," File "CameraEvents.py", line 388, in OnReceive
"
2020-02-16 07:24:26,stdout,Traceback (most recent call last):
2020-02-16 07:24:12,stdout,"2020-02-16 07:24:12,563 - main - DEBUG - Heartbeat: 2020-02-16 07:24:12.562919
"
2020-02-16 07:24:00,stdout,"2020-02-16 07:24:00,679 - main - DEBUG - [NVR] OnDisconnect(Success)
"
2020-02-16 07:23:55,stdout,"2020-02-16 07:23:55,513 - main - DEBUG - [NVR] OnDisconnect(Failed writing body (0 != 928) (23))
"
2020-02-16 07:23:55,stdout,AttributeError: 'bytes' object has no attribute 'encode'
2020-02-16 07:23:55,stdout," Data = data.encode().decode("utf-8", errors="ignore")
"
2020-02-16 07:23:55,stdout," File "CameraEvents.py", line 388, in OnReceive
"
2020-02-16 07:23:55,stdout,Traceback (most recent call last):
2020-02-16 07:23:22,stdout,"2020-02-16 07:23:22,422 - main - DEBUG - Heartbeat: 2020-02-16 07:23:22.422608
"
2020-02-16 07:22:32,stdout,"2020-02-16 07:22:32,282 - main - DEBUG - Heartbeat: 2020-02-16 07:22:32.282435
"
2020-02-16 07:21:42,stdout,"2020-02-16 07:21:42,134 - main - DEBUG - Heartbeat: 2020-02-16 07:21:42.134327
"
2020-02-16 07:20:52,stdout,"2020-02-16 07:20:52,000 - main - DEBUG - Heartbeat: 2020-02-16 07:20:52.000056
"
2020-02-16 07:20:01,stdout,"2020-02-16 07:20:01,849 - main - DEBUG - Heartbeat: 2020-02-16 07:20:01.848941
"
2020-02-16 07:19:11,stdout,"2020-02-16 07:19:11,709 - main - DEBUG - Heartbeat: 2020-02-16 07:19:11.709434
"
2020-02-16 07:18:21,stdout,"2020-02-16 07:18:21,560 - main - DEBUG - Heartbeat: 2020-02-16 07:18:21.560570
"
2020-02-16 07:17:31,stdout,"2020-02-16 07:17:31,418 - main - DEBUG - Heartbeat: 2020-02-16 07:17:31.418445
"
2020-02-16 07:16:41,stdout,"2020-02-16 07:16:41,217 - main - DEBUG - Heartbeat: 2020-02-16 07:16:41.217579
"
2020-02-16 07:15:51,stdout,"2020-02-16 07:15:51,068 - main - DEBUG - Heartbeat: 2020-02-16 07:15:51.068084
"
2020-02-16 07:15:00,stdout,"2020-02-16 07:15:00,927 - main - INFO - Connected to MQTT OK Returned code=0
"
2020-02-16 07:15:00,stdout,"2020-02-16 07:15:00,905 - main - DEBUG - Starting MQTT Loop
"
2020-02-16 07:15:00,stdout,"2020-02-16 07:15:00,904 - main - DEBUG - Connecting to MQTT Broker
"
2020-02-16 07:15:00,stdout,"2020-02-16 07:15:00,903 - main - DEBUG - Added Dahua device at: http://IP_NUMBER:80/cgi-bin/eventManager.cgi?action=attach&codes=%5BVideoMotion,CrossLineDetection,AlarmLocal,VideoLoss,VideoBlind%5D
"
2020-02-16 07:15:00,stdout,"2020-02-16 07:15:00,903 - main - INFO - Created Data Device: NVR
"
2020-02-16 07:15:00,stdout,"2020-02-16 07:15:00,837 - main - DEBUG - Device NVR Getting channel ids: http://IP_NUMBER:80/cgi-bin/configManager.cgi?action=getConfig&name=ChannelTitle
"
2020-02-16 07:15:00,stdout,"2020-02-16 07:15:00,834 - main - INFO - Loading config
"`
Sorry about that, something introduced in the tests caused that. New build is coming now (21:21) will take about ten mins.
And I've just ran it here to verify it works.
Thnaks, it works now.
But there's a strange behavior on AlarmLocal start event. It fires a camera motion detector with attached snapshot (using the same alarm index for camera channel but snapshot string is corrupted, can't be decoded) also. Why?
Thnaks, it works now.
But there's a strange behavior on AlarmLocal start event. It fires a camera motion detector with attached snapshot (using the same alarm index for camera channel but snapshot string is corrupted, can't be decoded) also. Why?
Snapshot seems corrupted because It start with double quotes but ends with nothing. Probably the full topic is truncated
Thnaks, it works now.
But there's a strange behavior on AlarmLocal start event. It fires a camera motion detector with attached snapshot (using the same alarm index for camera channel but snapshot string is corrupted, can't be decoded) also. Why?Snapshot seems corrupted because It start with double quotes but ends with nothing. Probably the full topic is truncated
Yeah it did, I copied the code block fo the video motion. Which as above was not how I thought it should run. In my mind, as this isn't attached to a physical camera, it shouldn't trigger a snapshot, so I'll remove the download and post of an image. So now it should just post an AlarmLocal ON and OFF.
Just committing, and it should make a new build shortly.
It works like a charm! Thank you very much.
I tried also the IVS event and all good but the topic, as already said, is corrupted:
{"message": "IVS: CAM-05: CrossLineDetection With Human in LeftToRight direction for REGOLA2 region", "imagebase64": "EXTRA_LONG_BASE64_CHARACTERS
As you can see the image ends without quotes and without the ending brace.
I'm not seeing this. Yes sometimes the image is not there, but are you looking at it in something? Or saving the image with something and seeing it corrupted? If you're using an mqtt tool it may not show it all, at it's about 1-3mb of data for the image.
I'm not seeing this. Yes sometimes the image is not there, but are you looking at it in something? Or saving the image with something and seeing it corrupted? If you're using an mqtt tool it may not show it all, at it's about 1-3mb of data for the image.
I copied the image string and tryed to convert with an online tool but, as you pointed out, it can be MQTT Explorer that truncates the topics.
Hi psyciknz, I am again.
I was focused on AlarmLocal and it works fine but I noticed a "wrong" behavior on IVS alerts.
CameraEvents reports the start event from various cams for tripwire alerts.
But it never publish the clear event even if it receives the stop action (example for CAM 4):
Code=CrossLineDetection;action=Stop;index=3;data={
Can you look at this?
I'm looking at your code but something that I don't understand:
In all events I see two lines with publish command: one for Alarm["Code"] and one for Alarm["channel"].
But as you can see in my previous screenshot I don't see the Alarm["channel"] node for AlarmLocal events (I see only the Alarm["Code"] node) and I don't see the ON and the OFF publish for IVS events but only the snapshot row.
Pull the latest, updated about 1-2 days ago. I changed how the event notifications work for IVS and motion events. And now they do publish a close.
IVS events do trigger a lot more than a motion event. So I’m not 100% happy with that
Regaring the alarm local, as the alarm local is an nvr event and not tied to a camera, it does not make sense to try and attach it to a camera. Also if you only have 4 alarm locals and 16 camera channels, it will never work.
So in your alarm local (1) config, you trigger a Recording of cam 02 and 03?
Does that trigger an event on the cameras? What do the logs say on the NVR web site? what type of event does it trigger? Is suspect none.
If it's just start recording because xyz event has happened, then surely thats like having cam 02 with a videomotion event also recording cam 03. Cam03 does not get any events triggered as that is the result of an event, not the cause.
What version of the docker image are you running? Actually i need to make that a retained topic.
Ok, just today I've pushed a new image that will post the alert state of devices and the code version as retained events. Current version is 0.2.0. Can you make sure you're on that, and then check the CameraEvents/<camera>/event
is reflecting ON and OFF with IVS and VideoMotion events.
Hmmm, this might be the confusion:
self.client.publish(self.basetopic +"/" + Alarm["Code"] + "/" + str(index) ,"ON")
self.client.publish(self.basetopic +"/" + Alarm["channel"] + "/event" ,"ON")
Is published for an AlarmLocal. I'm not sure I should be doing this.....the Alarm["channel"].
Ok, just today I've pushed a new image that will post the alert state of devices and the code version as retained events. Current version is 0.2.0. Can you make sure you're on that, and then check the
CameraEvents/<camera>/event
is reflecting ON and OFF with IVS and VideoMotion events.
I'm on 0.2.0 and no alarm input is setup to trigger cam recordings.
Yes, all work fine with tripwire events: image snapshot, ON and OFF.
But AlarmLocal publish an event under AlarmLocal (right) but also under cam name (wrong).
self.client.publish(self.basetopic +"/" + Alarm["Code"] + "/" + str(index) ,"ON") self.client.publish(self.basetopic +"/" + Alarm["channel"] + "/event" ,"ON")
Is published for an AlarmLocal. I'm not sure I should be doing this.....the Alarm["channel"].
I'm agree with you, the second row shouldn't be there
OK. I'll make a 0.2.1 and push a new version dropping
self.client.publish(self.basetopic +"/" + Alarm["channel"] + "/event" ,"ON")
It works. Thank you for your help