ESP32 Cam - working!

Unfortunately it can, I don’t know why…

When I watch the stream through HA it just shows a delay of +/- 2 seconds… This is my automations that starts with a delay to compensate the delay of the stream:

# Send an iOS notification with a snapshot of someone who is in front of the door and pushed the doorbell button

- alias: ios snapshot doorbell

  trigger:
  - entity_id: binary_sensor.doorbell_button
    platform: state
    from: 'off'
    to: 'on'

  action:
  - delay: 00:00:06

  - service: camera.snapshot
    data_template:
      entity_id: camera.voordeur_camera_deurbel
      filename: '/config/www/snapshots/deurbel_{{ now ().day }}_{{ now ().month }}_{{ now ().hour }}_{{ now ().minute }}.jpg'

  - delay: 00:00:01

  - service: notify.ios_iphone_van_martijn
    data_template:
      title: Deurbel
      message: Er stond om {{now().strftime('%H:%M')}} iemand voor de deur!
      data:
        attachment:
          content-type: jpg
          url: 'https://myduckdnsaddres.duckdns.org/local/snapshots/deurbel_{{ now ().day }}_{{ now ().month }}_{{ now ().hour }}_{{ now ().minute }}.jpg'
          hide-thumbnail: false 

  - delay: 00:00:01
  
  - service: camera.local_file_update_file_path
    data_template:
      entity_id: camera.local_file
      file_path: '/config/www/snapshots/deurbel_{{ now ().day }}_{{ now ().month }}_{{ now ().hour }}_{{ now ().minute }}.jpg'
4 Likes

Thank you for config.
And what idle_framerate do you use (in ESPhome config)?

Just the default setting of 0.1 fps .

Here is an example using a SONOFF 433 RF PIR, but you could also use the onboard PIR (if you have it installed) No option to use software motion detection like with motionEye for example.

alias: '[Camera] Entree Cam record on motion when away'
initial_state: 'on'
hide_entity: false
trigger:
  - platform: state
    entity_id: binary_sensor.front_door_motion
    to: 'on'
condition:
  - condition: state
    entity_id: 'person.ezra'
    state: 'not_home'
action:
  # Turn on the flash light
  - service: homeassistant.turn_on
    data:
      entity_id: light.entreecam_light_2
  # Take 7x snapshot
  - service: camera.snapshot
    data:
      entity_id: camera.entreecam
      filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot.jpg'  
  - service: camera.snapshot
    data:
      entity_id: camera.entreecam
      filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot2.jpg'  
  - service: camera.snapshot
    data:
      entity_id: camera.entreecam
      filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot3.jpg'  
  - service: camera.snapshot
    data:
      entity_id: camera.entreecam
      filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot4.jpg' 
  - service: camera.snapshot
    data:
      entity_id: camera.entreecam
      filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot5.jpg' 
  - service: camera.snapshot
    data:
      entity_id: camera.entreecam
      filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot6.jpg' 
  - service: camera.snapshot
    data:
      entity_id: camera.entreecam
      filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot7.jpg' 
  # Send snapshot to telegram
  - service: notify.telegram
    data:
      title: Entree Cam
      message: "Motion alert entree camera."
      data:
        photo:
          - file: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}-snapshot.jpg'                                  
  #- service: camera.record
  #  data:
  #    entity_id: camera.entreecam
  #    filename: '/config/camera/entreecam/{{ now().strftime("%Y-%m-%d-%H:%M") }}.mp4'
  # Turn off flash light
  - service: homeassistant.turn_off
    data:
      entity_id: light.entreecam_light_2          

@mitchins

I’m guessing motionEye is not possible given the lack of RTSP stream and external access, though the stream should be possible though the token is a concern. As nice as it would be to have the cameras all tied together under motion eye…

Given the slow framerate, how do people handle capturing? FWIW I suppose node-red or similar dumping during times of activity would suffice, though again motionEye add-on could probably do the grunt work for you without a PIR.

I’ve discussed this with Ludeus and its probably not meant to be exposed in that manner, although you need to be logged in to view the stream. It would also not work stand alone (when logged out) nor will it with HTTPS, HTTP does work (adding it to motioneye that is) for now.

Using the default arduino camera webserver sketch also doesnt work for MotionEye, it times out trying to add it.

I really want but dont have an other option to try to get this setup in MotionEye, i’d be glad if anyone has an idea?!

Guys, the ESP32 cam does work with MotionEye and as standalone IP cam. I tested it. There are different codes to program it. If you flash it through ESPHome i.e. inside Home Assistant, there will be no IP access, it will just work in picture card in HA. If you flash it through Arduino default sketch, it will work as IP cam but not working with MotionEye. If you follow instructions on following link, it will work as IP cam and can also work with MotionEye inside HA. Few points to note. Cam resolution should be carefully chosen. On maximum resolution, it wont work long before heating up too high. So I am thinking to use it on max resolution only as snapshot taker like on movement take pic or stream and then go to deep sleep, though not tested this part yet.

4 Likes

Does anyone know why my image is rotated 90 degrees?
At least I assume it is and that the board is supposed to be orientated with the long side vertically.

1 Like

Maybe you can set the vertical_flip or horizontal_mirror configuration variables in the configuration file to fix this? See here, https://esphome.io/components/esp32_camera.html?highlight=camera

EDIT: Will not fix your 90 degree issue.

1 Like

Thanks but that will still give me an image rotated by 90 degrees, albeit a different orientation.

1 Like

This was helpful, but I’m curious why using the below doesn’t allow control of the brightness. Does anyone have a working example of controlling the brightness on the led? It’s crazy bright as just an on/off switch.

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

light:
  - platform: monochromatic
    output: gpio_4
    name: "Camera Light"
2 Likes

I’ve tried the same and also doesn’t give brightness control heh…

Not, in OTA flashing, is not necessary.

You are quite right, I missed that somehow. Cheers.

So I’ve noticed 2 other people asked a similar question in this thread, but let me get to it.

I’d like to use my ESP32 CAM on the NVR software “iSpy”, and have HA simply just display a live view of the ESP cam (which I already have set up).

I’ve been looking into how to enable an http web server on the ESP firmware that simply displays the stream kind of like on the example camera code in the Arduino IDE. If I am able to get the stream showing on a web server, I am confident I can get the camera working in iSpy. I am aware of the stream link generated in home assistant, but I would rather not convolute the stream by passing it through HA first; seems like a waste of CPU.

Does anyone have an idea?

Maybe the example code from this link will help:

2 Likes

Not via esphome.

1 Like

Like @Oleksii_Zelivianskyi stated I use the code in the link he provided and it works great with motion eye (running as a hassio addon) which then again trunks the stream in to home assistant. It gives me motion detection and a time lag of about 5 seconds.

As @nickrout stated this is not (yet) possible to do with esphome.

Also I think the quality of the picture is measurable better with the code from here https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/ than using esphome (with resolution and jpg quality set to maximum). The lag with esphome (about 10 seconds) is also significant higher than with the randomnerdtutorial sketch

To give an idea about the quality here is a shot with two esp 32 cam boards side by side:


cam 1 is esphomatized and has a pir sensor added. Beside that the onboard led is integrated as switch.
cam 2 is powered by the sketch from randomnerdtutorial and feed into motion eye. Their I have motion running over the stream and once again trunk the stream into ha from their.

5 Likes

I have switched over to that, but unfortunately, my NVR and HA cannot use the stream at the same time. I think I will allow iSpy to access the stream, and then I can import the stream from iSpy’s stream feature outlined and described here:

My computer running iSpy is way overpowered, so using CPU on it is a non-issue.

Pretty sure this will work, will find out later tonight.

Edit: Works great, would recommend.

1 Like

Whatever config I take, I don’t get any camera feed, the rest is working. I just got a second board and this is also not working

Any tipps?

Current config:

esphome:
  name: mobile_camera
  platform: ESP32
  board: nodemcu-32s


wifi:
  ssid: "bla"
  password: "blabla"

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  password: 'bla'

ota:
  password: 'bla'

esp32_camera:
  name: Mobile Camera
  external_clock:
    pin: GPIO0
    frequency: 20 MHz
  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
  reset_pin: GPIO32

output:
  - platform: gpio
    pin: GPIO4
    id: gpio_4

binary_sensor:
  - platform: status
    name: "ESP32Cam status"
sensor:
  - platform: wifi_signal
    name: "ESP32Cam WiFi Signal Sensor"
    update_interval: 60s
light:
  - platform: binary
    output: gpio_4
    name: ESP32Cam light

I have these two boards:

Looks like the one I have,
here’s my camera config

esp32_camera:
name: ${upper_devicename} 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
vertical_flip: false
horizontal_mirror: false
resolution: 1024x768
#max_framerate: 15 fps

And set the board to this
esphome:
name: ${devicename}
platform: ESP32
board: esp-wrover-kit

I did find out powering this from the ftdi adapter or through a breadboard doesn’t work and give a brownout error.
Powering it with 5v works like a charm

1 Like

I ended up with the configuration mentioned by @orange-assistant.
Installed MotionEye addon, flashed esp32-cam with this firmware: https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/

And it works better. With esphome, my esp32-cam stopped reporting in a day or two and was more laggy. With this firmware and motioneye it is stable for 2 weeks now, Raspberry Pi 3 processor load is about 15-20%. MotionEye records video to separate NAS.
The only problem is - I don’t know yet how to add a button trigger to this firmware.

And I am wondering, maybe it will be better to have a separate installation of MotionEye on another raspberry? Or on the same raspberry but separate from HA (in Docker)?

3 Likes