Yaml error block end

Hi,

I’m new into HA and trying to configure my nodemcuv3 with esphome.
Have 2 sensors attached to it.

esphome:
  name: test-dev

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "guesswhat"

ota:
  password: "guesswhat"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test-Dev Fallback Hotspot"
    password: guesswhat

i2c:
 sda:D1
 scl:D2
 scan:true
 id:bus_a
 
 sda:D5
 scl:D6
 scan:true
 id:bus_a

# Example configuration entry
  - platform: bme280
   temperature:
    name: "Temperatuur"
    oversampling: 16x
   pressure:
    name: "Luchtdruk"
   humidity:
    name: "Vochtigheid"
   i2c_id: bus_a
   address: 0x76
   update_interval: 60s
# ...
# Example configuration entry
 - platform: bh1750
   name: "Lux"
   i2c_id: bus_b  
   address: 0x23
   update_interval: 60s
# ...
INFO Reading configuration /config/esphome/test-dev.yaml...
ERROR Error while reading config: Invalid YAML syntax:

while parsing a block mapping
  in "/config/esphome/test-dev.yaml", line 1, column 1:
    esphome:
    ^
expected <block end>, but found '<block sequence start>'
  in "/config/esphome/test-dev.yaml", line 39, column 3:
      - platform: bme280
      ^

If someone can help me with this, yaml is also new to me. The nodemcu is running with a smaller config and works like a charm, with one sensor, but cant get that code back, is that also possible with esphome?

multiple problem I’d say.

first hint … you have to handle the errors bottom up … means no time to waste with the eshome error.

since so … what might be wrong with line 39 column 3?
the line itself looks pretty good on the first look.
But what does it belong to?
i2c: since that’s the last “:” ? Looks to me as if it should be a “sensor:” but it’s not declared.

if you solved that one.

next hint
remember indentation is not optional. if YAML requires things to be indented by 2 spaces then this is a must not something optional. Yeah I also like YAML because of being unable to handle such things similar to more common lanuages.

Have fun with the hints

I’m getting there now, but little stuck on this one:

INFO Reading configuration /config/esphome/test-dev.yaml...
ERROR Error while reading config: Invalid YAML syntax:

while parsing a block mapping
  in "/config/esphome/test-dev.yaml", line 40, column 5:
      - platform: bme280
        ^
expected <block end>, but found '-'
  in "/config/esphome/test-dev.yaml", line 53, column 5:
        - platform: bh1750
i2c:
 sda:D1
 scl:D2
 scan:true
 id:bus_a
 
 sda:D5
 scl:D6
 scan:true
 id:bus_b

# Example configuration entry
sensor:
  - platform: bme280
    temperature:
     name: "Temperatuur"
    oversampling: 16x
    pressure:
     name: "Luchtdruk"
    humidity:
     name: "Vochtigheid"
     i2c_id: bus_a
    address: 0x76
    update_interval: 60s
# ...
# Example configuration entry
    - platform: bh1750
       name: "BH1750 Illuminance"
      i2c_id: bus_b  
      address: 0x23
      update_interval: 60s
# ...

I read I²C Bus — ESPHome but is that article then false information?

Indenting is everything in yaml. You sometimes indent only one space extra, it should be 2. You seem to specify 2 buses, but you do not folow the specification for 2 buses you yourself linked to.

It would something be, but I still dont understand yaml, getting a litte confused of all the different methods and codes.

I hashed it out, so at least one sensor is working.
If someone could line it up good for me, I think I can understand it, and look for myself what I did wrong.

i2c:
  sda: D1
  scl: D2
  scan: true
  id: bus_a

#    sda: D5
#    scl: D6
#    scan: true
#    id: bus_b

# Example configuration entry
sensor:
  - platform: bme280
    temperature:
      name: "Temperatuur"
      oversampling: 16x
    pressure:
      name: "Luchtdruk"
    humidity:
      name: "Vochtigheid"
    address: 0x76
    update_interval: 60s
    i2c_id: bus_a
# ...
# Example configuration entry
   # - platform: bh1750
     # name: "BH1750 Illuminance"
       # i2c_id: bus_b  
     # address: 0x23
     # update_interval: 60s
