Error using secrets.yaml file. ... raise ValueError("{} not found in secrets file".format

I need to know if I am doing something stupid of do I need to post this as an issue?

I think I have the issue boiled down to as simple as possible. I have a app yaml that defines a app. It passes parameters. Some of the parameters are from a secret yaml file. My latitude and longitude works and passes at expected. When I added the device tracker I started getting errors. I can rem it out and the errors go away.

Here is a snippet of the error log.

2018-06-18 09:34:13.287768 INFO AppDaemon: Reading config
2018-06-18 09:34:13.327687 WARNING AppDaemon: ------------------------------------------------------------
2018-06-18 09:34:13.328725 WARNING AppDaemon: Unexpected error loading config file: /config/appdaemon/apps/apps.yaml
2018-06-18 09:34:13.329821 WARNING AppDaemon: ------------------------------------------------------------
2018-06-18 09:34:13.333284 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1674, in read_config_file
    new_config = yaml.load(config_file_contents)
  File "/usr/lib/python3.6/site-packages/yaml/__init__.py", line 72, in load
    return loader.get_single_data()
  File "/usr/lib/python3.6/site-packages/yaml/constructor.py", line 37, in get_single_data
    return self.construct_document(node)
  File "/usr/lib/python3.6/site-packages/yaml/constructor.py", line 46, in construct_document
    for dummy in generator:
  File "/usr/lib/python3.6/site-packages/yaml/constructor.py", line 398, in construct_yaml_map
    value = self.construct_mapping(node)
  File "/usr/lib/python3.6/site-packages/yaml/constructor.py", line 204, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "/usr/lib/python3.6/site-packages/yaml/constructor.py", line 129, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
2018-06-18 09:34:13.335998 WARNING AppDaemon: File '/config/appdaemon/apps/apps.yaml' invalid structure - ignoring
  File "/usr/lib/python3.6/site-packages/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/lib/python3.6/site-packages/appdaemon/utils.py", line 104, in _secret_yaml
    raise ValueError("{} not found in secrets file".format(node.value))
ValueError: device_tracker_paul not found in secrets file
2018-06-18 09:34:13.337075 INFO AppDaemon: /config/appdaemon/apps/apps.yaml added or modified
2018-06-18 09:34:13.334444 WARNING AppDaemon: ------------------------------------------------------------

I am including all 3 files.
Secrets.yaml

latitude: 3
longitude: -9
device_tracker_paul: google_maps_xxxxxxxxxxxxxxxxxxxxxx

apps.yaml

tell_nancy_paul_is_on_his_way:
  module: on_way_home_notify
  class: on_way_home_notify
  home_coord_lat : !secret latitude
  home_coord_lon : !secret longitude
  devicetracker_coord : !secret device_tracker_paul
  send_alert_to : "textalertsnancy"
  toggle_switch : "paul_on_way_home_switch"
  send_alert_from : "Paul"

on_way_home_notify.py

import appdaemon.plugins.hass.hassapi as hass
import json
import urllib

class on_way_home_notify(hass.Hass):

  def send_text_callback(self, entity, attribute, old, new, kwargs):
    self.log("callback started")
    dest_coord_lat = self.args["home_coord_lat"]
    dest_coord_lon = self.args["home_coord_lon"]
    orig_coord_lat = self.get_state(entity = "device_tracker." + self.args["devicetracker_coord"], attribute = "latitude")
    orig_coord_lon = self.get_state(entity = "device_tracker." + self.args["devicetracker_coord"], attribute = "longitude")
    url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins={0},{1}&destinations={2},{3}&mode=driving&language=en-EN&sensor=false".format(str(orig_coord_lat),str(orig_coord_lon),str(dest_coord_lat),str(dest_coord_lon))   
    result = json.load(urllib.request.urlopen(url))
    self.log("\n***********************************************\n" +
             url +
             "\n*********\n" +
             json.dumps(result) +
             "\n***********************************************\n")
    driving_time = result['rows'][0]['elements'][0]['duration']['text']
    origin_addresses = result['origin_addresses'][0]
    self.log(driving_time)
    self.log(origin_addresses)
    message = self.args["send_alert_from"] + " is on his way home." + "\nThey will be there in about " + driving_time + "\nLeaving from " + origin_addresses
    self.log("\n***********************************************\n" +
             message +
             "\n***********************************************\n")
    #self.call_service("notify/textalertspaul",title="",message=message)
    #self.call_service("notify/textalertsnancy",title="",message=message)
    
  def initialize(self):
    self.listen_state(self.send_text_callback,
                      "switch." + self.args["toggle_switch"],
                      new="on")
    self.log("Automaintion initialize.")

The secret yaml names (values) has been changed to protect the innocent. Ok, you would need to be a child of the 60’s whose parents watched Dragnet to get that one.

Also, if I want to use the secrets.yaml for HA, would the secret: look like …secerts.yaml ? To reference the directory above?

I think I know now what was happening. Bottom line the secret.yaml is cached and not refreshed.
I finally figured out what was confusing me. I thought maybe I was using something reserved. So I started using test and it was saying, could not find test. Then I restarted appdaemon and it read it. So, I copied back the secrets file from the HA and restarted appdaemon all worked as expected. No big deal, but maybe you can add secrets file to the “auto refresh”. Again, no big deal, not like it gets changed very often, just as I was debugging my app and sanitizing it by adding hidden parameters to the secrets file, it would be cool to refresh same as app.yaml and app.py.

Also, I noticed when I was testing the secret: override in the appdaemon.yaml I typed it wrong. So I retested using …secrets.yaml. I tested by deleting my secrets.yaml file in the appdaemon directory. Then restarting. I was getting could not find …secrets.yaml errors. I rem out the entry in the appdaemon.yaml. Then got missing secrets.yaml (no back up directory dots). I copied the secrets.yaml file from the HA config directory and all works.

Can you specify the HA config directory? If so how do you do it running Hass.io sandbox?

2 things.

  1. secrets was created to put secrets in appdaemon.yaml and is not supported for use inside apps at this time.
  2. in hassio it is probably not possible to reuse the HA secrets. thats because it are 2 seperate addons that cant see each other due to rights. it would be possible if you could set the rights from files yourselve and specify the complete path. sorry there are a lot of things you cant do in hassio that you can do in another environment. hassio is developed to give users an easy to use environment, the things you want belong to an advanced environment.

oops… Well it seems to work. Well, it works if you refresh and copy it. :slight_smile:

I hear you. I been experimenting with it for a while. I think as I get more serious I will need to go with some more powerful and reliable. I will do more research when the times comes. :slight_smile:
Thanks again for your work.

1 Like

it works and it doesnt work :wink:
to work with it you lose the biggest power from AD a little. the fact that you can program on the fly.
but i am glad you pointed that out to me, because there are others that wanted to use secrets in the yaml too. so if its asked again i can tell that its possible this way.