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):
super().__init__()
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':
self.device.post_value('ON')
self.countdown.reset()
def switch_off(self):
self.device.post_value('OFF')
MyCountdownRule()
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.