# ...

Indenting looks better now, the example for 2 buses is right there in the note at the bottom of the documentation you yourself linked to:

 # Example configuration entry
i2c:
  - id: bus_a
    sda: D1
    scl: D2
    scan: true
  - id: bus_b
    sda: D5
    scl: D6
    scan: true
# Sensors should be specified as follows
sensor:
  - platform: bme280
    i2c_id: bus_a
    address: 0x76
  # ...

yes I have it working now, sort of. The bme sensor saying communication error and lux sensor gives data.
When I hash out the i2x bus_b and the bh1750 sensor, the bme sensor does work again.
What could that be? Limitation of the board or did I choose wrong pins?

nodemcu layout:
https://images.theengineeringprojects.com/image/webp/2018/10/Introduction-to-NodeMCU-V3-2.png.webp?ssl=1

current code

i2c:
  - id: bus_a
    sda: D1
    scl: D2
    scan: false
#  - id: bus_b
#    sda: D5
#    scl: D6
#    scan: false

# Example configuration entry
sensor:
  - platform: bme280
    temperature:
      name: "Temperatuur"
      oversampling: 16x
    pressure:
      name: "Luchtdruk"
    humidity:
      name: "Vochtigheid"
    i2c_id: bus_a
    address: 0x76
    update_interval: 60s
    # ...
# Example configuration entry
#  - platform: bh1750
#    name: "BH1750 Illuminance"
#    i2c_id: bus_b  
#    address: 0x23
#    update_interval: 60s

If only 1 sensor fails while the other one works it’s pretty unlikely you used the wrong pins.

a example pics with a more complete pinout. Check yourself if you got a v2 or v2.x nodemcu and then make sure to define the correct one in the esp8266: board: section of your code.
Though it won’t make a differnce since both the v2 and v3 have D1 & D2 at the same pins.

Something which looked strange to me.
D1 should be SCL and D2 should be SDA … that the common way.

Perhaps you simply mixed up the cabels … double check all 3 devices have SDA connected to SDA and same for SCL.


Hi, I have the nodeMCU V3 layout.
I switched the d1 and d2 and changed the script. But it still does the same error unfortunately.

