I’ve been integrating my entire home into Home Assistant using as much open-source software and hardware as possible. Recently I’ve wanted to add some additional cameras to my home such as a camera to monitor my HVAC / water heater.
Although I already have 6 Unifi cameras integrated into the home those are extremely expensive (and frankly availability is poor on them as well). I don’t need a camera that costs hundreds of dollars to watch my utilities area.
Fortunately there’s an extremely widely available and cheap solution called the ESP32-CAM! These have been around for years and are one of the most popular ESP32 products. Since it uses ESP32 we can use ESPHome and Home Assistant to add a super cheap camera anywhere you’d like.
In this guide I’ll show my ESP32-CAM setup and how to configure it within Home Assistant and ESPHome. Let’s get started!
Hardware Used
The ESP32-CAM-MB supports WiFi / Bluetooth / BTLE for connectivity and uses a OV2640 2MP camera module
Links: Amazon.com*, AliExpress*, Amazon.com.au*, Amazon.ca*, Amazon.co.uk*, Amazon.co.jp*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.se*
Overview
First let’s take a look at the ESP32-CAM:
This is exactly how it came except you can see that I glued the image sensor in place. It comes detached but I intend to mount it pretty much exactly how you see it so I used some glue and permanently attached the sensor to the SD card slot. Be careful not to get any glue inside the SD card slot if you try this (and use less glue than I did).
Notice that there are two pieces here:
Not all listings give you both and some will only give you the ESP32-CAM part of the board. If you already have devices you can use with it to power the camera this is fine but most people will want to pick up the listing that comes with both boards. The micro USB port to power the board is on the second board as you can see above.
Here is the area I wanted to add a camera to:
This is my HVAC / utilities indoor area. On the very far right is a newer type of water softener that is much more efficient (which is why it has that really small salt can next to it). In the middle is my water heater and the on the left is the HVAC system.
I’ve had issues before where the pipe leading from the HVAC system has got knocked away from the drain and the water will start backing up. Having a camera here lets me easily spot problems like this and address them before it becomes a *really* big problem.
Adding ESPHome to Home Assistant
We are going to assume you have Home Assistant installed as installing Home Assistant is outside the scope of this guide. You can absolutely follow along though and see if it looks like something you’d like to explore. I have it installed as a supervised installation on an Orange Pi 5.
Sign into your Home Assistant instance and go to “Settings” and then “Add-ons”. Next click the “Add-on Store”.
ESPHome has it’s own section like this:
Select ESPHome and then click “Install”. Once the installation is finished you can click “Start” to start the service.
To make things easier choose to add the ESPHome option to your sidebar. That way you’ll see a menu choice specifically for ESPHome going forward.
Configuring ESPHome
First head to the ESPHome menu option:
If you don’t see the ESPHome menu option then go back to the “Add-on Store” from the previous step. Select ESPHome and enable “Show in sidebar”.
For setup we need to connect your camera to your device running Home Assistant with USB. This is only required for setup. It will communicate wirelessly after you’ve completed setup (if you configure it that way).
You also have the option of connecting it to a different computer but *only* if your Home Assistant instance is configured to run in HTTPS.
Click “New Device” in the bottom right hand menu. Follow the menus to add the device into your ESPHome instance. Choose “ESP32” as the device type.
Now install the configuration to the device.
Adding Device to Home Assistant
Now head back to your “Settings” menu for Home Assistant and click “Devices”. You should see your new sensor with the name you specified in the configuration.
Check to see if the sensor is online. With any luck it is like my example above. Now click “Configure”:
It should ask you if you want to add the node to Home Assistant. Select “Submit” and then it will ask you for your encryption key it gave us earlier. If you don’t have this just go back to the ESPHome menu and select “Edit”. You will see the key in plain text under “encryption” and then “key”.
If everything goes well the device should come online and be successfully paired with Home Assistant. From this point forward we will be able to update and push the configuration wirelessly to the device.
Adding Camera to YAML
Now your device should be available in Home Assistant but you won’t see a camera feed yet. We’re going to add that now. Go back to ESPHome and go to your new camera. Click “Edit”.
esphome: name: cam-utilities-indoor friendly_name: cam-utilities-indoor esp32: board: esp32dev framework: type: arduino # Enable logging logger: level: VERBOSE tx_buffer_size: 256 # Enable Home Assistant API api: encryption: key: "XXXX" services: # change camera parameters on-the-fly - service: camera_set_param variables: name: string value: int then: - lambda: |- bool state_return = false; if (("contrast" == name) && (value >= -2) && (value <= 2)) { id(espcam).set_contrast(value); state_return = true; } if (("brightness" == name) && (value >= -2) && (value <= 2)) { id(espcam).set_brightness(value); state_return = true; } if (("saturation" == name) && (value >= -2) && (value <= 2)) { id(espcam).set_saturation(value); state_return = true; } if (("special_effect" == name) && (value >= 0U) && (value <= 6U)) { id(espcam).set_special_effect((esphome::esp32_camera::ESP32SpecialEffect)value); state_return = true; } if (("aec_mode" == name) && (value >= 0U) && (value <= 1U)) { id(espcam).set_aec_mode((esphome::esp32_camera::ESP32GainControlMode)value); state_return = true; } if (("aec2" == name) && (value >= 0U) && (value <= 1U)) { id(espcam).set_aec2(value); state_return = true; } if (("ae_level" == name) && (value >= -2) && (value <= 2)) { id(espcam).set_ae_level(value); state_return = true; } if (("aec_value" == name) && (value >= 0U) && (value <= 1200U)) { id(espcam).set_aec_value(value); state_return = true; } if (("agc_mode" == name) && (value >= 0U) && (value <= 1U)) { id(espcam).set_agc_mode((esphome::esp32_camera::ESP32GainControlMode)value); state_return = true; } if (("agc_value" == name) && (value >= 0U) && (value <= 30U)) { id(espcam).set_agc_value(value); state_return = true; } if (("agc_gain_ceiling" == name) && (value >= 0U) && (value <= 6U)) { id(espcam).set_agc_gain_ceiling((esphome::esp32_camera::ESP32AgcGainCeiling)value); state_return = true; } if (("wb_mode" == name) && (value >= 0U) && (value <= 4U)) { id(espcam).set_wb_mode((esphome::esp32_camera::ESP32WhiteBalanceMode)value); state_return = true; } if (("test_pattern" == name) && (value >= 0U) && (value <= 1U)) { id(espcam).set_test_pattern(value); state_return = true; } if (true == state_return) { id(espcam).update_camera_parameters(); } else { ESP_LOGW("esp32_camera_set_param", "Error in name or data range"); } ota: password: "XXXX" wifi: ssid: !secret wifi_ssid password: !secret wifi_password domain: .jamesachambers.net power_save_mode: none manual_ip: static_ip: 192.168.4.76 gateway: 192.168.1.1 subnet: 255.255.0.0 dns1: 192.168.1.1 dns2: 8.8.8.8 esp32_camera: id: espcam name: esp-cam external_clock: pin: GPIO0 frequency: 10MHz i2c_pins: sda: GPIO26 scl: GPIO27 data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35] vsync_pin: GPIO25 href_pin: GPIO23 pixel_clock_pin: GPIO22 power_down_pin: GPIO32 resolution: 800x600 jpeg_quality: 10 # max. 63 max_framerate: 1.0fps idle_framerate: 0.2fps vertical_flip: true horizontal_mirror: false brightness: 2 # -2 to 2 contrast: 1 # -2 to 2 special_effect: none # exposure settings aec_mode: auto aec2: false ae_level: 0 aec_value: 300 # gain settings agc_mode: auto agc_gain_ceiling: 2x agc_value: 0 # white balance setting wb_mode: auto output: # white LED - platform: ledc channel: 2 pin: GPIO4 id: espCamLED # red status light - platform: gpio pin: number: GPIO33 inverted: True id: gpio_33 light: - platform: monochromatic output: espCamLED name: esp-cam light - platform: binary output: gpio_33 name: esp-cam led switch: - platform: restart name: esp-cam restart binary_sensor: - platform: status name: esp-cam status
Make sure to update with your own encryption keys (or use the ones that were automatically generated). I’ve replaced mine with XXXX.
Final Result
I ended up installing the camera here:
This is the top port of my network setup plug showing the Minoston Z-Wave power monitoring plug. I’ve covered that here and have more pictures of it in that article if you’d like to see a wider shot.
Within Home Assistant it looks like this:
And here’s the device entities:
You can see here we have a WiFi signal indicator, a restart switch and controls to turn on the ESP32-CAM’s LED as well as the white onboard light.
Conclusion
The ESP32-CAM is an incredibly good and cost effective choice to use for Home Assistant. With ESPHome we can ensure we are programming the device ourselves using open source software and not sharing any of our data with the cloud. At a cost of less than $20 it’s a really easy and cheap way to add a camera view anywhere you have a decent WiFi signal.
Getting it working can be pretty tricky to be honest mostly because there’s a lot of different models out there so the example configs might not always work properly. I have a few tricks in my YAML that seem to stabilize things such as setting the external clock frequency to 10MHz. If I set the resolution very far above 800×600 I’d get messages in my log file that my TCP send buffer was full. The device is definitely starting to show some age. It’s using a pretty old ESP32 chip (ESP32-S1).
If you have a spot that you need to monitor in a low resolution then this is a great <$20 completely open source solution. It doesn’t perform very well in high resolutions with the included ESP32 module. Undoubtedly you can use a better/newer ESP32 module and get better performance.
I’ll be exploring some slightly more expensive camera options that may be appropriate for places you need a higher resolution or better performance. This solution has been around for a long time and it’s starting to show it’s age which is why I only recommend it for a use case like this.
I’ll be covering some other ESP32 camera options coming up on the site including options from Adafruit and Seeed Studios (Grove). I’ll also be covering some thermal camera modules that can be used with ESP32 in the near future here. These will all cost more but will deliver higher performance. Definitely stay tuned!
Other Resources
I’ve also made a really cool Home Assistant / ESPHome WiFi action key here
You can also make a Home Assistant / ESPHome enabled action button
I’ve covered making a ESP32 air quality sensor (7-in-1) without soldering here
Well – I’ve been playing with ESP32 Cams for a couple of years with lesser and greater degrees of success … mainly failure!
However, since the early days I’ve got into HASS and reading your article I was inspired to have another go.
So I got hold of a new esp32 cam and a couple of MB boards to fit my old ESP32 cams (it was always such a pain to flash them and to power them successfully.
Anyway – followed your tutorial (after having to upgrade my ESPHOME instance which as fun!) and the first camera worked! Straight off! Amazing.
The other two older cameras were much more difficult but nothing to do with your instructions … they needed the IO0 button pressed when connecting to be able to flash them.
Even then, I simply couldn’t get them to fully integrate into HASS.
Finally, I managed to get them set up using CLI esphome, brute force them into HASS and then paste in your yaml and re-flash
So … I now have three working ESP32 cams … now … what the heck am I going use them for?!
THANKYOU
Hey Steve,
Great work! I also really struggled with finding the exact right configurations that worked and I’m glad some of these helped. Enjoy the 3 cameras!
Hi James, I am trying to follow your tutorial but I cant seem to get ESPHome to see my ESP32-CAM-MB CH340G WI-FI Bluetooth Development Board +OV2640 Camera Module. I already have ESPHome running with 3 esp8266 boards in different locations around my house, so i skipped on down to new device and selected esp32. I have a YAML file for the Camera but when i try to install using “plug into computer running ESPHome Dashboard” I get a no serial devices found error. I tried several different USB cords with the same result. Then I plugged in a spare ESP8266 I had and it sees the serial port right away. does this mean I have a defective Camera Module or am I doing something wrong?
Hey Jimp,
I’m glad you tested with several different cables as that is often the issue. I think it’s probably defective if the other modules will show up but that one won’t. I didn’t have that experience so it may be worth an exchange.
Hopefully that helps!
well, I just got in 3 more boards, these three don’t have the IO0 switch but at any rate I am getting the same result with those also. I can’t see having 4 bad boards and I know the cable is good. I am at a loss for what to try next
Hi James, first of all. I am glad that i found your site, but this is the first of many tutorials that i followed that actually worked (followed by a but 😉 )… Several ESP32S cam boards in home, buy them at aliexpress, the sell them as AI-thinker, but it is not mentioned on the board. Anyway. Tried al kind of different ways to get these things working. Arduino IDE with an FTDI adapter. I made me angry. I could not get it possible to upload. 3.3 volt, 5 volt, reset button on al different ways tried, never succeeded. Upload failed because of no communication. Then i found the ESP32 motherboard. Hoorrah… no it was possible to upload through Arduino IDE. Except it generates garbage and would not boot up.
Then i finally find this page. Great tutorial, followed it. And yes, i got finally a working camera. I only removed the static ip, it wouldn’t not work after i adjusted it to my home network settings. Anyway, dhcp works fine…but, no i have several of these devices and thouhgt…great, let’s install them all with this tutorial. So i picked numer 2, followed the exact same steps. HA mentioned “hi there, i find a new devices, do you want to add it”… sure i want. So i did, then go back to ESPHome, copy this script, made the neccesary adjustments with the api key and so on. Save, install…. succesfully installed. Find the IP address… and nothing…
This device in HA stays mentioning that it only has 1 entity, instead of 9. Browse to the ip adress with :8080 of :8081… no stream… ping on the address… no issue.
So, what am i doing wrong here, yes i did several tries. Also picked a third board. Exactly the same.
If i check the logs through esphome (wireless) i get:
INFO ESPHome 2023.5.5
INFO Reading configuration /config/esphome/esp32-camera-1.yaml...
WARNING GPIO0 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Starting log output from esp32-camera-1.local using esphome API
INFO Successfully connected to esp32-camera-1.local
[14:24:00][I][app:102]: ESPHome version 2023.5.5 compiled on Jun 8 2023, 13:46:34
[14:24:00][C][wifi:505]: WiFi:
[14:24:00][C][wifi:363]: Local MAC: 40:22:D8:76:C3:50
[14:24:00][C][wifi:364]: SSID: [redacted]
[14:24:00][C][wifi:365]: IP Address: 192.168.2.16
[14:24:00][C][wifi:367]: BSSID: [redacted]
[14:24:00][C][wifi:368]: Hostname: 'esp32-camera-1'
[14:24:00][C][wifi:370]: Signal strength: -37 dB ▂▄▆█
[14:24:00][C][wifi:374]: Channel: 1
[14:24:00][C][wifi:375]: Subnet: 255.255.255.0
[14:24:00][C][wifi:376]: Gateway: 192.168.2.254
[14:24:00][C][wifi:377]: DNS1: 192.168.2.234
[14:24:00][C][wifi:378]: DNS2: 192.168.2.254
[14:24:00][C][logger:301]: Logger:
[14:24:00][C][logger:302]: Level: DEBUG
[14:24:00][C][logger:303]: Log Baud Rate: 115200
[14:24:00][C][logger:305]: Hardware UART: UART0
[14:24:00][C][captive_portal:088]: Captive Portal:
[14:24:00][C][mdns:108]: mDNS:
[14:24:00][C][mdns:109]: Hostname: esp32-camera-1
[14:24:00][C][ota:093]: Over-The-Air Updates:
[14:24:00][C][ota:094]: Address: esp32-camera-1.local:3232
[14:24:00][C][ota:097]: Using Password.
[14:24:00][C][api:138]: API Server:
[14:24:00][C][api:139]: Address: esp32-camera-1.local:6053
[14:24:00][C][api:141]: Using noise encryption: YES
I cannot debug or check what is going wrong, can i?
Hope you maybe have an idea?
Hey Clubeddie,
What is the hostname of your other camera? You said that this is the second camera but I notice that all of your entity names are still esp32-camera-1. Should this be esp32-camera-2?
The reason this is a problem is because look at your addresses:
Address: esp32-camera-1.local:3232
Address: esp32-camera-1.local:6053
HomeAssistant uses hostnames to resolve these and not IPs. That’s why you can use DHCP at all. You cannot however use the same hostname on every camera. I’d make sure that your names are different within your config from any other cameras. You won’t be able to reuse the same config on every camera as they will all need unique host names at the very least.
Hopefully that helps!
Hi! Thanks a lot for the post, I have the same module, and I just managed to use your yaml and it worked! Do you know if it’s possible to turn off the LED of the USB power module? Thanks a lot
Hey Joao,
Great question! So yes, you can turn off both LEDs (the flash and the power LED). With this YAML it should be the “esp-cam LED” toggle switch.
Hopefully that helps!
Hello, that’s nice post. I have a question why your board is just esp32dev and no esp32cam, Do you know if there is a difference? In your loj can you see the state of PSRM, available YES?
Im asking because I bought to the same seller in AliExpress exactly the same camera and with one of them I have problem with PSRM, is not available, but then if I reflashed deleting everything appear again, and after few ‘install’ from esphome it disappear again. Problem is only with one camera. Do you have an idea what could be?.. I will try reflashing with esp32dev.
Nice job and first time i see a complete yaml file, mostly with services and it seem you are able to change parameter without have to install , right?
Cheers, Mauricio.
Hey Mauricio,
Great questions! So you can absolutely change the camera parameters without reinstalling via the API (shows up as a service within Home Assistant). Here’s what that looks like:
Here I’ve gone to Settings->Automations and Scenes and created a new automation. You can see that once you’ve added the camera via ESPHome you’ll have a new service you can call to set the camera parameters.
In here you just put in the parameter you want (I used brightness in the example but you can use any parameter specified in the YAML from the article near the “lambda” section) and then set it to the value you’d like. The camera will change when the automation is triggered and you’ll see the settings update on the fly (after a second or two the live image will change). In the above example I used my Adafruit WiFi Action Key but you could use anything as the trigger.
So for the one that isn’t working the thing that made the biggest difference for me is changing the resolution (lower). It seems to be resource related. If you run the serial log (or the wireless log) from ESPHome after setting the log_level to VERBOSE you can usually see what is going wrong. With mine I was getting messages that my TCP send queue was full. That means you are out of resources and should probably try lowering the resolution if you see that.
As far as using esp32dev this was because it was actually kind of hard to get this working. I tried many different configurations. I found the esp32dev one here on reddit (along with the API). This was by far the most reliable and best working configuration I found on the entire internet. I did modify it a bit but this was the base working configuration I started from (and I kept the API functionality which actually does work as shown above and is quite nice). I found it though because I was searching for ESP32-CAM reliability because mine was crashing all of the time. That thread covers setting it to 10MHz instead of 20MHz which did seem to stabilize mine quite a bit as well (when combined with lowering the resolution).
I didn’t use his exact configuration. I dropped the web server built-in functionality he is using for example. Why? Because I notice that my camera still is really short on resources all of the time (even at 800×600). He got 1024×768 out of his but if I use that on my board the camera drops off and becomes unavailable in Home Assistant much more frequently. It always recovers and comes back (on it’s own) but the higher I turn the resolution the more often it shows as unavailable and crashes basically. Lowering the resolution stabilized it and it shows as available in Home Assistant all the time now on 800×600 with this configuration.
Perhaps I could improve the throughput by using the external antenna on the ESP32-CAM. This requires hooking up the antenna and then bridging two points on the board with solder to activate the external antenna. I suspect the TCP send buffer is full due to WiFi signal not being super strong on mine. This would cause the send buffer to fill up as it’s waiting to clear it by sending the data over WiFi. Some people may be able to get higher resolutions out of theirs than I did if they have a better WiFi signal or by using the external antenna.
Not all of the ESP32-CAM boards everyone is getting are the same. Sometimes the ESP32 they are giving you with it won’t match what other people are getting. That’s part of why finding configurations for this is so confusing. Mine should match most people’s though as I did just buy the most popular Amazon listing of it so it should be a fairly common one.
Did you order all of your camera boards from the same seller? I assume by PSRM you mean PSRAM. It almost sounds like one of the boards might have a bad PSRAM. These already have very limited PSRAM available (Built-in 520 KB SRAM, external 4M PSRAM). To be honest with you those are pretty poor specs. The modern boards I use for projects like that Adafruit action key have quite a bit more resources than this available to them (ESP32-C3 and ESP32-S3) so the resources available on the bundled ESP32 they give you with the ESP32-CAM are definitely pretty low (the module I got with my ESP32 CAM was a ESP32-S1).
If the PSRAM isn’t showing up at all though I’d be wondering about a defect on that one. It sounds like maybe sometimes it does and sometimes it doesn’t? It is strange behavior though for sure and if only one of them is doing it (especially if that one came from the same place as some of the other working ones) then that one might just be defective. They are produced and sold for incredibly low prices so the defect rate almost certainly isn’t 0 and at this price point it might be even be higher than normal to be honest.
Hopefully that helps!
Cant wait to see you test higher res versions!
Hey Tink,
Thank you so much, me either! Technically the image sensor on these cameras can handle a lot more than the resolutions everyone has to configure them at. I think that’s largely a product of the ESP32 that they ship with it is definitely an older one. I keep running into buffer is out of space issues and things that suggest the ESP32-S1 they ship with this common one found on Amazon is really low on resources. I have no doubt even this module can perform a lot better with a better image sensor swapped in and a more powerful ESP module powering it.
I really appreciate the comment. I prioritize how I write these based on feedback like this that I get. It helps me to know people are interested in camera modules like this. It also makes me feel a little better since I spent a couple hundred dollars on camera modules a couple of days ago and wasn’t sure if anyone would be that interested or not. Now I feel a lot better about dropping that money and I hope you enjoy the coverage as I receive them and write up the results!
Outstanding work James and you’ve saved me the headache of working the EASP32-CAM boards into my ESPHome setup so thank you so much!
I agree it doesn’t help that some sellers list their devices as AI-Thinker boards yet ship some generic no-name brand which adds to the confusion and I strongly recommend buyers get the matching carrier board as it saves the effort when flashing and can be used to power the CAM board via powerbank. Otherwise for a basic web/security camera these function great if you’re happy with the 2MP low resolution and you can always try a different camera module such as fish eye, wide lense or night vision.
I look forward to seeing your future reviews as the Grove, Adafruit versions look to be upgrades and other offerings from M5STACK come with POE, Thermal imaging and Sipeed have a few RISC-V camera boards that look cool yet not quite as cheap or user friendly to setup from what I’ve read… Great work!
Hey Razor Burn,
Thanks so much! It definitely took some experimenting but this configuration seems to be pretty stable. It also helps to have a good power supply for it. Apparently it’s a known issue that if you try to power it via USB from another device it might not get enough power.
I just received an ESP-EYE module today which it looks like is actually made by Expressif. It will be interesting to compare the two. It looks like they even have a S3 version of it available now but mine is not that one. I really feel like the original ESP32-CAM would benefit a lot from having a S3 in it as well.
I can’t seem to find the ESP32-S3-EYE available as easily as the original version though. I see it on AliExpress but it’s like $66. That version seems to have a built-in LCD so it’s a lot more expensive.
I’d really like to find a ESP camera module that works in the dark. From what I can see there are very few choices like that. The most common solutions seem to be either to modify the camera and take out the IR filter or to buy a lens that supports night vision (since it’s as easy to swap out the entire camera module as removing the ribbon cable and putting a different one in).
I’d like to find one that just comes like this though ideally but maybe buying a module with a night vision lens is the answer. I didn’t do myself any favors by gluing the camera module to the SD card port if that ends up being the best thing to do.
Thanks so much for your comment, it’s very much appreciated. I recently got a Radxa Rock 3 compute module (CM3) as well that I’ll be reviewing soon. Take care!