HABApp - Scheduling next level?!

With version 0.3 HABApp restructured scheduling an introduced some new scheduling mechanisms like countdown.

Compared to the cron syntax with DSL rules i am missing soem features or a least there are not so easy to build.

I found out that a start time for an schedule needs to be in the future. So if i like to start a schedulrr exact on every hour i have to calculate the next start.

self.run.every(time(datetime.now().hour+1, 0, 0), timedelta(hours=1), self.myfunction)

It would be easier to write

self.run.every(0, 0, 0), timedelta(hours=1), self.myfunction)

and the scheduler starts at the next proper time.

Another thing ist that the starttime has no overflow mechanism, so we have to check if there is an overflow when adding some value. So the following will lead to an error if datetime.now.hour is 23

time(datetime.now().hour+1, 0, 0)

because for hours only allows values between 0 and 23.

So based on these two restrictions i am looking for some easy, elegant solutions to define my schedulers.

To be honest i have not checked the datetime module in deapth.

What kind of scheduler did you define with HABApp and how they are established?

Thomas

Sorry for bumping old thread, but you helped me and I got the same problem. I solved the “overflow” with a mod operator.

Getting better but still not great in coding python I had some problems to get the syntax right for the run.every-scheduler call.

        self.run.every(start_time=time(hour=self.next_hour(), minute=0, second=1), interval=timedelta(hours=1), callback=self.my_method)

    @staticmethod
    def next_hour():
        return (datetime.now().hour + 1) % 24

Most nice would have been if any non important time-setting could be omitted (this was my first attempt):

#not valid
self.run.every(start_time=time(minute=0, second=1), interval=timedelta(hours=1), callback=self.my_method)

Another syntax that I considered was a timedelta with minutes left to next full hour, however with this syntax its harder to control execution “seconds”-part. At least this is how I would expect a start_time=timedelta-definition start to behave??

self.run.every(start_time=timedelta(minutes=60-datetime.now().minute).. )