Splitting yaml files , access to secrets in ESPHome subfolders

hi, unfortunately I’m unable to reach the esphome secret file from any subfolder.
I’ve tried to do so packages but without success.

The way I’m doing this is to assign the secrets to substitutions in my main file and then just use the substitution variables everywhere else.

That works. Mostly. I think I found one case where it didn’t work and that was for the esphome.build_path.

could you please write an example?

thank you

Hi, I provided most of the files in another post.

1 Like

I see you put secrets.yaml in a subfolder with wifi.yaml. In this way works also for me. What I’m unable to do is reaching secrets.yaml from a subfolder (/common/wifi.yaml).

The secrets file has to be in the same folder as the yaml.

I’ve changed my config now so that all the secrets are in the root. The root yaml accesses them in substitutions. Other yaml files can use substitutions more easily.

I’m curious why the documentation has an incomplete example showing it is possible:
Configuration Types — ESPHome

I can’t see any references to secrets in subfolders on that page. Packages yes. Packages in subfolders work fine and I make extensive use of them so that I can keep my main YAML as simple as possible and reusable across multiple device types.

sorry I meant I can’t reach secrets from a package in a subfolder:

I cannot reach secrets in a parent folder from a package in a subfolder.

<<: !include ../../secrets.yaml

I hope i did explain better

No, I don’t think that works. Instead use the root file to assign secrets to substitutions and use those.

since it’s/ I’m on a linux OS, I solved this by creating a symbolic link. Login through ssh and cd into the correct folder.

ln -s ../secrets.yaml

I am only using that secrets file for Esphome. I am not sharing secrets between HA and ESPH.
However, I can see this should also work in that scenario.
I do not know (yet) if this will survive any updates.

1 Like

Now that HASSIO bought ESPHOME it would be interesting to integrate secret files.
:slight_smile:

I’m not comfortable moving those files in subfolders. I suppose there might be security reasons.

well all this was supposed to make order in root files :slight_smile:

Create a new secrets.yaml file in the common folder and include the single line <<: !include ../secrets.yaml in that file.
Don’t add this include to your device configuration.

2 Likes

You can use links on Windows and Mac as well.

that’s a great tip however it’s curious we still need to use a workaround also after 2021.12 update that uses the wizard to import wifi credential from the main secret file.