Esphome secrets file

Hi guys, I’m trying to create a secret file on esphome YAML but when I try to run the code it gives me this:

PS C:\Coding\Home Assistant\Water Temp\Test> esphome run test.yml
INFO Reading configuration test.yml...
Failed config

WifiSsid: [source secrets.yaml:2]

  Component not found: WifiSsid.
  !secret WifiSsid
WifiPassword: [source secrets.yaml:3]

  Component not found: WifiPassword.
  !secret WifiPassword
PhoneNumber: [source secrets.yaml:6]

  Component not found: PhoneNumber.
  !secret PhoneNumber

this is my code:

<<: !include secrets.yaml


esphome:
  name: hot-lake
  platform: ESP32
  board: esp32dev





# Enable logging
logger:
  baud_rate: 0
  level: VERBOSE


# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: !secret WifiSsid
  password: !secret WifiPassword

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Hot-Water-Lake-Esp32"
    password: "iAZP1T0BOxke"

captive_portal:



# defining sensors:

# relay:
switch:
  - platform: gpio
    name: "Relay"
    id: relay_1
    pin: GPIO26

# sim:
uart:
  baud_rate: 9600
  tx_pin: GPIO1
  rx_pin: GPIO3


sim800l:


# dallas temperature sensor:
dallas:
  - pin: GPIO32


# conditions:

sensor:




  - platform: dallas
    address: 0x2e0319a27968ac28
    name: "Water Temperature ESP32"

    on_value_range:
      - below: 24.0
        then:
        - sim800l.send_sms:
            recipient: !secret PhoneNumber
            message: Cold
      - above: 32.0
        then:
        - sim800l.send_sms:
            recipient: !secret PhoneNumber
            message: Hot





binary_sensor:
  - platform: sim800l
    registered:
      name: "Sim800L Registered"


  - platform: gpio
    pin: GPIO25
    name: "Button"

    on_press:
      then:
        - sim800l.send_sms:
            recipient: !secret PhoneNumber
            message: Hot



# deep_sleep:
#   run_duration: 2min
#   sleep_duration: 58min

this is my secrets file:

#  wifi password and ssid
WifiSsid: XXX
WifiPassword: XXX

# phone number 
PhoneNumber: '+XXX'

Does anybody have an idea how to solve it?
Thanks for the help :slight_smile:

You don’t need to include the secrets.yaml file like this - instead it’s automatically found in the same directory as your device config file.

By including the secrets.yaml the way you did, ESPHome is trying to interpret its content as device config and hence tries to find those things as components.

thanks a lot it’s working

1 Like

Hi
I need add multiple phone numbers in secret file and in my program make this condition which any of that phone numbers was the sender, accept them.
would you please help me to write multiple phone number in one heading, in correct format, in secret file, and point it out correctly in my program.

#...
- if:
        condition:

          - lambda: |-

              return (id(sms_message).state == "esp relay state") && ((id(sms_sender).state == !secret PhoneNumber " ));

        then:
#...