So as someone that has a blog that mainly has posts that either relate to the ESP8266 or Home Assistant, I feel like I should have been using ESPHome a long time ago. TL;DR: If you have ESP8266 devices and Home Assistant, you should absolutely be moving stuff to ESPHome. I plan on moving my Garage Door, Fireplace, and Sump Pump Monitor over to ESPHome.

Anyways, I read about how Home Assistant added support for ESP32 based cameras on ESPHome. That piqued my interest, so I bought one, and decided that would be the first device I use ESPHome with.

NOTE: The one that I bought is the same as the links above, but mine doesn’t have the BME280 sensor for temperature, humidity, and pressure. As you can see in pictures, it has a spot for the tiny sensor, but no sensor. I didn’t realize that when I bought it, or else I would have gotten that version. The ones in the links above have the sensor, and I’ve got code below to enable the sensor. You will just need to uncomment it.

NOTE2: I’m using Hass.io with the ESPHome add-on. That makes things a lot easier to manage your ESPHome devices. So if you’re not running Hass.io, you will likely have more steps you need to do, which I am not going to be too familiar with.

  1. Install the ESPHome Addon. In Home Assistant (HA), go to the Hass.io panel -> Add-on Store. Add https://github.com/esphome/hassio as an add-on repository. Click on the ‘ESPHome’ addon and install it, and start it. Click on “Open Web UI” and login with your HA login.
  2. Click the ‘+’ button to create an ESPHome node. Enter a name for it, and select the device type. In my case, it was the Generic ESP32 (WROVER Module). Put in your WiFi information and then submit.
  3. Compile the firmware. Click the 3dots on the new node and click ‘compile’. It can take a minute or 5 this first time.
  4. Upload the firmware to the ESP32. If you just connect the ESP32 directly to your HA computer/Pi, then at the top right select the TTY for the ESP from the dropdown, and then just click Upload on the node. This will take a minute or so.
    Alternatively, if you are like me and your HA instance is in your basement, and you don’t feel like plugging directly into it, you can download the binary using the link at the bottom of the compile dialog from step 3. After downloading the file, follow the steps below to upload it from your PC:

    1. Install Python 3
    2. Run these commands from the command line. I’m thinking it should be the same for any OS, but I was using Win10. I ran it from the Win10 command line, not the python command line.
      • pip3 install wxpython
      • pip3 install esphomeflasher
      • esphomeflasher
    3. That should open up a nice little gui. Select the ESP32 COM port, browse to the binary file you downloaded and flash it.
  5. In ESPHome, it should show online after a few minutes. For this node, you can now upload all future firmware updates to it over WiFi, without connecting it to the computer.  When we created the node, all it did was upload firmware that allows it to connect to WiFi and talk to ESPHome. Now we will make changes to the YAML for that node to add functionality to the firmware.
  6. Under the node in ESPHome, click ‘Edit’. Add the following code to the end of the existing code. If you got a unit with the BME280 sensor, be sure to uncomment those lines. For the display/font config, you will need to download that font(or whichever font you want to use) and copy it to your Hass.io ‘config/esphome’ directory. Then Save and Close:
    esp32_camera:
      name: My Camera
      external_clock:
        pin: GPIO32
        frequency: 20MHz
      i2c_pins:
        sda: GPIO13
        scl: GPIO12
      data_pins: [GPIO5, GPIO14, GPIO4, GPIO15, GPIO18, GPIO23, GPIO36, GPIO39]
      vsync_pin: GPIO27
      href_pin: GPIO25
      pixel_clock_pin: GPIO19
      max_framerate: 5 fps
      jpeg_quality: 10
      vertical_flip: false
      
      
      
    i2c:
      sda: GPIO21
      scl: GPIO22
    
    font:
      - file: "Ubuntu-Regular.ttf"
        id: ubuntu
        size: 20
    
    display:
      - platform: ssd1306_i2c
        model: "SSD1306 128x64"
        address: 0x3C
        lambda: |-
          it.print(0, 0, id(ubuntu), "Hello World!");
      
    # sensor:
    #   - platform: bme280
    #     temperature:
    #       name: "BME280 Temperature"
    #       oversampling: 16x
    #     pressure:
    #       name: "BME280 Pressure"
    #     humidity:
    #       name: "BME280 Humidity"
    #     address: 0x77
    #     update_interval: 60s
    
    binary_sensor:
      - platform: gpio
        pin: GPIO33
        name: "PIR Sensor"
        device_class: motion
  7. Upload the code again. You can upload it over the USB if you want, but Over-The-Air (OTA) updates should work now. Just select OTA from the drop down at the top right. The click Upload. Any time you add or remove components to the node, it has to completely recompile, which takes a few minutes. If you just make minor changes to a node’s component, then it takes about 30 seconds. Note the IP address of the node in the logs after it finishes uploading.
  8. Add the Integration in HA. In HA, go to Configuration -> Integrations. Configure the ESPHome. Give it a name. It will ask for a password if you set one when configuring the node. Now, the camera, PIR sensor, and the BME280 sensor should show up in HA.

And that’s it. I really wish ESPHome was around when I first got into this. It would have made things so much easier than having to write the code for each project. Something that took me a couple days to code could have been done in 20 minutes. Hopefully this is useful to someone. Feel free to comment below if you have any questions.

7 Replies to “My Experience with ESPHome on Home Assistant Using and ESP32 Camera/Motion Module

  1. Hi, great post, I have ordered the esp32 and can’t wait to test.

    Just a question on the pin mapping; if I look on the espHome page it shows different config for the wrover board. Will I need to remap?

Leave a Reply