[08:24:54][C][logger:277]:   Log Baud Rate: 115200
[08:24:54][C][logger:278]:   Hardware UART: UART0
[08:24:54][C][i2c.arduino:038]: I2C Bus:
[08:24:54][C][i2c.arduino:039]:   SDA Pin: GPIO4
[08:24:54][C][i2c.arduino:040]:   SCL Pin: GPIO5
[08:24:54][C][i2c.arduino:041]:   Frequency: 50000 Hz
[08:24:54][C][i2c.arduino:044]:   Recovery: bus successfully recovered
[08:24:54][C][i2c.arduino:038]: I2C Bus:
[08:24:54][C][i2c.arduino:039]:   SDA Pin: GPIO14
[08:24:54][C][i2c.arduino:040]:   SCL Pin: GPIO12
[08:24:54][C][i2c.arduino:041]:   Frequency: 50000 Hz
[08:24:54][C][i2c.arduino:044]:   Recovery: bus successfully recovered
[08:24:54][C][bme280.sensor:174]: BME280:
[08:24:54][C][bme280.sensor:175]:   Address: 0x76
[08:24:54][E][bme280.sensor:178]: Communication with BME280 failed!
[08:24:54][C][bme280.sensor:187]:   IIR Filter: OFF
[08:24:54][C][bme280.sensor:188]:   Update Interval: 60.0s
[08:24:54][C][bme280.sensor:190]:   Temperature 'Temperatuur'
[08:24:54][C][bme280.sensor:190]:     Device Class: 'temperature'
[08:24:54][C][bme280.sensor:190]:     State Class: 'measurement'
[08:24:54][C][bme280.sensor:190]:     Unit of Measurement: '°C'
[08:24:54][C][bme280.sensor:190]:     Accuracy Decimals: 1
[08:24:54][C][bme280.sensor:191]:     Oversampling: 16x
[08:24:54][C][bme280.sensor:192]:   Pressure 'Luchtdruk'
[08:24:54][C][bme280.sensor:192]:     Device Class: 'pressure'
[08:24:54][C][bme280.sensor:192]:     State Class: 'measurement'
[08:24:54][C][bme280.sensor:192]:     Unit of Measurement: 'hPa'
[08:24:54][C][bme280.sensor:192]:     Accuracy Decimals: 1
[08:24:54][C][bme280.sensor:193]:     Oversampling: 16x
[08:24:54][C][bme280.sensor:194]:   Humidity 'Vochtigheid'
[08:24:54][C][bme280.sensor:194]:     Device Class: 'humidity'
[08:24:54][C][bme280.sensor:194]:     State Class: 'measurement'
[08:24:54][C][bme280.sensor:194]:     Unit of Measurement: '%'
[08:24:54][C][bme280.sensor:194]:     Accuracy Decimals: 1
[08:24:54][C][bme280.sensor:195]:     Oversampling: 16x
[08:24:54][C][bh1750.sensor:118]: BH1750 'BH1750 Illuminance'
[08:24:54][C][bh1750.sensor:118]:   Device Class: 'illuminance'
[08:24:54][C][bh1750.sensor:118]:   State Class: 'measurement'
[08:24:54][C][bh1750.sensor:118]:   Unit of Measurement: 'lx'
[08:24:54][C][bh1750.sensor:118]:   Accuracy Decimals: 1
[08:24:54][C][bh1750.sensor:119]:   Address: 0x23
[08:24:54][C][bh1750.sensor:124]:   Update Interval: 60.0s
[08:24:54][C][mdns:100]: mDNS:
[08:24:54][C][mdns:101]:   Hostname: test-dev
[08:24:54][C][ota:089]: Over-The-Air Updates:
[08:24:54][C][ota:090]:   Address: test-dev.local:8266
[08:24:54][C][ota:093]:   Using Password.
[08:24:54][C][api:138]: API Server:
[08:24:54][C][api:139]:   Address: test-dev.local:6053
[08:24:54][C][api:141]:   Using noise encryption: YES
[08:25:03][D][api:102]: Accepted 192.168.1.46
[08:25:04][D][api.connection:917]: Home Assistant 2022.11.1 (192.168.1.46): Connected successfully
[08:25:15][D][bh1750.sensor:159]: 'BH1750 Illuminance': Got illuminance=226.4lx

Question, can I do 2 sensors on the same D1 and D2 pin with soldering, when the adresses in i2c are different from the sensors or insn’t it?

Yes you can run many devices off of a single i2c if the devices allow different addresses.

I make these for the purpose (I also make them for ground/power).

It might also depend upon which sensor (bme) you got. Some do work at address 0x76 and some at address 0x77. Most of them offers selecting by connecting an additional pin to gnd if I remember right.

Please use

logger:
  level: debug

then you’ll get much more information about if the sensor is detected and at which address it was detected.
And before using cable to make the sensor run at 0x76 it’s easier to use 0x77 in the code. :slight_smile:

hi, I adressed it already on 0x76
[08:24:54][C][bme280.sensor:174]: BME280:
[08:24:54][C][bme280.sensor:175]: Address: 0x76

And he works good, but when in combination with the bh1750 on the other pins, only the bh1750 will work.

Nice, like to see that. I will take a look in my drawers if I can find some rails for this. Maybe Ali is quicker :wink:

Here’s a dump of some parts on Ali I really like. They are old links so search around for newer/similar.

Double row and right angle headers:

Flexible Silicone wire (great for small enclosures):

Vero board:

Crimper (See Adreas Spiess Youtube reviews): IWS-2820M - Buy IWS-2820M with free shipping on AliExpress

Dupont headers/connectors:

What other pins? Perhaps you could post you actual code again (the sensor section)
I only used a TSL2591 in the past and that gave no problems.
Some sensors are critical on the i2c clockspeed, but I never heard about the BH1750 being amongst these.
No hints given if you turn logger: level to verbose or even very_verbose?

I fixed it with the 2 sensors on the same D1+D2 pin.
Removed the bus identity.
Will now ask the neighbour to print a nice enclosure for all.