Accessing home assistant copy of secrets.yaml from ESPHome

Hi, I am trying to reuse the secrets.yaml from the home assistant folder in the esphome secrets.yaml as described by Otto Winter here. I am unable to do that as I get the error :

Error reading file /config/../secrets.yaml: [Errno 2] No such file or directory: '/config/../secrets.yaml'

My config files are as under:
My HA secrets.yaml is under the ~/home_assistant folder
The secrets.yaml in ~/home_assistant folder/esphome just contains :
<<: !include ../secrets.yaml

I am running esphome on Ubuntu as a docker image and use the following command to run esphome:

docker run  -d --restart  always --name esphome --net=host -v ~/home_assistant/esphome:/config -v /dev:/dev -v  -it esphome/esphome:latest

As you can see I have mapped the volume as: ~/home_assistant/esphome folder to the esphome config folder

My question is : Is the error that I am getting expected as the esphome docker container does not have access to the parent folder ~/home_assistant ? But then I am not able to find out how to give access to this folder. I tried modifying the volume to a level up but then esphome starts showing all HA yamls as esphome projects rather than showing yaml files from esphome folder. i.e. if if do the following

docker run  -d --restart  always --name esphome --net=host -v ~/home_assistant:/config -v /dev:/dev -v  -it esphome/esphome:latest

Also, the error that I get is "/config/../secrets.yaml" does not exist instead of
"/config/esphome/secrets.yaml" does not exist. I think this should give a clue to what am doing wrong but I am not able to get it.
I am sure I am doing something silly here, can somebody help?

a … in the middle of the path won’t work, have you tried absolute path?


if that does not work, and you really don’t want to keep two copies, you could try to make a symlink

ln -s /config/esphome/secrets.yaml /config/secrets.yaml

Can’t promise it will work though…

I got esphome running atm, but can’t really test this right now… I can test it out tomorrow if you don’t get it working.

Hi @kurtj , I tried the absolute path too and it doesnt work, results below:

<<: !include /home/vijay/home_assistant/secrets.yaml

Error reading file /home/vijay/home_assistant/secrets.yaml: [Errno 2] No such file or directory: '/home/vijay/home_assistant/secrets.yaml'

Also, ls -l for this file gives

vijay@E6410-UBUNTU:~$ ls -l /home/vijay/home_assistant/secrets.yaml
-rw-rw-rw- 1 vijay vijay 732 Mar 14 23:36 /home/vijay/home_assistant/secrets.yaml

I believe the issue here is that the parent directory should not be accessible to the docker container file system and that’s why it doesn’t work. But then how has the ESPHome documentation proposed this solution?

I think I have got part of the problem but not the other half.
I saw the default installation of esphome on hassio and there it maps the HA config directory as the /config for esphome, which makes sense. Now esphome has access to the parent directory. But the issue that still needs to be solved is how do I tell esphome that my yaml files are in /config/esphome and not in /config. I dont seem to find a way to specify it.

Here are the mounts on the hassio install of esphome. The /data mount is used for specifying the options for esphome , so that doesn’t seem to be of interest here.

[{bind  /usr/share/hassio/addons/data/15ef4d2f_esphome /data  rw true rprivate} {bind  /usr/share/hassio/homeassistant /config  rw true rprivate} {bind  /usr/share/hassio/ssl /ssl  ro false rprivate}]

On the other hand I tried doing it on the hassio install and it also doesnt allow me to map the parent secrets.yaml in HA config folder - but with a different error, irrespective of if I give a relative path or absolute path.

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

Why not hard link the secrets file and go back to the original set up?

I dont want to do that as I need things to be in code than steps & code.
I think I near a solution. TH eonly thing I still need to find out is how to set the working directory for the esphome dashboard. It currently is taking /config as the working directory while I need to specify /config/esphome.

That makes no sense.

Well, if it doesnt make sense then it could be that I did not understand your proposal or the other way :slight_smile:
I understood your suggestion as to use a symlink for this. While I can do that, there are 2 reasons I wouldn’t prefer this:

  1. There is already a documented way to do this via the config file. If somebody can tell me , what I am trying to do is different from that and maybe not possible I am happy to look at other solutions.
  2. Symlink solution is a step outside of code. My preference would be to do it within code.
    That said, if nothing works out I am happy to fallback to the symlink solution.

I did not suggest a symlink. I suggested a hard link.

oh well! then that falls in the same category of reasons for me. Anyway, thanks for the suggestion, your solution can certainly work but I am still insistent on finding a code solution to this.

And I have found one and it works although with some tweaks in the esphome code. So, in a way not so elegant but works
I went through the code of esphome to see why is the dashboard picking up the /config directory than picking up the config/esphome directory as that was the only issue left to be sorted out from my previous comments. I found this to be because of the following line in the Dockerfile :

CMD ["/config", "dashboard"]

I changed it to :

CMD ["/config/esphome", "dashboard"]

And everything works well. I build a new image of the docker file and bang! Now I can access the parent directory from esphome and the dashboard also shows the yamls in /config/esphome. I can maintain a single copy of secrets.yaml in the home assistant config.

That said, I am sure if Ottowinter has documented this, it should work out of the box but I don’t know why would i have to make this change.

1 Like