I had the same issue. Without being an expert, I am reasonably certain the ESPHome implementation ESP32 Camera Component results in Home Assistant sending a request to the camera which then sends a image back, and the communication overhead is too much to provide reasonable framerates. At least running HA on an Raspberry Pi 3 B, might be different on newer models.
The log of the ESP32-CAM (in HA under ESPHome, works kind of like the Serial Monitor in Arduino) looks something like this:
[17:51:40][D][esp32_camera:196]: Got Image: len=73025
[17:51:41][D][esp32_camera:196]: Got Image: len=72865
[17:51:41][D][esp32_camera:196]: Got Image: len=72846
[17:51:41][D][esp32_camera:196]: Got Image: len=73011
The solution is to add the ESP32 Camera Web Server Component to the yaml file:
esp32_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
esp32_camera_web_server:
- port: 8080
mode: stream
- port: 8081
mode: snapshot
(if we try to use only esp32_camera_web_server
, it will complain that it requires esp32_camera
)
You can then add a Picture
Card to your HA dashboard and put in the stream’s adress as image path, for example http://192.168.2.109:8080
for the stream.
The log of the ESP32-CAM in your ESPHome will look like this:
[17:51:41][D][esp32_camera_web_server:198]: MJPG: 73025B 236ms (4.2fps)
[17:51:41][D][esp32_camera:196]: Got Image: len=73134
[17:51:42][D][esp32_camera_web_server:198]: MJPG: 73134B 240ms (4.2fps)
[17:51:42][D][esp32_camera:196]: Got Image: len=72908
However, I found that using the HA’s MJPEG IP Camera Integration is a better choice to avoid a 24/7 continuous stream.
After setting it up it will show up in HA in Settings - Devices & Services as “MJPEG IP Camera” and if you open the “device” page you will see “Add to Dashboard” below the sensor (just click around a bit, you will get used to it). HA will propose a card for you and you can just confirm it.
After that you should have the still image on your dashboard and if you click on it it will open the stream, as can be verified looking at the logs of the ESP32-Cam. Pretty much the behavior you are probably aiming for.
What I haven’t found out yet is if the framerates we can specify in esp32_camera
impact the streaming and still image framerates. Doesn’t look like it.