This is a continuation from this article: https://techstuff.leighonline.net/2023/03/19/esphome-on-home-assistant-running-in-docker/
Bascially, I have an ESP32Cam that I want to add to Home Assistant. My Home Assistant runs in Docker (So no supervisor. It is also called Home Assistant Core).
Steps
In ESPHome, click on New Device. I will be using ESPHome Flasher to flash my firmeware so if I get a warning, I just click continue.
Enter a name for your device
Select ESP32
Now click on Skip as we need to add some YAML config
Click on Edit
You can get YAML config from here: https://devices.esphome.io/devices/ESP32-CAM or here https://esphome.io/components/esp32_camera.html or just use the yaml below.
This config will add a section for the camera as well as a section for the LED light that is on the ESP32Cam that you can control from Home Assistant.
esphome:
name: esp32cam-3dprinter
friendly_name: esp32cam-3dprinter
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "t4Kxxx"
ota:
password: "2c0xxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32Cam-xxx"
password: "0RLxxx"
captive_portal:
# Config for esp32cam
esp32_camera:
name: the_camera
external_clock:
pin: GPIO0
frequency: 20MHz
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
max_framerate: 10 fps
resolution: 640x480
jpeg_quality: 25
wb_mode: auto
idle_framerate: 0.1fps
switch:
- platform: gpio
name: "esp32cam-3dprinter-light"
pin: 4
Once you added the config and gave your camera a nice name, click on Save, then Install, and then select Manual Download, and then select Legacy Format
The code will now be compiled and downloaded once it is done compiling. This might take a while. In the meantime, lets connect our ESPCam32 to our PC so long.
How to connect ESP32Cam to PC
We have to use an FTDI adapter for this. These guys have a great tutorial for how to connect your ESP32Cam to an FTDI, but the image below will show the gist of it
URL: https://randomnerdtutorials.com/program-upload-code-esp32-cam/
If you want to put the ESP32Cam in flashing mode, you need to connect GND and GPIO0 together like in the image below. Once you start uploading the firmware, you might have to press the RST button located on the bottom of the board. (I use a plastic wedge to push this button as my ESP32Cam is on a breadboard)
When flashing is done, you must remove the connection between GND and GPIO0, and press the RST button.
In ESPHome Flasher you select your COM port and the firmware that was downloaded, and click the “Flash ESP” button. You will see console messages flying by in the black window.
Once the flashing is done (remember to disconnect GND and GPIO0 and press the RST button), go to Home Assistant and then Integrations.
Click on Configure and then on Submit
It will ask for an encryption key for your ESPHome node. You can just open Home Assistant in another browser, open ESPHome (or go directly to ESPHome), and get this device’s encryption key from its YAML config.
You will see all your ESPHome devices listed under ESPHome. I have 2 so there are 2 devices. If I click on MyTestCam, it will show 2 entities (mine shows 3 but it should be 2, I made a mistake and had to reflash the firmware). The first entity is the camera and the second entity is the flashlight.
esp_cam_02 corresponds to the name that was used in the YAML config. (Ignore the 3rd entity)
Clicking on either one of these entities will either open up the camera or bring up a light control for the flashlight.
Adding camera feed to Home Assistant
To add the camera feed you must add a Picture Glance card. This will show a static image unless you tick the “Live” option when adding the card. Otherwise when you click on it it will show the camera feed if you do not want a live feed.