Esp32-cam always idle?

I’ve been trying to get a few ESP32 cameras up and running in key areas. While I get a picture, it seems mostly static (not changing) and the camera is ALWAYS listed as idle. I can see in the log that frames are sent “as expected” but I don’t see updates of the image often when viewing it through HA. II don’t see parameters to tell what area to look at if there is a way to have the camera report motion/activity automatically. Perhaps someone can see what’s wrong here?

esphome:
  name: esp32cam

esp32:
  board: esp32cam
  framework:
    type: arduino

output:
- platform: ledc
  pin: GPIO4
  id: gpio_4
  channel: 2

light:
  - platform: monochromatic
    output: gpio_4
    name: Flash/PWM Light
    restore_mode: ALWAYS_OFF

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxxxxxxxxxxx"

ota:
  password: "xxxxxxxxxxxxx"

wifi:
  ssid: "xxxxxxxxxxxx"
  password: "xxxxxxxxxxxxxxxxx"
  fast_connect: on

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32Cam Fallback Hotspot"
    password: "xxxxxxxxxxxxxxxx"

captive_portal:

time:
  - platform: homeassistant
    id: homeassistant_time

sensor:
  - platform: wifi_signal
    id: signal_strength
    name: "Wifi Signal Strength"
    update_interval: 60s

# Example configuration entry
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

  # Image settings
  name: My Camera
  resolution: 1280x1024
  max_framerate: 10 fps
  idle_framerate: 0.2 fps
  jpeg_quality: 10
  wb_mode: home
  agc_gain_ceiling: 128x
  vertical_flip: false

I know, I didn’t add secrets here - need to fix that. I’ve tried to experiment with picture quality parameters, changed the idle and max framerates etc. but it’s clear none of these have any effect on showing up as idle? Here’s what HA sees - the event of going idle happens the moment the camera comes online, and I haven’t seen it change yet.

When I view the camera/video feed I see mostly a static image, and even rapidly moving the camera doesn’t change the view. If I close and then re-open the image window I may see the change, or I may see a picture that’s 10 seconds old.

I’ve run out of ideas and wondering if I missed something? I would expect to see “moving pictures” even if just at a low frame-rate, and if the ESP32-CAM can detect motion/changes see that reflected so I can use that in automations. Am I expecting too much out of the ESP32-CAM?

1 Like

Try commenting out idle_framerate

Try commenting out idle_framerate

Since 0.1 is the default, and I’ve already tried several values there, there’s no difference. According to the docs, it’s the frame-rate used when no clients are trying to watch the stream. It’s when I watch the stream I see “idle” and it would be the max_framerate that would cause issues given the big delays I see - but alas, changing that value doesn’t seem to do anything either.

What did you change it to (I did suggest commenting it out, but you ignored that).

What did you change it to (I did suggest commenting it out, but you ignored that).

I’ve tried leaving it out, specifying 0.1, 0.2 or even whole numbers. It doesn’t change the status of idle. The way I read the documentation, this value is used WHEN the camera is idle - it doesn’t cause it to be idle.

As to commenting out, not sure why it matters how I make suggested changes? I keep files managed by git, I have multiple different files with different configuration combos saved etc - and I just switch files out when I test. I don’t need to comment things out. But even if I did, why would that make a difference? So when I say I don’t specify it, it’s not in the file (commented or otherwise). When I say it has a value, it means it’s in the file with a value.

General update
I’ve managed to get more frequent updates so changes show up within a second delay - nothing that would ever be considered movie level, but at least I see changes very close to when they happen, and the resolution is high enough for my purpose.

However, HA still calls it ‘idle’. For now, I’m removing that status since it’s ‘false’ allowing the media->video view to work just fine, the dashboards will show the ‘live’ video with 1-2 frames a second (tops).

I didn’t expect high end camera quality - so the low framerate isn’t a big issue. But I would definitely still like to ‘fix’ the idle status.

Here are the image settings I use (successfully):

  # Image settings
  aec2: True
  aec_mode: AUTO
  name: "My Camera"
  resolution: 800X600
  max_framerate: 6 fps
  idle_framerate: 0.1 fps
  jpeg_quality: 10
  wb_mode: home
  agc_gain_ceiling: 8x
  vertical_flip: False
  horizontal_mirror: False

Note, the max_framerate is funny - it’s nowhere close to 6, but since it is an upper bound only it would only prevent the device trying to push more through the wireless signal.

