Could you pull updated app from my repository (here) and try setting ignore_ssl: True
to configuration file?
Great work, @algirdasc! I am experiencing some issues with parsing the JSON payload, maybe because it contains a lot of “\n”?
{"code": "CrossRegionDetection", "action": "Stop", "index": "2", "data": "{\n \"Action\" : \"Appear\",\n \"Class\" : \"Normal\",\n \"CountInGroup\" : 1,\n \"DetectRegion\" : [\n [ 346, 2473 ],\n [ 2512, 1092 ],\n [ 7754, 2249 ],\n [ 7827, 4722 ],\n [ 8045, 5204 ],\n [ 3822, 6681 ],\n [ 8100, 7773 ],\n [ 8082, 8063 ],\n [ 36, 8127 ],\n [ 55, 5332 ],\n [ 419, 5300 ]\n ],\n \"EventSeq\" : 84,\n \"Extension\" : {\n \"EventLongID\" : \"0220190507170948003539900000\"\n },\n \"FrameSequence\" : 21637811,\n \"GroupID\" : 84,\n \"IndexInGroup\" : 0,\n \"LocaleTime\" : \"2019-05-07 17:09:51\",\n \"Mark\" : 0,\n \"Name\" : \"Voorkant\",\n \"Object\" : {\n \"Action\" : \"Appear\",\n \"BoundingBox\" : [ 5840, 2400, 6432, 4448 ],\n \"Center\" : [ 6136, 3424 ],\n \"Confidence\" : 0,\n \"FrameSequence\" : 0,\n \"LowerBodyColor\" : [ 0, 0, 0, 0 ],\n \"MainColor\" : [ 0, 0, 0, 0 ],\n \"ObjectID\" : 840,\n \"ObjectType\" : \"Human\",\n \"RelativeID\" : 0,\n \"Source\" : 0.0,\n \"Speed\" : 0,\n \"SpeedTypeInternal\" : 0\n },\n \"PTS\" : 43814814030.0,\n \"RuleId\" : 1,\n \"Sequence\" : 0,\n \"Source\" : 55530608.0,\n \"Track\" : null,\n \"UTC\" : 1557248988,\n \"UTCMS\" : 273\n}\n"}
Could you please specify what issues are you experiencing? A lot of “\n” might be from printing debuging info, which should be ignored and JSON should be parsed anyway.
I would like to parse out the “Name” field. I use dev-template to test my template.
Template:
{% set my_test_json = {"code": "CrossRegionDetection", "action": "Stop", "index": "2", "data": "{\n \"Action\" : \"Appear\",\n \"Class\" : \"Normal\",\n \"CountInGroup\" : 1,\n \"DetectRegion\" : [\n [ 346, 2473 ],\n [ 2512, 1092 ],\n [ 7754, 2249 ],\n [ 7827, 4722 ],\n [ 8045, 5204 ],\n [ 3822, 6681 ],\n [ 8100, 7773 ],\n [ 8082, 8063 ],\n [ 36, 8127 ],\n [ 55, 5332 ],\n [ 419, 5300 ]\n ],\n \"EventSeq\" : 56,\n \"Extension\" : {\n \"EventLongID\" : \"0220190506205857002629900000\"\n },\n \"FrameSequence\" : 19821373,\n \"GroupID\" : 56,\n \"IndexInGroup\" : 0,\n \"LocaleTime\" : \"2019-05-06 20:59:00\",\n \"Mark\" : 0,\n \"Name\" : \"Voorkant\",\n \"Object\" : {\n \"Action\" : \"Appear\",\n \"BoundingBox\" : [ 1744, 4040, 2080, 4440 ],\n \"Center\" : [ 1912, 4240 ],\n \"Confidence\" : 0,\n \"FrameSequence\" : 0,\n \"LowerBodyColor\" : [ 0, 0, 0, 0 ],\n \"MainColor\" : [ 0, 0, 0, 0 ],\n \"ObjectID\" : 1460,\n \"ObjectType\" : \"Human\",\n \"RelativeID\" : 0,\n \"Source\" : 0.0,\n \"Speed\" : 0,\n \"SpeedTypeInternal\" : 0\n },\n \"PTS\" : 43742164310.0,\n \"RuleId\" : 1,\n \"Sequence\" : 0,\n \"Source\" : 55530608.0,\n \"Track\" : null,\n \"UTC\" : 1557176337,\n \"UTCMS\" : 525\n}\n"} %}
{{ my_test_json.data }}
Then the result is:
{
"Action" : "Appear",
"Class" : "Normal",
"CountInGroup" : 1,
"DetectRegion" : [
[ 346, 2473 ],
[ 2512, 1092 ],
[ 7754, 2249 ],
[ 7827, 4722 ],
[ 8045, 5204 ],
[ 3822, 6681 ],
[ 8100, 7773 ],
[ 8082, 8063 ],
[ 36, 8127 ],
[ 55, 5332 ],
[ 419, 5300 ]
],
"EventSeq" : 56,
"Extension" : {
"EventLongID" : "0220190506205857002629900000"
},
"FrameSequence" : 19821373,
"GroupID" : 56,
"IndexInGroup" : 0,
"LocaleTime" : "2019-05-06 20:59:00",
"Mark" : 0,
"Name" : "Voorkant",
"Object" : {
"Action" : "Appear",
"BoundingBox" : [ 1744, 4040, 2080, 4440 ],
"Center" : [ 1912, 4240 ],
"Confidence" : 0,
"FrameSequence" : 0,
"LowerBodyColor" : [ 0, 0, 0, 0 ],
"MainColor" : [ 0, 0, 0, 0 ],
"ObjectID" : 1460,
"ObjectType" : "Human",
"RelativeID" : 0,
"Source" : 0.0,
"Speed" : 0,
"SpeedTypeInternal" : 0
},
"PTS" : 43742164310.0,
"RuleId" : 1,
"Sequence" : 0,
"Source" : 55530608.0,
"Track" : null,
"UTC" : 1557176337,
"UTCMS" : 525
}
This however does not provide any result:
{{ my_test_json.data.Name }}
Yes, I see. The problem is that my_test_json.data
is not parsed to JSON object, but to string instead. I’ve updated app, please update and let me know if the problem is resolved.
Great work, I have problem getting AudioAnomaly: input abnormal to work even when i see on Onvif Device Manager that there are events. Anyone got Audio Detected to work?
DahuaMQTT:
class: DahuaMQTT
module: dahua_mqtt
cameras:
- host: 192.168.1.113
port: 80
user: !secret living_room_camera_username
pass: !secret living_room_camera_passwd
topic: cameras/living_room/
events: VideoMotion,CrossLineDetection,CrossRegionDetection,LeftDetection,TakenAwayDetection,FaceDetection,AudioMutation,AudioAnomaly,VideoBlind,LeftDetection,MoveDetection
eventCode can be any one of the standard codes defined in DHIIF, or “All”.
All means all kinds of the eventcode.
eventcode include:
VideoMotion: motion detection event
VideoLoss: video loss detection event
VideoBlind: video blind detection event.
AlarmLocal: alarm detection event.
CrossLineDetection: tripwire event
CrossRegionDetection: intrusion event
LeftDetection: abandoned object detection
TakenAwayDetection: missing object detection
VideoAbnormalDetection: scene change event
FaceDetection: face detect event
AudioMutation: intensity change
AudioAnomaly: input abnormal
VideoUnFocus: defocus detect event
WanderDetection: loitering detection event
RioterDetection: People Gathering event
ParkingDetection: parking detection event
MoveDetection: fast moving event
StorageNotExist: storage not exist event.
StorageFailure: storage failure event.
StorageLowSpace: storage low space event.
AlarmOutput: alarm output event.
MDResult: motion detection data reporting event. The motion detect window contains 18 rows
and 22 columns. The event info contains motion detect data with mask of every row.
HeatImagingTemper: temperature alarm event
Yes, has been resolved. Thanks!
A great way to troubleshot is
use the command that makes a log
wget 'http://USERNAME:PASSWORD@IP/cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion,VideoLoss,VideoBlind,AlarmLocal,CrossLineDetection,CrossRegionDetection,LeftDetection,TakenAwayDetection,VideoAbnormalDetection,FaceDetection,AudioMutation,AudioAnomaly,VideoUnFocus,WanderDetection,RioterDetection,ParkingDetection,MoveDetection,MDResult]' -O events.log
I get an error with that command. I’m using username=admin & password=somethingsomething
Error Invalid Authority!
Does anyone have this working with a Dahua NVR?
I have just stumbled across this by accident whilst looking for something else.
I have actually setup MotionEye JUST to capture motion detection events, hitting a webhook which in turn sets a binary sensor in HA - but it would be great to remove the extra complexity and load of running motioneye!
Read few post above, there was someone, who had issues with NVR, but it was solved and working.
Sorry - I shuld have clarified.
I have it working, and I am getting data posted to MQTT
Am i correct to assume the index value relates to the camera channel ?
ie index 0 is D1 and so on (it seems to be the case!)
Assuming that is the case, i made a change to add the index to the topic
ie cameras/1/VideoMotion gets hit when the payload is {“code”: “VideoMotion”, “action”: “Start”, “index”: “1”}
To me that makes it easier to have a simple on/off binary sensor for movement in HA.
just wondering, does the script at the top allow you to differentiate between multiple different events on the same camera.
like can i have an automation for motion and a different automation for face detection?
Yes, you can. You can provide multiple events to app. You’ll receive different JSON payloads which you need to parse and adapt to your needs.
I have managed to install AppDaemon and the DahuaMQTT app. The app seems to connect to the Dahua IP camera, but I’m receiving the below error once an event is triggered by the camera.
2019-08-02 22:05:36.847211 INFO DahuaMQTT: [192.168.1.108] Publishing MQTT. topic=cameras/1, payload={“code”: “VideoMotion”, “action”: “Stop”, “index”: “0”}
2019-08-02 22:05:36.880411 INFO DahuaMQTT: Failed to parse: 400 Client Error: Bad Request for url: http://hassio/homeassistant/api/services/mqtt/publish
How should I fix the bad url requests? I’m on Hassio and Raspberry PI and over https if that makes a difference.
Is your HASS <-> AppDaemon
connection configured properly?
I am seeing this over and over again in the log. Any ideas?
2019-08-06 15:09:51.083151 INFO DahuaMQTT: [192.168.0.104] OnDisconnect(Success [])
2019-08-06 15:09:51.160786 INFO DahuaMQTT: [192.168.0.104] OnDisconnect(Success [])
2019-08-06 15:09:56.093670 INFO DahuaMQTT: [192.168.0.104] OnDisconnect(Success [])
Also, when I run the wget command below to troubleshoot, I see the motion events occur, but they do not trigger an MQTT message in Home Assistant.
wget ‘http://USERNAME:PASSWORD@IP/cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion]’ -O events.log
I tried to Google, but I couldn’t find what is missing from configuration. I couldn’t find any instructions on how the set this up using https. Is there a way to configure this so that it doesn’t go over the internet? I would prefer to stay on the home network. Below my appdaemon.yaml
secrets: /config/secrets.yaml
log:
errorfile: STDERR
logfile: STDOUT
appdaemon:
threads: 10
plugins:
HASS:
type: hass
ha_url: https://xxxxx.duckdns.org
token: <automatic created by system>
hadashboard:
dash_url: http://127.0.0.1:5050
dash_dir: /config/appdaemon/dashboards
if you got homeassistant installed with hassio, you shouldnt change appdaemon.yaml at all (the addon takes care of everything) if not this is not the right topic to answer your question, then please ask me in PM or ask help on our discord server.
Hi,
AppDaemon was installed via Hassio. I reverted back to the original ha_url: http://hassio/homeassistant. Rest of the appdaemon.yaml is untouched. Original problem is still valid.