[SOLVED] Hassio - Appdaemon text file path

HiI have an automation for presence that I am trying to get to TTS a message when someone arrives home.
I am trying to read a line from an external txt file randomly to play.

I seem to have it all working, but an receiving a file not found to the txt file when it tries to read the file
See the example function below

def getWelcomeMessage(self, name):
        with open ('welcome.txt') as f:
           welcome = f.read().splitlines()
       random.shuffle(welcome)
       quote = (random.choice(welcome)) %(name)
       return quote

I have welcome.txt located in the apps directory where the App is located. I get the following error in the log

2018-03-03 10:28:43.368401 WARNING Unexpected error in worker for App auto_turn_on_off_presence_lia:
2018-03-03 10:28:43.370489 WARNING Worker Ags: {'name': 'auto_turn_on_off_presence_lia', 'id': UUID('b6345ec9-60e3-48a0-865e-02adee6239d0'), 'type': 'attr', 'function': <bound method AutoTurnOffPresence.presenceChange of <auto_turn_on_off_presence.AutoTurnOffPresence object at 0x746c3590>>, 'attribute': 'state', 'entity': 'device_tracker.lia_iphone_lia', 'new_state': 'home', 'old_state': 'home', 'kwargs': {}}
2018-03-03 10:28:43.372991 WARNING ------------------------------------------------------------
2018-03-03 10:28:43.394416 WARNING Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 512, in worker
    utils.sanitize_state_kwargs(args["kwargs"]))
  File "/config/appdaemon/apps/auto_turn_on_off_presence.py", line 42, in presenceChange
    self.arriveHome()
  File "/config/appdaemon/apps/auto_turn_on_off_presence.py", line 62, in arriveHome
    welcomeMessage = self.getWelcomeMessage(self.args["name"])
  File "/config/appdaemon/apps/auto_turn_on_off_presence.py", line 93, in getWelcomeMessage
    with open ('welcome.txt') as f:
FileNotFoundError: [Errno 2] No such file or directory: welcome.txt'

I am using Hassio and AppDaemon2 - What Path should i use to the file? Or should I located the text file in another location?

thanks

You just need to use the full path to the file rather than just the filename.

Great thanks. That worked

1 Like