Commanding a Soft-I/O device from XTension is easy (isn't everything, once you know it?). Make a function that communicates an 'on' or an 'off' to a soft-device "PO" in the Soft-I/O module, make a php on-script that calls the function with 'on' as argument and a php-off script that calls the function with 'off' as argument. Finally, add the proper AppleScript command to XTension, calling either the ON or the OFF script.
Have an 'on' script that turns the device on:
<? include "preheat.php" ?>
<?
if(preheat("on")){
echo "switched on<br />";
//
}else{
echo "error encountered<br />";
//
}
?>
one script that turns the preheater off:
<? include "preheat.php" ?>
<?
if(preheat("off")){
echo "switched off<br />";
//
}else{
echo "error encountered<br />";
//
}
?>
And a routine that is included in the two scripts above:
<?
//preheater is a soft-device in the Soft-I/O module that commands a relay coil
//the relay is normally open and shorts two pins of the central heating
//when shorted, the central heating continuously preheats a small water storage
//this consumes natural gas, so we want to minimise the uptime of this feature
//switching off preheating however, takes hot water a long time to reach the faucet
//wasting water and gas, as more gas is needed to eventually deliver hot water.
//currently, the preheater is continuously ON, the current routine will allow
//the preheater to be commanded by the home automation system XTension
//
//turn on or off preheater.
//
//syntax: preheatON.php
//
//accept local access only by having a proper .htaccess file setting
function preheat($onof){
$vacation =0;//set to 1 to block real time display of data
$hostname="softio-xxxx.local.";
$host=gethostbyname($hostname);
$host="192.168.1.32";
$preheater="PO";
// echo "Host: ".$host."\n";
$port = 8001;
// open a client connection
$mysocket=socket_create(AF_INET,SOCK_STREAM,0);
if(!$mysocket){die("could not create socket");}
if (!socket_connect($mysocket,$host,$port)){die("could not connect socket");}
$q=strtolower($onof);
if (!strcmp($q,"on")){
$message=$preheater.".FORCEON&";
}else{
if(!strcmp($q,"off")){
$message=$preheater.".FORCEOFF&";
}else{
die("Invalid command (syntax: preheat([on|off])");//return(NULL);
}
}
$nchars=strlen($message);// echo "sending '".$message. "' as string\n";
$nsentchar=socket_send($mysocket, $message, $nchars,0);
if(!($nsentchar==$nchars)){
die("could not send command");
}else{
// echo "sent '".$message. "' as string of ".$nsentchar." characters\n";
$ncharerreceived=socket_recv($mysocket, $string,256,0);
if (!$ncharerreceived){
//echo "nothing received\n";
die("no response");//return(NULL);
}else{
//echo "received $string" $thelength=strlen($string);$thelength=$thelength-2;
if (!strcmp($string,"OK")){
die("prolem encountered: $string ");//return(NULL);
}else{
return(true);
}
}
}
// echo $astring."\n";
socket_close($mysocket);
}
?>
Finally, add the following AppleScript code to the ON script of the XTension unit "device":
ignoring application responses
do shell script "/Applications/MAMP/bin/php5/bin/php -q /Applications/MAMP/htdocs/php/deviceon.php >/dev/null 2>&1 &"
end ignoring
Likewise, have the following in the OFF script of the XTension unit "device"
ignoring application responses
do shell script "/Applications/MAMP/bin/php5/bin/php -q /Applications/MAMP/htdocs/php/deviceoff.php >/dev/null 2>&1 &"
end ignoring
Thanks to this forum entry