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"};
}