Page 1 of 1

Python to read MQTT messages

Posted: Monday 07 March 2022 5:32
by sundansx
I have an MQTT broker setup and I have setup and "MQTT Client Gateway with LAN interface" setup to listen to topics from an MQTT device (frigate). I am seeing the MQTT messages in the log as:

2022-03-05 00:25:05.876 MQTT: Topic: frigate/events, Message: {"before": {"id": "1646468697.36655-yw8znn", "camera": "backdoor", "frame_time": 1646468699.373544, "snapshot_time": 1646468698.94389, "label": "person", "top_score": 0.76953125, "false_positive": false, "start_time": 1646468697.36655, "end_time": null, "score": 0.53515625, "box": [433, 568, 556, 872], "area": 37392, "region": [64, 88, 872, 896], "stationary": false, "motionless_count": 0, "position_changes": 1, "current_zones": [], "entered_zones": [], "has_clip": true, "has_snapshot": true}, "after": {"id": "1646468697.36655-yw8znn", "camera": "backdoor", "frame_time": 1646468699.373544, "snapshot_time": 1646468698.94389, "label": "person", "top_score": 0.76953125, "false_positive": false, "start_time": 1646468697.36655, "end_time": 1646468704.540655, "score": 0.53515625, "box": [433, 568, 556, 872], "area": 37392, "region": [64, 88, 872, 896], "stationary": false, "motionless_count": 0, "position_changes": 1, "current_zones": [], "entered_zones": [], "has_clip": true, "has_snapshot": true}, "type": "end"}

This message is obviouly a json structure. I want to be able to write a python script, or plugin if necessary that can gather that data and process it. I am trying to glue a frigate (AI camera NVR) to domoticz to do some alerts and stuff. btw, frigate is really cool.
I know about node red, but did not want to install another piece of glue if the data is already coming into domotiz. I am not trying to tie this to a domoticz device, just get the data into a script
any ideas?

Re: Python to read MQTT messages

Posted: Monday 07 March 2022 8:08
by waltervl
See plugins like Zigbee2MQTT , Shelly MQTT etc
Search in https://www.domoticz.com/wiki/Plugins for MQTT for inspiration.

Re: Python to read MQTT messages

Posted: Tuesday 08 March 2022 14:02
by JanJaap
Most of those (o.a. my own Dyson plugin) create a mqtt class (mqtt.py) to do the interaction with the broker and then in plugin.py read in the data, process it and prepare the presentation of data to domoticz. You do not need the "MQTT Client Gateway with LAN interface" in between in that case.

Alternatively there is also the "MQTT Auto Discovery Client Gateway with LAN interface" which I think tries to created the domoticz widgets based on the incoming info but I have no experience with that.

Re: Python to read MQTT messages

Posted: Saturday 28 May 2022 21:20
by Ittiz
You ever make progress on this? I'd like to use AI to do presence detection on my cameras. It seems a lot easier to adapt an already working solution than try to integrate something like Detectron2 from scratch.