MQTT Motion Detection using ESP32 Camera (no PIR)

Motion Detection using ESP32 Camera (no PIR)

  • Enable/Disable Motion Detection

    • configured by publishing “enable” or “disable” to motion/office/settings/enable
  • Configurable “Heartbeat”

    • MQTT Topic: motion/office/online
    • reports onliine every 60 seconds
    • configured by publishing a new interval in ms to motion/office/settings/heartbeat
      • By default between 60000 - 300000 (1 minute - 5 minutes)
  • Configurable Motion “Lockout”

    • Stops motion detection for X miliseconds after motion detected
    • configured by publishing a new interval in ms to motion/office/settings/lockout
      • By default between 1000 - 60000 (1-60 seconds)
  • LED Indication

    • By default runs on pin 12 (works on FreeNove wrover dev board)
  • Based on ESP32 Camera Motion Detection without PIR {The Ultimate Guide} | Eloquent Arduino

  • In Arduino IDE you need the following extra libraries installed:

  • EloquantArduino

  • PubSubClient

2 Likes

Now includes MQTT Discovery Setup.

Upload the sketch to your ESP32 Cam and Home Assistant will auto discover it!!!



1 Like

Nice.

I’d love to see the appropriate libraries incl in esphome.

If I knew how, I’d be all over it. Maybe it’s time for me to delve into ESPHome…

1 Like

Made a bunch more improvements. It now uses Home Assistant’s MQTT Discovery to add 3 sensors:

  • Temperature (via DHT Sensor)
  • Humidity (via DHT Sensor)
  • Motion
    All 3 are updated at a minimum of 60 seconds. Temp/Humidity polls every 60 seconds by default
    Everything can be easily changed by the variables toward the top of the sketch file.

Its neat, this think cost me a total of $7 maybe $8 and is basically a 3 in 1 multisensor on the cheap

Now make it battery driven, that lasts a year :slight_smile:

Yeah, that’s not gonna happen. This is a fun project that I’ll have plugged into one of my USB outlets in the bedroom, hallway, and kitchen.

Man the places I would put 5v power if I had the wall linings off!

1 Like

Nice work.
Any plans to take a snapshot?
I would like to use the camera as a motion sensor and also to detect objects with Doods.

No, pretty much lies as it is. I don’t plan to do anymore with this. I use frigate and my custom front end, fEVR for object detection. This was just a fun little project to help me learn something new.

The code is out there and anyone is more than welcome to build up on it.

Having issue with mqtt authentication. How should this be coded in the arduino sketch?
The following doesn’t work

Many thanks

const char* mqtt_server = "192.168.0.159";           // MQTT Broker IP/URL
const int mqtt_port = 1883;                           // MQTT Broker Port
const char* mqtt_user = "mqttuser";
const char* mqtt_password = "mqttuser";

mqtt log in HA

error: received null username or password for unpwd check
2022-09-23 11:58:54: Client <unknown> disconnected, not authorised.
2022-09-23 11:58:59: New connection from 192.168.0.107:51145 on port 1883.

I think the user/pw go in the client.connect so line 427 would become

if (client.connect(uniqueID,mqtt_user,mqtt_password)) {
1 Like

Yep, that worked. Thanks

Hi ,
I couldn’t find where to write. Could you help ? Line 427 of which file. Thank you.

There is only one file in the repo.

Than you. :+1:

Hi there,

I will use this motion detection to create an automation for my washing machine (if motion detects that the timer turnes on / change the minutes it will start the live feed).
So I can see in the overview the live camera feed…

my question is: do I just need to copy the code from github link to the tf card and put it into the ESP32 cam? (MQTT & WiFi data will be changed)

Do I need an addon-on installed at HA except of Mosquitto?