Problem running BME280

I have been trying to get this ESP32 working with a BME280 in my grow tent so that I can monitor temp/humidity and trigger fans/humidifier to maintain conditions.

I have been trying to make some changes to the yaml code but I keep getting this message:

I downloaded the yaml from the esp32 and when I try to validate that, I get the same message. Any ideas about what I am doing wrong? Thanks in advance!

Here is the yaml code:

esphome:
  name: bme280
  friendly_name: BME280

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

api:
  encryption:
    key: "EM43UulDisv8PIfH77HhPSDGrTL0U5MOSMRkmw+LV7M="

ota:
  - platform: esphome
    password: "f3229f8a8a34bd9ed45eeb91e18aa395"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

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

captive_portal:

i2c:

sensor:
    platform: bme280_i2c
    temperature:
      name: "4x4 Tent Interior Temperature"
      oversampling: 16x
    pressure:
      name: "4x4 Tent Pressure"
    humidity:
      name: "4x4 Tent Humidity"
    address: 0x76
    update_interval: 8s
    
template:
    sensor:
      - name: "VPD in KPA"
        unit_of_measurement: "kPa"
        device_class: pressure
        state_class: measurement
        state: >
          {% set T = states('sensor.tent_temp_with_offset')|float(0) %}
          {% set RH = states('sensor.tent_rh_with_offset')|float(0) %}
          {% set SVP = 0.61078 * e ** (17.2694 * T / (T + 238.3)) %}
          {% set VPD = ((100-RH) / 100) * SVP %}
          {{-VPD | round(3) -}}
      sensor:
      - name: "Tent RH"
        unit_of_measurement: "%"
        device_class: humidity
        state: >
          {% set tent_rh = states('bme280_i2c_humidity')|float %}
          {% set offset = states('input_number.bme280_i2c_humidity')|float %}
          {{ (tent_rh + offset)}}
      sensor:
      - name: "Tent Temp"
        unit_of_measurement: "°F"
        device_class: temperature
        state: >
          {% set tent_temp = states('bme280_i2c__temperature')|float %}
          {% set offset = states('input_number.bme280_i2c__temperature')|float %}
          {{ (tent_temp + offset)}}

And here is the error message I keep getting:

INFO ESPHome 2024.10.2
INFO Reading configuration /config/esphome/bme280.yaml...
ERROR Error while reading config: Invalid YAML syntax:

while parsing a block collection
  in "/config/esphome/bme280.yaml", line 48, column 7
expected <block end>, but found '?'
  in "/config/esphome/bme280.yaml", line 58, column 7

What does this mean?

Anyway your template code doesn’t look like Esphome code.

1 Like

I am very new to Home Assistant and Esphome so thank you for your comment and for bearing with me.

I had thought that if I clicked on the 3 dots next to the sensor in ESPhome that says “Download yaml”, it would download the yaml that it is currently using.

For the template, I used this link to put together the yaml code.

Thanks for your help!