class PantryLightTimerRule ( Rule ): def register_triggers ( self ): self .delay_timer = DelayTimer( self .config, " adjustable_delay " , " 10m " ) self .PantryButton.subscribe_to_event( ' pressed ' ) self .PantryButton.subscribe_to_event( ' longPressed ' ) return ( self .PantryButton, self .delay_timer, self .PantryLight) def action ( self , the_triggering_thing , the_trigger_event , new_value ): if the_triggering_thing is self .PantryButton and the_trigger_event == ' pressed ' : if self .PantryLight.on: self .delay_timer.add_time() # add ten minutes else : self .PantryLight.on = True elif the_triggering_thing is self .PantryButton and the_trigger_event == ' longPressed ' : self .PantryLight.on = False elif the_triggering_thing is self .delay_timer: self .PantryLight.on = False elif the_triggering_thing is self .PantryLight and new_value is False : self .delay_timer.cancel() elif the_triggering_thing is self .PantryLight and new_value is True : self .delay_timer.add_time() # add ten minutes (see this code in situ in the timer_light_rule.py file in the pywot rule system demo directory

PantryButton

PantryLight

register_triggers

pressed

longPressed

PantryButton

PantryLight

PantryLight

action

the_triggering_thing

PantryLight

delay_timer

delay_timer

delay_timer

action

the_triggering_thing

PantryButton.

longPressed

all off stove light only stove light & counter light stove light, counter light & sink light counter light & sink light sink light only counter light only

class CombinationLightRule ( Rule ): def initial_state ( self ): self .index = 0 self .combinations = [ ( False , False , False ), ( True , False , False ), ( True , True , False ), ( True , True , True ), ( False , True , True ), ( False , False , True ), ( False , True , False ), ] def register_triggers ( self ): self .KitchenButton.subscribe_to_event( ' pressed ' ) self .KitchenButton.subscribe_to_event( ' longPressed ' ) return ( self .KitchenButton, ) def set_bulb_state ( self ): self .StoveLight.on = self .combinations[ self .index][ 0 ] self .CounterLight.on = self .combinations[ self .index][ 1 ] self .SinkLight.on = self .combinations[ self .index][ 2 ] def action ( self , the_triggering_thing , the_trigger_event , new_value ): if the_trigger_event == " pressed " : self .index = ( self .index + 1 ) % len ( self .combinations) self .set_bulb_state() elif the_trigger_event == " longPressed " : self .index = 0 self .set_bulb_state() (see this code in situ in the combination_light_rule.py file in the pywot rule system demo directory

combinations

index

KitchenButton

pressed

index

longPressed





pywot