Why am I getting an invalid YAML syntax error?

Here is my secrets.yaml

wifi_ssid: xxx
wifi_password: xxx
serenity_password: xxx
miranda_password: xxx
naboo_password: xxx

And my WiFi component:

# Networks
wifi:
  networks:
  - ssid: Kaywinnet
    password: !secret wifi_password
  - ssid: Serenity
    password: !secret serenity_password
  - ssid: Miranda
    password: !secret miranda_password
  - ssid: Naboo
    password: !secret naboo_password

Why am I getting an invalid YAML syntax error in the WiFi component?

yaml

If I comment out the Miranda lines from the wifi component, there’s no error. But I can’t see what is wrong with the Miranda lines. I’ve also made sure there were no TAB characters anywhere.

Any ideas?

line 9 is - ssid: Naboo
Make sure you don’t have a line continuation character in there.

There is a comment at the top of the actual file that I didn’t copy, so the line# is off by one… I’ve added it to the post so that the line number is correct.

Could there be something in the serenity password that messes up the lines after? I would try to put the miranda password above the serenity one and see if the problem moves to naboo.

Are you actually getting an error if you do a configuration validation, or is it only the editor telling you that?

I’ve moved the networks around in the component, but the error is always on ‘miranda’. And always at the exclamation point:
yaml

Both.

INFO Reading configuration /config/esphome/steve-desk-light.yaml...
ERROR Error while reading config: Invalid YAML syntax:

Secret 'miranda_password' not defined
  in "/config/esphome/common/wifi.yaml", line 9, column 15:
        password: !secret miranda_password
                  ^

Would you happen to have multiple “secrets.yaml”?
“/config/esphome/common/wifi.yaml” would read “/config/esphome/common/secrets.yaml”

Holy bleep. I have three.
In:
config
config/esphome.
config/esphome/common

The one that opens when I click on “SECRETS” in the ESPHome panel is where I’ve been adding the passwords.

The one that ESPHome is using is the common folder.

The secrets.yaml in the config folder holds my latitude and longitude, my MQTT broker credentials and various usernames and passwords for external hosts and cameras.

At any rate, adding the Miranda password into the secrets.yaml in the common folder fixed the issue.

if you want to use the same secrets.yaml for both ha and esphome, use this for config in esphome:

<<: !include ../secrets.yaml

Where would I put this?

I don’t have an esphome: component in my configuration.yaml, so I added this:

esphome:
  !include secrets.yaml

and I get no errors with “check configuration”.

Later:
No matter what I try, the packaged component insists that the file should be located in

\esphome\common\secrets.yaml

But, it would be nice if I could only have one secrets.yaml file.

Inside esphome’s secrets.yaml

image

So basically, you’re telling ESPhome to include HA’s secrets.yaml from the parent folder

Thanks. That works.
Since I want just one secrets.yaml file, I put this into the two other secrets.yaml locations:

#U:\esphome\common\secrets.yaml
!include ../../secrets.yaml

# U:\esphome\secrets.yaml
!include ../secrets.yaml

Unless someone can point to the wisdom of three secrets.yaml files?

@stevemann
Hmm… maybe has something to do with the type of installation you are using…
I don’t have \esphome\common\secrets.yaml, I only have one: \esphome\secrets.yaml.

And having \esphome\secrets.yaml as well as HA’s secrets.yaml makes sense; not everyone uses ESPHome as HA addon; it can also be running stand alone, and in that case it would need its own secrets.yaml :face_with_raised_eyebrow:

PS, in your case you’re telling common ESPhome to include ESPhome secrets, and then tell ESPhome secrets to include HA’s secrets.yaml from the parent folder

That only happened when I added some Network Access Points and use different AP names. To make it easier, I moved my wifi: component into a package. This is why the common/secrets.yaml.