ESPHome: expected <block end>, but found '-'

Hiyo all,

I am trying to setup an MQ-7 & BME680 on an ESP32 dev board and running into an error that I’ve narrowed down, but cannot resolve it. I’ve combined the example codes from the ESPHome MQ-7 page, and and mix-mash of the BME680 sensor page.

Individually they work, but combined I think I pooched it.

Could someone help take a look at the code below? Thank you!

Error:

while parsing a block mapping
  in "/config/esphome/test.yaml", line 145, column 3
expected <block end>, but found '-'
  in "/config/esphome/test.yaml", line 146, column 3

In case the formatting in this post changes the line number, 145 & 146 is:

  id: bme680_internal
  - platform: bme680_bsec

Code:

substitutions:
  mq72_name: "MQ72"
  mq72_id: "mq72"
  mq72_heater_pin: "25"
  mq72_analog_pin: "33"
  mq72_low_side_resistor: "1000"
  mq72_high_side_resistor: "470"
  mq72_supply_voltage: "5.0V"
  temperature_sensor_id: "bme680temperature"
  humidity_sensor_id: "bme680humidity"
  mq72_clean_air_compensated_resistance: "65196.7"

esphome:
  name: co-detector-2
  friendly_name: CO Detector 2

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:
  baud_rate: 115200

api:
  encryption:
    key: 
ota:
  password: 

wifi:
  ssid:
  password: 
  manual_ip:
    static_ip: 
    gateway:
    subnet: 255.255.255.0
    dns1:
    dns2:

  ap:
    ssid: 
    password: 

#This I2C is for the BME680 sensor
i2c:
  sda: GPIO21
  scl: GPIO22
  scan: True

output:
  - platform: gpio
    pin: ${mq72_heater_pin}
    id: ${mq72_id}_heater_pin

switch:
  - platform: output
    name: "${mq72_name} Heater"
    icon: mdi:fire
    entity_category: diagnostic
    disabled_by_default: True
    id: ${mq72_id}_heater
    output: ${mq72_id}_heater_pin

interval:
  - interval: 150s
    then:
      - switch.turn_on: ${mq72_id}_heater
      - logger.log: "${mq72_name}: The sensor is heating!"
      - delay: 55s
      - switch.turn_off: ${mq72_id}_heater
      - logger.log: "${mq72_name}: The sensor is measuring!"
      - delay: 90s
      - if:
          condition:
            - switch.is_off: ${mq72_id}_heater
          then:
            - component.update: ${mq72_id}_raw
            - logger.log: "${mq72_name}: Done"
            - switch.turn_on: ${mq72_id}_heater
            - delay: 5s

sensor:

  - platform: adc
    id: ${mq72_id}_raw
    name: "${mq72_name} Voltage"
    entity_category: diagnostic
    disabled_by_default: True
    pin: ${mq72_analog_pin}
    attenuation: auto
    update_interval: never
  - platform: resistance
    id: ${mq72_id}_resistance
    name: "${mq72_name} Resistance"
    icon: mdi:omega
    entity_category: diagnostic
    disabled_by_default: True
    sensor: ${mq72_id}_raw
    configuration: UPSTREAM
    resistor: ${mq72_low_side_resistor}
    reference_voltage: ${mq72_supply_voltage}
    filters:
      - lambda: return (x - ${mq72_high_side_resistor});
    on_value:
      then:
        - component.update: ${mq72_id}_compensated_resistance
  - platform: template
    id: ${mq72_id}_compensated_resistance
    name: "${mq72_name} Compensated Resistance"
    icon: mdi:omega
    entity_category: diagnostic
    unit_of_measurement: Ω
    lambda: |-
      return (id(${mq72_id}_resistance).state / ( -0.01223333 * id(${temperature_sensor_id}).state -0.00609615 * id(${humidity_sensor_id}).state + 1.70860897));
    update_interval: never
    on_value:
      then:
        - component.update: ${mq72_id}_ratio
  - platform: template
    id: ${mq72_id}_ratio
    name: "${mq72_name} Ratio"
    icon: mdi:percent
    entity_category: diagnostic
    disabled_by_default: True
    unit_of_measurement: "%"
    lambda: |-
        return 100.0 * (id(${mq72_id}_compensated_resistance).state / ${mq72_clean_air_compensated_resistance});
    update_interval: never
    on_value:
      then:
        - component.update: ${mq72_id}_co
  - platform: template
    id: ${mq72_id}_co
    name: "${mq72_name} Carbon Monoxide"
    unit_of_measurement: "ppm"
    device_class: carbon_monoxide
    lambda: |-
      auto ratio_ln = log(id(${mq72_id}_ratio).state / 100.0);
      return exp(-0.685204 - 2.67936 * ratio_ln - 0.488075 * ratio_ln * ratio_ln - 0.07818 * ratio_ln * ratio_ln * ratio_ln);
    update_interval: never

# BME Sensor Setup
bme680_bsec:
  id: bme680_internal
  - platform: bme680_bsec
    bme680_bsec_id: bme680_internal
    address: 0x77
    temperature_offset: -1.3
    iaq_mode: static
    supply_voltage: 3.3V
    sample_rate: ulp
    state_save_interval: 6h
  temperature:
    id: "${temperature_sensor_id}"
    name: "BME680 Temperature"
    oversampling: 16x
  pressure:
    name: "BME680 Pressure"
  humidity:
    id: "${humidity_sensor_id}"
    name: "BME680 Humidity"
  gas_resistance:
    id: "gas_resistance"
    name: "BME680 Gas Resistance"
  update_interval: 60s
  co2_equivalent:
    name: "BME680 CO2 Equivalent"
    filters:
      - median
  breath_voc_equivalent:
    name: "BME680 Breath VOC Equivalent"
    filters:
      - median

  - platform: template
    name: "BME680 Indoor Air Quality"
    id: iaq
    icon: "mdi:gauge"
    # caulculation: comp_gas = log(R_gas[ohm]) + 0.04 log(Ohm)/%rh * hum[%rh]
    lambda: |-
      return log(id(gas_resistance).state) + 0.04 *  id(${humidity_sensor_id}).state;
text_sensor:
  - platform: template
    name: "BME680 IAQ Classification"
    icon: "mdi:checkbox-marked-circle-outline"
    lambda: |-
      if (int(id(iaq).state) <= 50) {
        return {"Excellent"};
      }
      else if (int(id(iaq).state) <= 100) {
        return {"Good"};
      }
      else if (int(id(iaq).state) <= 150) {
        return {"Lightly polluted"};
      }
      else if (int(id(iaq).state) <= 200) {
        return {"Moderately polluted"};
      }
      else if (int(id(iaq).state) <= 250) {
        return {"Heavily polluted"};
      }
      else if (int(id(iaq).state) <= 350) {
        return {"Severely polluted"};
      }
      else if (int(id(iaq).state) <= 500) {
        return {"Extremely polluted"};
      }
      else {
        return {"unknown"};
      }


This looks wrong. I think it should be

bme680_bsec:
  - platform: bme680_bsec
    id: bme680_internal

I’ve tried that and it showed error from:

while parsing a block collection
  in "/config/esphome/test.yaml", line 145, column 3
expected <block end>, but found '?'
  in "/config/esphome/test.yaml", line 154, column 3


Following entries:

  - platform: bme680_bsec
    id: bme680_internal
    bme680_bsec_id: bme680_internal
    address: 0x77
    temperature_offset: -1.3
    iaq_mode: static
    supply_voltage: 3.3V
    sample_rate: ulp
    state_save_interval: 6h
  temperature:



I am NOT and expert- especially with YAML. Mistake me for one at your own risk.

The block starts with bme680_bsec: in column 1 But if that is another sensor, like the ones above it, then I would guess that it should be similarly indented.

Can you elaborate a bit more? Do you mean that I have the bme680_bsec: incorrectly indented?

You are mixing options of the base component bme680_bsec and the sensors
“platform” or “bme680_bsec_id” belong to the sensors
you might want to try something like:

# BME Sensor Setup
bme680_bsec:
    id: bme680_internal
    address: 0x77
    temperature_offset: -1.3
    iaq_mode: static
    supply_voltage: 3.3V
    sample_rate: ulp
    state_save_interval: 6h
sensor:
  - platform: bme680_bsec
    temperature:
      id: "${temperature_sensor_id}"
      name: "BME680 Temperature"
      oversampling: 16x
    pressure:
      name: "BME680 Pressure"
    humidity:
      id: "${humidity_sensor_id}"
      name: "BME680 Humidity"
    gas_resistance:
      id: "gas_resistance"
      name: "BME680 Gas Resistance"
      update_interval: 60s
    co2_equivalent:
      name: "BME680 CO2 Equivalent"
      filters:
        - median
    breath_voc_equivalent:
      name: "BME680 Breath VOC Equivalent"
      filters:
        - median

bme680_bsec_id as a reference to the base component is not needed IMHO, you only have one device.
You might also have to move the sensor definitions for the BME680 into a single block with the other sensors above the BME680 stuff, one block for sensor in the whole file

Thanks for the information armin-gh. @stevemann’s comment lead to look at the information more closely and the modifications I made are near to what you have just suggested and it is working!

I noticed that the BME680 via BSEC has 2 extra sensors (CO2 & VOC). Does anyone know why the BME680 doesn’t have this? Is it specific to the BSEC?

Many thanks to everyone for taking the time to look and respond.

Cheers.

Based on the documentation for the BSEC-Library on Github GitHub - boschsensortec/BSEC-Arduino-library: Arduino library for BSEC to simplify integration into compatible platforms. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community it sounds like the BSEC-Library provides functions beyond the raw sensor data to calibrate the sensors and calculate for air quality

1 Like