-
Notifications
You must be signed in to change notification settings - Fork 130
Light_Restriction
Use this object with predictive/automatic lighting (i.e. Occupancy_Monitor.pm and Light_Item.pm) to place certain restrictions on when lights should and should not come on.
Example initialization:
# noloop=start
use Light_Restriction_Item;
my $only_when_dark = new Light_Restriction_Item();
$only_when_dark->attach_scalar(\$Dark);
# noloop=stop
$om_auto_master_bath_light->add($om_motion_master_bath,
$om_presence_master_bath, $only_when_dark);
# To enable the tied light
set $test_restrict ON;
set $test_restrict 'light_ok';
# To disable the tied light
set $test_restrict OFF;
set $test_restrict 'no_light';
State is either 'light_ok' or 'no_light'
You can attach to a scalar to automatically allow or disallow lights based on its value. Any number of "light ok" values are allowed:
# Light can turn on when $Dark is true
# (defaults to true when no OK values are given)
$only_when_dark->attach_scalar(\$Dark);
# Light can turn on when the current second is 0-9
$test_restrict->attach_scalar(\$Second, 0, 1, 2, 3, 4, 5, 6 , 7, 8, 9);
Although you can attach to a hash entry by doing this:
$only_when_dark->attach_scalar(\$hash_name{hash_key});
Sometimes this reference becomes invalid. In particular, the %Save hash is sometimes reloaded and the references to the values change. So, I recommend attaching to hash values as follows:
$only_when_dark->attach_hash_key(\%hash_name, 'hash_key');
You can attach to another object to automatically allow or disallow lights based on its state. Any number of "light ok" values are allowed:
# Only allow lights to turn on when mode_occupied is 'home'
$only_when_home->attach_object($mode_occupied, 'home');
# Only allow lights to turn on when mode_sleeping is 'nobody'
$only_when_awake->attach_object($mode_sleeping, 'nobody');