Skip to content
ggodart edited this page Jan 11, 2021 · 1 revision

Timers

See Timer item for a full description of the timer object and more examples

A simple timer

#-----------------------------------
# create the timer and a voice command to start and stop it
# only runs once so wrap in noloop
#-----------------------------------
#noloop=start

$v_laundry_timer    = new  Voice_Cmd('Laundry timer [start,stop]');
$timer_laundry      = new  Timer;
#noloop=stop

#-----------------------------------
# launch the timer on voice command
# timer runs for 35 minutes
#-----------------------------------
if ($state =  said $v_laundry_timer ) {
    if ($state eq "start") {
	set $timer_laundry 35*60 ;
    }
    elsif ($state eq "stop") {
	set $timer_laundry 0;
    } else {
        print_log("invalid state $state passed to laundry timer voice command');
    }
}

#-----------------------------------
# create a handler for when the timer expires
#-----------------------------------
if ( expired $timer_laundry) {
  print_log("Laundry timer expired");
}
Clone this wiki locally