Thank for all your testing work. I am also using the camera since some weeks and facing exact the same issue. So i was also wondering what causes the issues about the Idle status.

I was suggesting taking it out of your config because I thought it was probably the cause of your problem. If idle_framerate is 0.2 and if the state is showing as idle, the camera will display one frame every 5 seconds, which would show the sort of display you were describing.

Of course why the camera integration is showing as idle all the time is another matter.

I’ll leave this with just a simple comment as I don’t think this is relevant to the topic. Your argument/complaint was that it wasn’t commented out. Hopefully we can agree that it doesn’t matter how you change the value. I appreciate the suggestion - really - but if your point was that the camera was slow because it was idle, it doesn’t really answer the question that the camera is idle in the first place. And removing the value from the configuration file just makes it LESS than 0.2 which also means it doesn’t solve the problem you say it does.

I would like to know if the idle frames has to be high for ESPHOME to detect motion. I don’t see that documented anywhere - and if that’s the case making it higher, not lower, would be the solution. I don’t know.

For now I’ll go through the code-base instead to find an answer. If I do find one, I’ll post it.

If the camera says it is in idle mode all the time, perhaps it is showing the idle_framerate (which would describe what you are seeing). That is why I suggested removing idle_framerate. Can I suggest then that you try the same as max_framerate, just to see if you see any difference. I don’t have idle_framerate set at all and I do not see what you see.

I don’t see anything about motion detection in the docs.

I’ll add this thread for something that uses an espcam to do motion detection. MQTT Motion Detection using ESP32 Camera (no PIR) - but does not provide a camera entity in HA.

Also motion detection is, I believe, possible with esphome esp32camera when combined with motion or motioneye.

Removing or commenting out idle_framerate won’t make any difference for the simple reason that it’s an optional parameter that will default to 0.1, per the docs:

ESP32 Camera Component — ESPHome

I am seeing the same behavior as described by @egoalter , with the thumbnail being labeled as “Idle”, but I think that’s actually normal. If I add the camera to a dashboard, and tap the thumbnail, I get a pop-out view that updates (somewhat) more frequently.

Frame rate in both cases is terrible, but there is a clear difference between the two.

Yes true, I was getting a little hung up on that.

Mine always has the state “idle” too, but does give moving images at greater than 0.1 FPS.

The default FPS is only 10, which will be a bit jerky.

I ended up giving up on the ESP32-CAM for this. Just could not get a decent frame rate. Repurposed an old Pi3 with a webcam as an MJPEG streamer and getting much better results. Overkill, but since I had the hardware available…

I tried a few different routes before I settled for the option of running ESPhome on the ESP32-cam with the web server camera component publishing the camera to a Motioneye server I have for other purposes. This will give me a live feed of the ESP32-cam in HA as well as access to all the usability found in ESPhome. Before that I tried the Arduino ESP32 example “Camera Web server” code instead. That in turn allowed me to use my Motioneye server to connect to the ESP32-cam and get a feed to HA, but I lost all the OTA access and such.

Fredrik

2 Likes

What kind of framerate did you get when using motioneye between?

I have tried esphome, GitHub - s60sc/ESP32-CAM_MJPEG2SD: ESP32 Camera motion capture application to record JPEGs to SD card as AVI files and stream to browser as MJPEG. If a microphone is installed then a WAV file is also created. Files can be uploaded via FTP or downloaded to browser. and GitHub - rzeldent/esp32cam-rtsp: Simple RTSP (streaming image) server for the ESP32CAM. Easy configuration and monitoring through the web interface.
Using the rtsp since the only thing I need is a video stream, and I get a good framerate. I can also use this directly in home assistant and I think I could do OTA (just saw that the arduino IDE finds the device on the network).

If I disable the HA API connection, I.E. disable the esp device in HA, I gett a framerate through motioneye around 5fps. The instant I enable the API the rate drops to 0.5fps.

/Fredrik

I’ve the same experience with the low frame rate.

I’ve added the [ESP32 Camera Web Server Component — ESPHome] to the ESP32_CAM and when I view the stream the logs on the ESPHome shows up a better framerate (for the stream via the webserver), but is is not reflected to the HA entity.

I’ve added a card on the dashboard with a webpage with the URL to that cam and have now a live stream on the HA dashboard.

1 Like

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.

1 Like