In case anyone is looking to use this with your recorder (DVR, XVR, NVR) not the camera itself change your apps.yaml to the following:
topic: cameras/1
to
topic: cameras
You should get JSON strings from any events triggered.
VideoMotion example:
{"code": "VideoMotion", "action": "Start", "index": "5", "data": {"SmartMotionEnable": false}}"
CrossRegionDetection example:
{"code": "CrossRegionDetection", "action": "Start", "index": "0", "data": {"Action": "Appear", "Class": "Normal", "CountInGroup": 1, "DetectRegion": [[1493, 1815], [1256, 4051], [1620, 4197], [5333, 2884], [4969, 308], [1547, 1815]], "EventSeq": 1160, "FrameSequence": 2942465, "GroupID": 0, "IndexInGroup": 0, "Mark": 0, "Name": "Rule4", "Object": {"Action": "Appear", "BoundingBox": [848, 2384, 1952, 4096], "Center": [1400, 3240], "Confidence": 0, "FrameSequence": 0, "ObjectID": 6500, "ObjectType": "Unknown", "RelativeID": 0, "Source": 0.0, "Speed": 0, "SpeedTypeInternal": 0}, "PTS": 62310.0, "RuleId": 3, "Sequence": 0, "Source": 0.0, "Track": null, "UTC": 1607268237, "UTCMS": 0}}
So we are interested mainly in the following:
-
“code”: Type of event
-
“action”: Start or Stop
-
“index”: Channel reporting the event. Channel 1 = (“index” = “0”), Channel 2 = (“index” = “1”) …
Example of a binary-sensor:
binary_sensor:
- platform: mqtt
name: Channel 1 Tripwire **this can be changed to what ever you want**
state_topic: cameras
value_template: "{{ 'ON' if value_json.code == 'CrossLineDetection' and value_json.action == 'Start' and value_json.index == '0' else 'OFF'}}"
device_class: motion
If you follow further down the CrossLineDetection string you will find:
"Name": "Rule4"
When you set an IVS rule on the recorder you can give it a unique name. This is where that name will appear. This will allow you set up multiple different triggers in the cameras view. This could be helpful to trigger lights based on where you are in a room.
You should be able add another
and
value with
value_json.data.0.name == 'your.rule.name'
Or, possibly, if all intelligent rules have unique names then just this string, VideoMotion will still need
"index"
to identify the channel.
I’ve yet to try the last value above. I believe there is a bracket that needs to be dealt with to get to the name field. I have little coding experience and most of this is Frankensteined together. So please correct any errors.
I did a full write up of the steps I followed on reddit: