Wher do I enter lines for a sensor in yaml file

I have my yaml file up for editing and have entered the wifi ssid and password.

Under that I have this:

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

Where do I add the sensor lines, is it under api??

Thanks

Wherever you want as it is a root yaml tag (means it is at the left border of the editor, no space)

sensor:
  - platform: dht
    pin: D7
    model: dht22
    ... <to be continued> ...
1 Like

Add it to where?

@Olivier1974
No because I entered under wifi section and threw up an error

Same level as api: or ota:

1 Like

The order of where you put sensor: doesn’t matter.

It just needs to be “at level 1” indentation like api: etc.

Typically people put it below the basic config you have there. So after ota:

yaml is very forgiving except with indentations.
it must be at the very beginning of a line

sensor:

1 Like

Ok thanks but just got this error:

Failed config

sensor.bh1750: [source /config/esphome/lounge .yaml:11]
  
  Component sensor.bh1750 requires component i2c.
  platform: bh1750
  name: BH1750 Illuminance
  address: 35
  update_interval: 60s
ap: [source /config/esphome/lounge .yaml:18]

I know what I2C is but how do I enter it in the file??
I copied the lines direct from the sensor page / part.

Here ?

You need this as well

@Rob_Heselwood I commend you to the example code found here and here

@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.