Skip to content

Example Time controlled lights

ggodart edited this page Jan 11, 2021 · 1 revision

Time controlled light examples

#-----------------------------------
# create the new x10 items
# wrap in noloop as they only need to be done once
#-----------------------------------
# noloop=start

$reading_light = new X10_Item('N5');
$backyard_light     = new X10_Item('C4');
$christmas_light    = new X10_Item('A5');

# noloop=stop
#-----------------------------------
# change item state at a fixed time
#-----------------------------------
if (time_now "9:00 PM") {
    speak "I just turned on the reading light";
    $reading_light->set( ON, "9PM time") ;
}

#-----------------------------------
# change item state at a time relative to sunset
#-----------------------------------
if (time_now "$Time_Sunset + 0:15") {
    speak "I just turned the backyard light on at $Time_Now";
    $backyard_light->set( ON, "15 minutes after sunset") ;
}

#-----------------------------------
# using time_cron for recurring events
#-----------------------------------
# run at 18:00 in December and January
$christmas_lights->set( ON, "6pm in Dec and Jan") if time_cron('00 18 * 12,1 *');
# run at 22:30 in December and January
$christmas_lights->set( OFF, "10:30pm in Dec and Jan") if time_cron('30 22 * 12,1 *');
Clone this wiki locally