Created
February 22, 2015 23:55
-
-
Save enishoca/4442e2754a7f2181b264 to your computer and use it in GitHub Desktop.
This script is run on a rooted wink hub and syncs the state of GE-Link devices to the original state. After a power failure the GE-Link bulbs turn on even if they were off previously, this is probably for supporting a local light switch. Luckily the bulb itself remembers the last state and can be set to it again.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
date_default_timezone_set('EST'); | |
$debug = 1; | |
$sleepinterval = 360; // run every 6 hours | |
# $item[0] master_id - master_id, as listed by aprontest -l | |
# $item[1] aprontest attribute - attribute to monitor | |
# $item[2] aprontest attribute description | |
$items = array | |
( | |
array(3,"1","On_Off"), | |
array(6,"1","On_Off","2") | |
); | |
while(true) { | |
$count = 0; | |
foreach($items as &$item) { | |
$cmd = "aprontest -l -m " . $item[0] . " | grep " . $item[2] . " | awk '{ print $9 }'"; | |
if($debug == 1) echo "$cmd\n"; | |
unset($out); | |
exec($cmd,$out,$retval); | |
$getvalue = $out[0]; | |
$cmd = "aprontest -l -m " . $item[0] . " | grep " . $item[2] . " | awk '{ print $ 11}'"; | |
if($debug == 1) echo "$cmd\n"; | |
unset($out); | |
exec($cmd,$out,$retval2); | |
$setvalue = $out[0]; | |
if($debug == 1) { echo "Master ".$item[0]." Set value = " . $setvalue . ".Get value = ". $getvalue." \n"; } | |
if($retval == 0 && $retval2 == 0) { | |
if($getvalue == $setvalue) { | |
if($debug == 1) { echo "Life is good\n"; } | |
} else { | |
if($debug == 1) { echo "resetting...\n"; } | |
$cmd = "aprontest -u -m " . $item[0] . " -t " . $item[1] . " -v ". $setvalue; | |
if($debug == 1) echo "$cmd\n"; | |
unset($out); | |
exec($cmd,$out,$retval); | |
print_r($out); | |
} | |
} | |
} | |
sleep($sleepinterval); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment