AppDaemon problem running every 2 min

import appdaemon.plugins.hass.hassapi as hass
from datetime import datetime

class AzureStorage(hass.Hass):

  def initialize(self):
    self.run_every(self.backuptoazure,, 2*60)

  def backuptoazure(self):
    self.log("---BACUP TO AZURE---")
    local_path = "/backup"
    onlyfiles = [f for f in listdir(local_path) if isfile(join(local_path, f))]
    for file in onlyfiles:
      self.log("Uploading to Azure Storage as blob:\n\t" + file)

The script fails and I don’t know why. I’ve tried many different things … but can’t manage it to work.

Hi @thunem,

I believe the problem is in the callback function. It needs a kwargs argument. Read more about here.

If this is not the problem, please share error logs so we can help you further.

Xavi M.

1 Like

A few things: You have already imported datetime so the line

 self.run_every(self.backuptoazure,, 2*60)

should be

 self.run_every(self.backuptoazure,, 2*60)

Secondly, the path iteration is wrong. Not sure if this is what you want but try

onlyfiles = [f for f in os.listdir(local_path) if os.path.isfile(os.path.join(local_path, f))]

but this will only list files in /backup and not in subfolders.

And as @xaviml points out, you need to add args to the callback function:

  def backuptoazure(self, args):
1 Like

And of course, you need to import os.

1 Like