Splitting yaml files , access to secrets in ESPHome subfolders

Tags: #<Tag:0x00007fc413574700>

I am trying to split my configuration for better maintainability but I think I am doing something wrong.
My requirement is to put repeated info like mqtt info etc into a common yaml file and then include this in all ESP device yamls I create. While I am able to do this, there are 2 issues I am facing:

  1. I am not able to access the secrets values in the include subfolder inside the ESPHome folder.
  2. One of my requirement is to be able to override newer configuration variables for a component in future in specific device yamls. I dont seem to find a way out of that.

my_device.yaml is as follows:

substitutions:
  base_topic: 'home/tank_controller'
 
esphome:
  name: tank_controller
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret secondary_ssid
  password: !secret secondary_ssid_pswd
   
<<: !include include/mqttinfo.yaml
  
api: 

etc etc

I have the mqtt yaml file in esphome\include\mqttinfo.yaml

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_uname
  password: mqtt_pswd
  topic_prefix: ${base_topic}

For 1 , I get an error
Error reading file /config/esphome/include/secrets.yaml: [Errno 2] No such file or directory: '/config/esphome/include/secrets.yaml'
I tried including the following line in mqttinfo.yaml but still get the same error:
<<: !include ../secrets.yaml
ESPHome doesn’t seem to be following the order of finding the secrets.yaml by going to the parent esphome directory, it keeps searching in the esphome/include.

For 2. I would want to include additional options, for eg. reboot_timeout: 0s in some device yaml in future. like eg below:

my_device.yaml in future:

substitutions:
  base_topic: 'home/tank_controller'
 
esphome:
  name: tank_controller
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret secondary_ssid
  password: !secret secondary_ssid_pswd
   
<<: !include include/mqttinfo.yaml
  reboot_timeout: 0s  

api: 

etc etc

Can somebody help me on both of these.

@VijayS Are you using docker ?

Yes I am using docker. I am using usual hassio install on docker and esphome is an addon.

Having the same problem now. Have you found a fix for it yet?

nope, not yet

You can add a secrets.yaml in the esphome folder in the config directory. You can use !secret now and store the items in that file.

sorry for jumping in this conversation but I have to ask: does this mean that I willl end up with two secrets.yaml files? one for the main configuration.yaml and one inside the esphome folder? is this allowed and this is the way things are supposed to be setup? I am really new at this and I am trying to organize the configurations so I can manage future device integrations.

Yes.

Yes

Yes

Yes.

However if you include this line in the secrets.yaml file that is in the esphome folder:

<<: !include ../secrets.yaml

This will pull all the secrets from your existing secrets.yaml file in the /config folder.

So you can enter the esphome specific secrets in either file, but both must exist.

Also if your home assistant secrets file is not in the root of the /config folder you would have to adjust the include path in the esphome secret file.

Yes, you end up with two secret files. One for hass and one for esphome.

thank you! this is a very clear explanation!

thank you! I understand now!

Hi, I dont think the solution of referring the base secret file from the esphome secret file is straight forward. At least I was not able to make it work the way Otto Winter suggested and how @tom_l has suggested here.
Please see this thread where I raised this issue and ultimately fixed it by compiling a custom version of esphome by making a simple change in the dockerfile. I know everybody may not want to compile a custom version of esphome but then i couldnt make it work any other way.

1 Like

It is if you are running the esphome addon.

Well , maybe you’re right but I wasnt able to make it work when I was running it as an addon in hassio. I always got this error:

cannot merge mappings; the provided source object is unacceptable at line 15, column 58:
     ... assio/homeassistant/secrets.yaml

ESPHome does not look the the secret file there. There is an ESPHome folder in your config dir, after installing ESPHome. You have to add the secrets file there for the items you want to use in the ESP config.

Hi @Lifelogger , that’s exactly I don’t want. I don’t want to maintain two different copies of secrets. I have one secrets in the home assistant config folder and i want to refer to that in esphome. And that’s what I have achieved by what I wrote above.

Ah ok. Didn’t read it properly I guess. :slight_smile:

Hi,
I’m having a similar issue.

I have yaml files in esphome root and the secret.yaml

node1.yaml
node2.yaml
secrets.yaml

and i included some packages in node1.yaml:

packages:
  wifi:                   !include common/wireless.yaml
  tempsensor:     !include components/sensors/dht/dht11.yaml

Now i’m unable to reach secrets.yaml located in esphome root from common/wireless.yaml

I tryed this in wireless yaml

<<: !include ../secrets.yaml
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

but the log reports that is still searching the secrets.yaml inside the /common folder instead of the secrets.yaml located in root.

Could you please help me?
thank you

Your only option is to compile your own version of esphome with the change i mentioned above.

1 Like

Thank you, I hoped something changed in the meanwhile.
The strange thing is that in this official guide:
Configuration Types — ESPHome
The above example about packages it suggest that may work.

Am I wrong or it is an error of the documentation?