HABApp: Variable Timers Best Practice?


Hi all (and Sebastian)…

I’m trying to modify/apply this code example from the docs:

import HABApp
from HABApp.core.items import Item
from HABApp.core.events import ValueUpdateEvent

class MyCountdownRule(HABApp.Rule):
    def __init__(self):

        self.countdown = self.run.countdown(30, self.switch_off)
        self.device = Item.get_item('my_device')

        self.movement1 = Item.get_item('movement_sensor1')
        self.movement1.listen_event(self.movement, ValueUpdateEvent)

        self.movement2 = Item.get_item('movement_sensor2')
        self.movement2.listen_event(self.movement, ValueUpdateEvent)

    def movement(self, event: ValueUpdateEvent):
        if self.device != 'ON':


    def switch_off(self):


But want to set the timer parameters when movement is detected (thus in the movement routine) instead of when the rule is loaded because I am trying to have timer durations based on variables such as occupancy, time of day, etc.

Is there a good way to do this in a way that won’t create multiple redundant timers? I’ve been picking at it for a bit but my understanding of python inheritance is proving to be an obstacle, and figure posting my spaghetti test code will be harder to follow than building on the example.

Appreciate any help, as this will allow me to consolidate dozens of rules and eliminate a number of ‘expire’ switches.

1 Like

If you click in the documentation on the returned object from self.run.countdown you get the CountdownJob

Cool! That looks very easy…I guess I was over-complicating it.