I recently updated Home Assistant to 2021.12.0 and ESPHome to 2021.12.0. Prior to the update, my yaml files for a NodeMCU would compile fine with substitutions used in a variable name for a secret. After the update, I get an error. My system also crashed during the update and I had to restore from a backup so it’s possible something else is going on here. Anyway, anyone else using substitutions in secret names successfully??
My NodeMCU yaml file (frame-b-status.yaml):
# This is a NodeMCU used to monitor the program run status for Frame B.
substitutions:
# Variables
frame: 'Frame B'
frame_strict: 'frame-b' # must be [a-z] [0-9] or - or _
########################
## Unique Node Config ##
########################
# Enable Home Assistant API
api:
password: !secret ${frame_strict}_api-ota_password
ota:
password: !secret ${frame_strict}_api-ota_password
wifi:
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
password: !secret ${frame_strict}_fallback_hotspot_password
########################
## Common Node Config ##
########################
<<: !include common_config-V1-3.yaml
# Note, I haven't shown the contents of the common config since I don't
# think it is relevant. I can certainly add it if necessary.
My secrets.yaml file:
# All the passwords for my ESPHome devices
wifi_ssid_password: "monkey"
frame-b_api-ota_password: "monkey2"
frame-b_fallback_hotspot_password: "monkey3"
And the error I’m getting:
INFO Reading configuration /config/esphome/frame-b-status.yaml...
ERROR Error while reading config: Invalid YAML syntax:
Secret '${frame_strict}_api-ota_password' not defined
in "/config/esphome/frame-b-status.yaml", line 14, column 13:
password: !secret ${frame_strict}_api-ot ...
^
So it seems like the variable ${frame_strict} isn’t getting replaced with the value frame-b before the search for the secret name takes place.
The thing is, this compiled fine yesterday and I have the code running on a NodeMCU… could this be a bug in the ESPHome 2021.12.0 release?
Unfortunately not. It wasn’t too big a deal for me though. I was planning on using unique passwords for the series of devices but instead I’m just using the same password for each device now.