ESP32-CAM Capture

I think this will be difficult via esphome. The esp32camera component works over the api and the API is generally unsuitable for deep sleep.

I think you’ll need to use a lot of C++ code via lambda. And while you are using mqtt (because of deep sleep) send the pic over mqtt.

I am not planning on integrating ESPHome on Home Assistant, so I don’t think I will have any problems with the deep sleep.
All I need is to send the picture to an external source to save it, but I have no idea how to do that.
MQTT might be the solution because it can retain the message, but I am not sure if it supports binary files.
Do you have any suggestions or code on how to save and upload the image?

It can, that is why I suggested it.

You posted in the esphome section of the forum!

1 Like

What would be the best way to send an image using http request from my esp32 to Home Assistant?


I was wondering if I could use this method to send the image via http command? Maybe using binary?

What’s your aim? If you use the native api you can just take snapshots (ha service) :camera_flash:

My aim is to send the data/image over the http request as the ESP will be on another network

(Wantig to set up a remote camera and send the images to Home Assistant via the Nabu Casa Rest API, similar to the link of my other post but rather than the button sending the “human readable uptime” state, it sends an image from the camera)

Somewhat advanced stuff. Did you give a look at the camera web server?

Yeah had a look but looks to only run locally via the API.

Would be a treat if I could set the host URL of the API.

Just no idea how to send the image remotely.

It might be a while, but I have a similar request. In my case, I made the esp32cam wake up every 10 minutes for 20 seconds. There’s an automation in HA that runs every 14 seconds and tries to download the picture.

Ideally, HA would know when to take the picture, I think it might be possible to do that. A better case would be if esp32cam can upload the file directly somewhere.

Battery consumption is somewhat decent, can be improved with longer sleep times - 150-240 mA while active, 3-5mA while sleeping. I’m keeping a backup of the old photo while getting the new one. Anyway, this is as far as I’ve gotten, for now.

ESPHome code:

  name: esp32cam1
  platform: ESP32
  board: esp-wrover-kit

  ssid: !secret wifi_ssid
  password: !secret wifi_password

  fast_connect: true
  reboot_timeout: 60s
  use_address: esp32cam1.local
    static_ip: <your ip here>
    gateway: !secret gateway
    subnet: !secret subnet 
    ssid: esp32cam1
    password: "********"

# Example configuration entry
    pin: GPIO0
    frequency: 20MHz
    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: ESP32 Cam 1
  # ...
  resolution: 640x480
  jpeg_quality: 10
  max_framerate: 1 fps
  idle_framerate: 0.01 fps

  - platform: restart
    name: Restart device

  - platform: monochromatic
    output: led
    name: "LED"

  - platform: ledc
    id: led
    pin: GPIO4
    frequency: "1000Hz"

  - platform: wifi_signal
    name: WiFi signal

  - platform: uptime
    name: Uptime Sensor

  - platform: homeassistant
    id: homeassistant_time

# Enable logging
  level: VERBOSE

# Enable Home Assistant API


  run_duration: 15s
  sleep_duration: 600s

  - port: 8080
    mode: stream
  - port: 8081
    mode: snapshot

In configuration.yaml for HA:

  snapshot_esp32cam1: cp ./www/esp32cam1.jpg ./www/esp32cam1_old.jpg && curl --max-time 10 http://<your IP here>:8081/ -o ./www/esp32cam1.jpg -s


alias: esp32cam1 snapshot
description: ""
  - platform: time_pattern
    hours: "*"
    minutes: "*"
    seconds: /14
condition: []
  - service: shell_command.snapshot_esp32cam1
    data: {}
mode: single
1 Like

Why not trigger the download from the esp device when it wakes up and takes the pic.

You can run any home assistant service from the esp.

1 Like

how can i start such a service (capture photo and save to HA disk) ?
yaml example ?

You ever wondered why there isnt an esphome action to trigger a snapshot? I never realized untill now that the only option seems to be a HA service

I’m very new to ESP home and generally YAML, following, as I’m currently struggling to make a mailbox “sensor” that uses esp32-cam to take a picture every 5 minutes, then sleeps, I’d like to keep it all in the ESP home / HA ecosystem.

I’ll be trying the above example tonight, but am also following for any improvements yall come up with. Thanks!

Whats the purpose of taking a picture every 5 min? Is this going inside a mail box? If there is a door or if its inside the mail box then snap a picture on door open, motion, vibration, light/lux level etc. Surely you just want to know when theres mail and not 300 pictures of the inside of your mailbox every day i assume?

That “example” above that you plan to try out. That isnt an example, thats someone elses configuration for how they need and want things to work and just copying it and trying it isnt a good idea. Just go to the website, they give you esp32-Cam base configurations you can use to start with. Theres also more than 1 type of esp32-Cam so make sure you use the config thats for YOUR board and not someone elses.

Do a search… click on the magnifying glass icon up top.
Type in questions there and it gives you answers.

lol. I’m not saving 300 pictures.

I guess I’m kinda lucky that copy and pasting the above code worked out for me.

Here’s where I am, I’ve got it to where esp32-cam wakes up every 5 minutes for 90s. When it’s awake it sends a mqtt message, and I setup an automation to run the shell script on receipt of the message. I used curl to download the jpg from the snapshot, always overwriting the same file name.

The mailbox is 300ft from the house, it would be nice to glimpse a screen to see if the mail is in, so I don’t have to walk out and check multiple times a day.

It’s not installed yet, I’m waiting for battery stuff to come in.

Right now I’m struggling with the wake up pin configuration. But I agree only walking up when the door opened would be a lot better.