Unifi Video Motion Detection with MQTT Working!

I’ve written a simple script to monitor the logs on a Unifi Video server and send MQTT messages when motion is detected as I have seen a lot of posts that people can’t get this to work.

I this this can be enhanced a lot more than what I’ve done, but this is simple and it works. I’d love to see it re-written maybe in Python but I don’t have the time or expertise to do that right now. Maybe if someone else wants to give it a go? You can use my code as a framework.

5 Likes

This is great! thanks alot for this. I learned alot just going through your code and setting this up.

One thing I did come accross though, your script has the MQTT messages with the “retain” flag set.
I found that the consequence of this was that as soon as HASSIO boots up, it sometimes processes the last 2 retained motion start messages, which causes some havoc since they are never preceeded by a motion end message. Is there a reason you had the retain flag set?
(Newbie here so Im assuming I must be missing something)

Thanks again