Python to read MQTT messages

Python and python framework

Moderator: leecollings

Post Reply
sundansx
Posts: 10
Joined: Tuesday 30 May 2017 8:16
Target OS: Windows
Domoticz version:
Contact:

Python to read MQTT messages

Post 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?
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python to read MQTT messages

Post by waltervl »

See plugins like Zigbee2MQTT , Shelly MQTT etc
Search in https://www.domoticz.com/wiki/Plugins for MQTT for inspiration.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: Python to read MQTT messages

Post 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.
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
Ittiz
Posts: 48
Joined: Tuesday 03 January 2017 0:37
Target OS: Linux
Domoticz version: 13939
Location: USA
Contact:

Re: Python to read MQTT messages

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest