Wher do I enter lines for a sensor in yaml file

@Arh
Thanks but the pin numbers are invalid, but according to the config variables then said pin numbers are correct for my Esp32, but in the file it says

esphome:
  name: lounge 
  platform: ESP8266
  board: esp01_1m

Why did you specify ESP8266 if it is ESP32 board. Take a look at following which helps with code to specify the correct board.

@JulianDH
Thanks, but I must have had a senior moment…doh!
Anyway I have now changed it to ESP32 and nodemcu-32s as per the link you gave.

Now it’s saying:
NFO Reading configuration /config/esphome/esphome.yaml…
ERROR Error while reading config: Invalid YAML syntax:


Duplicate key "platform"
  in "/config/esphome/esphome.yaml", line 17, column 3:
      platform: bme280
      ^
NOTE: Previous declaration here:
  in "/config/esphome/esphome.yaml", line 11, column 3:
      platform: bh1750
      ^

Try this after all you wifi and board stuff. After ota:

i2c:
  - id: bus_a
    sda: GPIO4
    scl: GPIO5
    scan: true

sensor:
  - platform: bh1750
    i2c_id: bus_a
    name: "Illuminance"
    address: 0x23
    update_interval: 60s

may be worth reading this (disclaimer I have not read it all to confirm it is correct or useful)

What is YAML? A beginner's guide | CircleCI.

How about posting your complete yaml file.

2 Likes
esphome:
  name: lounge
  platform: ESP32
  board: esp32s

wifi:
  ssid: "xxxxxxxx "
  password: "xxxxxxxx"
  
sensor:
  platform: bh1750
  name: "BH1750 Illuminance"
  address: 0x23
  update_interval: 60s
  

  platform: bme280
  temperature:
  name: "BME280 Temperature"
  oversampling: 16x
  pressure:
  
  humidity:
  
  address: 0x77
  update_interval: 60s  
  

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxxxx"

ota:
  password: "xxxxxxxxx"

This yaml :point_up_2: should generate this error :point_down:

So all good I would say. :joy:

Best for you @Rob_Heselwood would be to spend like 5 or 10 minutes reading what YAML is and how it “works”, some link was already posted earlier but feel free to use a search engine of your choice to gather more information :page_facing_up:

Beside if you need further help this post explains how to ask good questions :point_down:

How to help us help you - or How to ask a good question

image

Its really not going to work without knowing where the pins its connected to are, it doesn’t matter how much you struggle with platforms and indentations.

And then try putting a - in front of platform. See my post above.

@orange-assistant
I copied and pasted the lines from the cofigs given for the said sensors. Then I had to remove indentations and duplicate lines like sensor: and others according to any error message I got when validating the yaml file.

Yep lines like sensor: on the first indentation only need to be entered once then every other instance of the same type goes under that heading.

Like this

sensor:

  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s

  - platform: dht
    pin: D4
    temperature:
      name: "Kitchen Temperature"
      filters:
        - offset: -4.5
    humidity:
      name: "Kitchen Humidity"
    #  filters:
      #  - offset: 44
    update_interval: 60s  

  - platform: bh1750
    name: "Kitchen Illuminance"
    address: 0x23
    update_interval: 300s
    
i2c:
  - id: bus_a
    sda: D2
    scl: D1
    scan: true


binary_sensor:
  - platform: gpio
    pin: D5
    name: "Kitchen PIR"
    device_class: motion

web_server:
  port: 80
  version: 2
  include_internal: true
  ota: true

You will see it has a sensors heading with all sensors after it then i2c: with those settings then binary_sensor: with those setting and so on. When you get to grips with it it is easy, And also easy to get wrong :grinning:

After I placed a - in front of platform, then saved and validated it says :slight_smile:

Failed config

esphome: [source /config/esphome/esphome.yaml:2]
  name: lounge
  platform: ESP32
  
  Could not find board 'esp32s'. Valid boards are alksesp32, bpi-bit, d-duino-32, esp-wrover-kit, esp32-devkitlipo, esp32-evb, esp32-gateway, esp32-poe, esp32-poe-iso, esp32-pro, esp320, esp32cam, esp32dev, esp32doit-devkit-v1, esp32thing, esp32vn-iot-uno, espea32, espectro32, espino32, featheresp32, firebeetle32, fm-devkit, frogboard, heltec_wifi_kit_32, heltec_wifi_lora_32, heltec_wifi_lora_32_V2, heltec_wireless_stick, hornbill32dev, hornbill32minima, intorobot, iotaap_magnolia, iotbusio, iotbusproteus, lolin32, lolin_d32, lolin_d32_pro, lopy, lopy4, m5stack-core-esp32, m5stack-fire, m5stack-grey, m5stick-c, magicbit, mhetesp32devkit, mhetesp32minikit, microduino-core-esp32, nano32, nina_w10, node32s, nodemcu-32s, odroid_esp32, onehorse32dev, oroca_edubot, pico32, pocket_32, pycom_gpy, quantum, sparkfun_lora_gateway_1-channel, tinypico, ttgo-lora32-v1, ttgo-t-beam, ttgo-t-watch, ttgo-t1, turta_iot_node, vintlabs-devkit-v1, wemos_d1_mini32, wemosbat, wesp32, widora-air, xinabox_cw02.
  board: esp32s [source /config/esphome/esphome.yaml:4]

My board is a ESP32-WROOM-32, and was ok at one time with another yaml file!!

That error is coming from this configuration:

esphome:
  name: lounge
  platform: ESP32
  board: esp32s

Do you know what board you’re using?

ESP32 has a good number of boards:

It says to use the default of “esp32dev”, so change out “esp32s” for “esp32dev” and try recompile.

Yes I do know what board I am using see the last line above.

If I only have 1 sensor included, the BH1750, it validates without error, but when I add the BME280 sensor there are loads of errors , and I don’t know if they should be indented or not.
I am putting the lines in the same place as the BH1750

Can you please tell what is wrong:

sensor:
  platform: bh1750
  name: "BH1750 Illuminance"
  address: 0x23
  update_interval: 60s
 
 
  
  platform: bme280
  temperature:
  #  name: "BME280 Temperature"
  oversampling: 16x
  pressure:
  #    name: "BME280 Pressure"
  humidity:
   #   name: "BME280 Humidity"
  address: 0x77
  update_interval: 60s

ERROR Error while reading config: Invalid YAML syntax:

Duplicate key “platform”
in “/config/esphome/lounge .yaml”, line 18, column 3:
platform: bme280
^
NOTE: Previous declaration here:
in “/config/esphome/lounge .yaml”, line 11, column 3:
platform: bh1750
^

I should have been clearer. ESP32-WROOM-32 is the chipset on the board, but the PCB/board will be something different.
When the manufacturer of the board lays out the PCB and names the pins, they don’t always follow the ping layout of the WROOM-32 chipset and hence you can have mapping or identification errors, or the inputs/outputs can vary. Also this tells the compiler what features are available on the board and ESP32. This is why each board has a specific name.

As a test, please change “board: esp32s” to “board: esp32dev” and just see if it compiles better.

For reference, I have a ESP32-WROOM-32 here too, and it’s configured as esp32dev and working fine.

I would say you need something more like this

  - platform: bme280
    temperature:
      name: "BME280 Temperature"
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
    humidity:
      name: "BME280 Humidity"
    address: 0x77
    update_interval: 60s

see

remember the - before platform the - means everything after it is one device till it sees another -

without it you will have too many platforms etc

1 Like

Oh, and I also have a BME280 compiling ok with this YAML:

sensor:
  - platform: wifi_signal
    name: "Shed-Sensor WiFi Signal Sensor"
    update_interval: 5s
  - platform: uptime
    name: "${name} Uptime"
  - platform: bme280
    temperature:
      name: "Shed-Sensor Temperature"
      id: bme280_temperature
      accuracy_decimals: 2

Try follow that layout.

@Arh
your lines didn’t compile either:
ERROR Error while reading config: Invalid YAML syntax:

while parsing a block mapping
  in "/config/esphome/lounge .yaml", line 1, column 1:
    esphome:
    ^
expected <block end>, but found '<block mapping start>'
  in "/config/esphome/lounge .yaml", line 17, column 2:
     -platform: bme280
     ^

But with only 1 sensor , BH1750, it compiles no problem???

@Arh
I’m on the verge of giving up , as it is one thing after another. What compiled with 1 sensor, now throws up another error

You need to.post you whole yaml code each time you ask a question as I have No idea what is on line 17 without it. It would solve far quicker if we had all your code.

Ok thanks, that is what I will do now.

ERROR Error while reading config: Invalid YAML syntax:

mapping values are not allowed here
  in "/config/esphome/lounge .yaml", line 18, column 16:
        temperature:
                   ^
esphome:
  name: lounge 
  platform: ESP32
  board: esp32dev

wifi:
  ssid: "xxxxxxxxxx "
  password: "xxxxxxxx"

sensor:
  platform: bh1750
  name: "BH1750 Illuminance"
  address: 0x23
  update_interval: 60s

  
  platform: bme280
    temperature:
      name: "BME280 Temperature"
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
    humidity:
      name: "BME280 Humidity"
    address: 0x77
    update_interval: 60s

  name BME280 
i2c:
  - id: bus_a
    sda: GPIO4
    scl: GPIO5
    scan: true

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxxx"
ota:
  password: "xxxxxxxxl"