Understanding the initialize function and times

I have a simple appdaemon app that will notify on a Tuesday to take out the trash.
Something simple to get started.

import hassapi as hass
import datetime

#App to send notification on day trash is to be taken outside
#Args:
#input_select: input select to identify trash day --not implemented

class TrashNotification(hass.Hass):
    def initialize(self):
        self.trashday = 'Tuesday'
        self.currentday = datetime.datetime.today().strftime('%A')
        runtime = datetime.time(7, 30,0)

        self.run_daily(self.notifytrash,runtime)

    def notifytrash(self, kwargs):
        if self.trashday == self.currentday:
            self.notify("🗑️️Dont forget to clean out all the bins.", title = "Trash day today!")

I havent implemented any arguments yet, just want to get the basics straight.
My questions are as follows:
1)Where is the correct place to define and assign my comparison variable currentday?
As i understand is once initialized is run once, until a callback is returned, the variables will remain with their values unchanged. So the currentday variable will not be updated daily?

2)is self.run_daily the best way to trigger a callback that will only run once a week?
Im only executing the notify if the day condition is correct, but maybe i could register the callback differently?
Looking through the documentation i cant see any better methods.

I hope ive explained my questions properly.
Thanks :slight_smile:

self.currentday will not change unless appdaemon is restarted since it is in the initialize function, so you need to move that to the callback. Otherwise, it looks fine.

Now you can implement an input_boolean that is off by default and turns on when its trashtime, and then you can repeat the notification every hour until you confirm that the trash has been taken out by resetting the input_boolean in the UI, or even better, put some sensor on the trashcan to verify that it has been moved!

1 Like

Thank you for the advice.
I appreciate it.
I may use a vibration sensor to confirm that the trash has been taken out. Good idea!