#!/usr/bin/php | |
<?php | |
date_default_timezone_set('MST'); | |
$debug = 0; | |
# $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 | |
# $item[4] send str1 - 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("side_window_contact",3,"ZoneStatus","48","CLOSED","49","OPEN",""), | |
array("bedroom_door_contact",7,"ZoneStatus","48","CLOSED","49","OPEN",""), | |
array("front_door_contact",8,"ZoneStatus","48","CLOSED","49","OPEN",""), | |
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://data.systrap.net:8080/rest/items/$item[0]/state"; | |
if($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"; } | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment