Cheap ESP32-CAM Home Assistant ESPHome Camera Guide

ESP32-CAM within Home Assistant
ESP32-CAM within Home Assistant

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

ESP32-CAM
ESP32-CAM

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:

ESP32-CAM - Top View
ESP32-CAM – Top View

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:

ESP32-CAM - Top View
ESP32-CAM – Top View

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:

ESP32-CAM Target Area
ESP32-CAM Target Area

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:

Home Assistant Add-on Store - ESPHome
Home Assistant Add-on Store – ESPHome

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:

ESPHome Configuration Menu
ESPHome Configuration Menu

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”:

Home Assistant - Devices Menu - Configure ESPHome
Home Assistant – Devices Menu – Configure ESPHome

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:

ESP32-CAM Installed
ESP32-CAM Installed

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:

ESP32-CAM within Home Assistant
ESP32-CAM within Home Assistant

And here’s the device entities:

ESP32-CAM - Home Assistant Entities
ESP32-CAM – Home Assistant 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

All of my Home Assistant related articles can be seen here

Subscribe
Notify of
guest

21 Comments
Inline Feedbacks
View all comments
Steve Kelly
Steve Kelly
11 months ago

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

Jimp
Jimp
1 year ago

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?

Jimp
Jimp
1 year ago

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

Clubeddie
Clubeddie
1 year ago

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?

Joao A.
Joao A.
1 year ago

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

Mauricio C.
Mauricio C.
1 year ago

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.

Tink
Tink
1 year ago

Cant wait to see you test higher res versions!

Razor Burn
Razor Burn
1 year ago

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!