Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # Usage details in this post https://groups.google.com/forum/#!category-topic/openhab/examples/AROBZn-WjnM
- date_default_timezone_set('EST');
- $debug = 0;
- $sleepinterval = 9;
- # $item[0] Item_name - OpenHAB item name
- # $item[1] master_id - master_id, as listed by aprontest -l
- # $item[2] aprontest attribute - attribute to monitor
- # $item[3] value1 or "AttributeValue" or "Percent" - if set to "AttributeValue" send back whatever comes back, if set to "Percent" attribute is converted to a percent of value in $item[4]
- # $item[4] send str1 or base of the number if $item[3] is "Percent" - if aprontest attribute changes to value1, send this string
- # $item[5] value2
- # $item[6] send str2 - if aprontest attribute changes to value2, send this string
- # $item[7] prev_value - value stored from the previous call to aprontest
- $items = array
- (
- array("denlight",6,"Level","Percent","255","","","")
- array("dendimmer",6,"ConfigurationParameter_0","AttributeValue","","","","")
- #array("side_door_contact",13,"ZoneStatus","48","CLOSED","49","OPEN",""),
- #array("front_door_lock",5,"Lock_Unlock","TRUE","ON","FALSE","OFF","")
- );
- while(true) {
- $count = 0;
- foreach($items as &$item) {
- $cmd = "aprontest -l -m " . $item[1] . " | grep " . $item[2] . " | awk '{ print $9 }'";
- # echo "$cmd\n";
- unset($out);
- exec($cmd,$out,$retval);
- if($retval == 0) {
- if($debug == 1) { echo "$item[0]: $out[0]\n"; }
- if($item[7] == "" ) {
- if($debug == 1) { echo "* Setting initial value\n"; }
- $item[7] = $out[0];
- } else {
- if($debug == 1) { echo "* Comparing to existing value...\n"; }
- if($item[7] != $out[0]) {
- echo date(DATE_RFC2822) . ": $item[0]: $item[7] -> $out[0]\n";
- $item[7] = $out[0];
- $url = "http://pi:8080/rest/items/$item[0]/state";
- if ($item[3] == "SourceValue") {
- $payload = $out[0];
- } elseif ($item[3] == "Percent") {
- $payload = intval($out[0] / intval($item[4]) * 100);
- }
- elseif($out[0] == $item[3]) {
- $payload = $item[4];
- } elseif($out[0] == $item[5]) {
- $payload = $item[6];
- }
- exec("curl -s -X PUT -d $payload -H \"Content-Type: text/plain\" $url");
- } else {
- if($debug == 1) { echo "No change\n"; }
- }
- }
- }
- $count += 1;
- }
- if($debug == 1) { echo "\n"; }
- sleep($sleepinterval);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement