Why run_every and run_hourly not working for me?

Hi y’all,

I have tried both run_every and run_hourly but they never trigger the callback.
I know, there are several threads about it, but it doesn’t help me at all. I can’t understand why my code would not work.
I can call my class from HA and it runs all fine, so the rest of the class is properly working.

This is my latest init code:

class UpdateDisplay(Hass):
    def initialize(self):
        self.listen_event(self.generate_chart, CHART_EVENT)
        # round to the next full hour
        t = datetime.now()
        t -= timedelta(minutes = t.minute, seconds = t.second, microseconds =  t.microsecond)
        t += timedelta(hours = 1)
        self.log(f'Starting hourly from {t}')
        self.run_every(self.generate_chart, t, 60*60)

    def generate_chart(self, event, data, kwargs):
        # Do stuff

The timestamp looks proper in the logs, no complaints about the run_every being faulty. But still no hourly runs.
It would be nice to get the scheduling completely encapsulated in the class instead of relying on HA to do that.

Help, pretty please

Can answer myself now.
Scheduling callbacks are weird and I found a working way through an issue discussion. Not so intuitive, but it works.

Callbacks have a (self, kwargs) signature, must be called with a proxy function to get it working.

class BigDisplayChart(Hass):
    def initialize(self):
        t  = datetime.now() ...
        self.run_every(self.callback, t, 60*60)

    def callback(self, kwargs):
        self.generate_chart(None, None, kwargs)

    def generate_chart(self, event, data, kwargs):
        ...

With this mid interceptor I have it running every hour.

Correct that works but, your generate_chart() method has a signature that is expected for a listen_event() callback signature. If generate_chart() is not being called by an event then fix the signature so you don’t have to pass in None object in callback(). If you do want to generate a chart from an event as well as in a scheduled callback, create an additional event callback method that calls generate_chart().