ESP32 Cam - working!

Hi there,

Sorry, if this is not the right place to post this. If not, please advice where I should go.

As mentioned by nickrout in post 495 above https://community.home-assistant.io/t/esp32-cam-working/109140/505, there are new and more advanced ESPHome features for configuring esp32cam. Details are here: https://github.com/esphome/esphome/pull/3090. and https://esphome.io/components/esp32_camera.html?highlight=camera

And, on that page it is described that is now possible to “push camera parameters to module, initially present into setup() method. This piece of code was put into pubic API to allowing update of parameters “on-the-fly”. Behavior during setup() is not changed. In addition, temporary solution consist to make user-defined service (detailed into config.yaml example, below). Result is one service available on home assistant to update camera parameters easily, to view influence of modification without need to recompile firmware.”

I am having difficulties figuring out what this exactly means. For one I am not sure what the config.yaml is, but I assume it is configuration.yaml in home assistant?

But, more importantly, I do not how to use the proposed code. There is an API part with some lambda for the different camera parameters. I do not how to set the different settings, ie how do I feed into those parameters?

And, assuming somebody explains that, how are these parameters then fed into the camera?

And below that there is the # ESP32-CAM configuration with pins etc, which looks like the one that goes into the ESPHome file. I tried including that also in the configuration.yaml, but that did not work?

Perhaps I got this all wrong? Should it go into the ESPHome yaml? And if so, how do I then feed the parameters to the camera.

Very confused here, but sure there is a simple solution…

The example config is for your esphome yaml. (Clue, it has lambdas, which ha doesn’t have)

The esphome config provides ha services which will change the cam’s parameters on the fly, see Native API Component — ESPHome

2 Likes

Thanks a lot for this nickrout! That was it, works now.

What I want to do is to change the settings for day and night. I can get a really clear night picture with a high agc_value, but then it is all white during the day. So if anybody got some good settings for that, please let me know.

Hello, I have a problem, maybe some one can help me.
I’m using this ESP32 cam with my home assistant. Is working quite good, for the live stream.

esphome config:

esp32_camera:
  name: esp32_cam_new
  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
  vertical_flip: false
  horizontal_mirror: false

An entity esp32_cam_new appears which I can show in dashboard.

Now I want to have a possibility to store from time to time a snapshot. But is not working. The trigger via MQTT works, but the snapshot isn’t stored on expected location.

esphome config:

mqtt:
  broker: xxx.xxx.xxx.xxx
  username: !secret mqtt_username
  password: !secret mqtt_passwort
  birth_message:
  will_message:
  on_message:
    - topic: esp32_cam/takesnapshot
      payload: 'ON'
      then:
        # - light.turn_on: esp32cam_light
        - output.set_level:
            id: esp32camnew_light
            level: "100%"
        - delay: 1000ms
        - logger.log: Calling snapshot service
        - homeassistant.service:
            service: camera.snapshot
            data:
              entity_id: camera.birdbox_camera
              filename: '/config/www/tmp/snapshot-birdbox.jpg'
        - delay: 1000ms
        - logger.log: Calling local_file service

        - homeassistant.service:
            service: local_file.update_file_path
            data:
              entity_id: camera.birdbox_snapshot
              file_path: '/config/www/tmp/snapshot-birdbox.jpg'
        - logger.log: Called snapshot service
        - delay: 1000ms
        - logger.log: Sleeping
        - output.set_level:
            id: esp32camnew_light
            level: "0%"

If I trigger snapshot from MQTT I get following output. Also the light becomes active, so trigger is working, but nothing stored:

[06:55:47][D][main:102]: Calling snapshot service
[06:55:48][D][main:113]: Calling local_file service
[06:55:48][D][main:120]: Called snapshot service
[06:55:49][D][main:127]: Sleeping
[06:55:49][D][sensor:125]: 'SupplyVoltage': Sending state 5.05337 V with 2 decimals of accuracy
[06:55:50][D][esp32_camera:168]: Got Image: len=19048
[06:55:54][D][sensor:125]: 'SupplyVoltage': Sending state 5.05337 V with 2 decimals of accuracy
[06:55:59][D][sensor:125]: 'SupplyVoltage': Sending state 5.05337 V with 2 decimals of accuracy
[06:56:00][D][esp32_camera:168]: Got Image: len=19439
[06:56:01][D][sensor:125]: 'ESP32CamNew YT WiFi Signal': Sending state -52.00000 dBm with 0 decimals of accuracy
[06:56:04][D][sensor:125]: 'SupplyVoltage': Sending state 5.05337 V with 2 decimals of accuracy
[06:56:09][D][sensor:125]: 'SupplyVoltage': Sending state 5.05337 V with 2 decimals of accuracy
[06:56:10][D][esp32_camera:168]: Got Image: len=18438
[06:56:14][D][sensor:125]: 'SupplyVoltage': Sending state 5.05337 V with 2 decimals of accuracy
[06:56:16][D][main:102]: Calling snapshot service
[06:56:17][D][main:113]: Calling local_file service
[06:56:18][D][main:120]: Called snapshot service
[06:56:19][D][main:127]: Sleeping

In my home assistant yaml file I have following configuration:

homeassistant:
  customize: !include customize.yaml
  packages: !include_dir_named packages
  allowlist_external_dirs:
        - "/config/www/tmp/"
.
.
.

camera:
  - platform: local_file
    name: birdbox Snapshot
    file_path: /tmp/snapshot-birdbox.jpg

I have installed my home assistant in a container on Raspi4B.

Any idea, what happens wrong here?

Fixed the Problem by myself. Entity name for snaphot service was wrong…

This seems to work:

light:
  - platform: monochromatic
    output: gpio_4
    name: PWM light
    id: pwm_light
    on_turn_on:
      then:
        - light.turn_on:
            id: pwm_light
            brightness: 10%

or:

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

Control the led with a slider

output:
  - platform: ledc
    pin: GPIO4
    channel: 2 # channel 1 is used for esp32_camera
    id: led

number:
  - platform: template
    name: Câmera Led
    optimistic: true
    min_value: 0
    max_value: 100
    step: 1
    mode: slider
    on_value:
      then:
        lambda: 'id(led).set_level(x/150);'
3 Likes

But how to make the LED turn on just while taking the image?

I didn’t test, but I think you can call number.set service if you are using HA automation.

Any tips/prep on how to solder the resistor to use the external antenna with a conventional solder iron?

Mine was already set up for the external antenna.

There is (was?) a video that demoed this…sadly I cannot find this quickly enough

This?

And seeing the description… how could I not have found this :crazy_face:

Looks easy, is hard. (For me)

Ask a friend? Or just try as entering this world of ESP32 will demand more soldering … And on the up-side…these things are so cheap that you can take a risk too…

But I was asking about accomplishing it with a soldering iron. I see no iron. What magic is this?

What board do you have?

Got it from aliexpress. I think Is equivalent to an ai thinker board.

I’ve found this, but this method is last resort if you messed up trying to move the resistor.
https://marksbench.com/electronics/esp32-cam-antenna-workaround/

As i have said, my AI thinker board was already set up for the external antenna. Do check :slight_smile: