Hallo,
also ich habe den CUL auch an der CCU laufen.
Klappt Prima.
Das einbinden in die CCU habe ich etwas anders gelöst.
Ich werte die Terminal Seite des CuxDaemon aus.
Speicher diese alle 10 Sekunden in eine Variable und trigger bei Änderung ein Script.
Vielleicht nicht optimal aber es geht.
Primär Werte ich die Daten des EM1010 aus.
ACHTUNG:
Das Script und diese Vorgehensweise kann NUR Daten lesen.
ToDo:
-
Variable anlegen
-
WWWReader anlegen:
URL: http://CCU-IP:8700/cgicmd?m=11
- Textparser anlegen
Übergeordnete Instanz ist der WWWReader
- Regel hinzufügen
- Text ausschneiden zwischen
- Tag eins: hidden; '>
- Tag zwei:
- Ausgang Variable: die oben angelegte unter Punkt 1
- PHP Script anlegen:
<?php
/**
RegVar-Script für busware.de CUL/CUN receiver
protocol decodes translated from FHEM project
http://www.koeniglich.de/fhem/fhem.html
testet with IPS 2.3 and CUN FW 1.39
Only use CuxD-Daemon 0.45 !!!!
http://www.tdressler.net/ipsymcon
http://www.tdressler.net/ipsymcon/cun_ips.html
24.09.2010
*/
$catname='EM1010CUL';
$sensorname='EM1010 Sensor';
//logging
$logPfad = (IPS_GetKernelDir(). "logs\\");
//echo $logPfad;
$cullog=$logPfad . "cul.log";
$emlog=$logPfad . "culem.log";
$fs20log=$logPfad . "culfs20.log";
$fhtlog=$logPfad . "culfht.log";
$wslog=$logPfad . "culws.log";
$hmslog=$logPfad . "culhms.log";
$datas = GetValueString(44069 /*[EM1010CUL\EM1010]*/ );
// Sonderzeichen ersetzen
$datas = str_replace(" --> "," ",$datas);
$datas = str_replace(" <-- "," ",$datas);
$datas = str_replace(chr(10),"",$datas);
// Empfangenen Text in GMA String einfügen Max. X Einträge
$datasets = explode(chr(13), $datas);
foreach($datasets as $datatag)
{
$data2 = explode(" ", $datatag);
if ($data2[0] <> "")
{
$zeit = $data2[1];
$data = $data2[2];
}
}
IPS_Logmessage($catname,$data);
logge($cullog,$data."
");
//split lines
$rows=preg_split("/
/",$data);
$data="";
foreach($rows as $line) {
//---------------EM1000-----------------------------------
if (preg_match("/^E0.................\s*\$/",$line)) {
// E0101E2997805002F02
$type=substr($line,2,1);
$addr=substr($line,3,2);
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Last'=>array('type'=>1,'profile'=>'~UnixTimestamp'),
'Total'=>array('type'=>2,'profile'=>'~Electricity'),
'Actual'=>array('type'=>2,'profile'=>'~Power'),
'Peak'=>array('type'=>2,'profile'=>'~Power'),
'total_cnt'=>array('type'=>1,'profile'=>''),
'basis_cnt'=>array('type'=>1,'profile'=>''),
'cf_power'=>array('type'=>2,'profile'=>''),
'cf_energy'=>array('type'=>2,'profile'=>''));
$varids=get_ips_vars($addr,$vartypes,$catname,$sensorname);
if (is_null($varids)) {
//Error, no vars created
IPS_LogMessage($catname,'No VarIDs!');
return;
}
$cf1=$varids['cf_power']['val'];
$cf2=$varids['cf_energy']['val'];
$basis_cnt=$varids['basis_cnt']['val'];
$total_cnt_last=$varids['total_cnt']['val'];
$last=$varids['Last']['val'];
//ips_logmessage($catname,"1:$cf1,2:$cf2,B:$basis_cnt,T:$total_cnt_last,L:$last");
/*
Set corretion factor
corr1 is the correction factor for power
corr2 is the correction factor for energy
*/
$cfnew=(($cf1==0)||($cf2==0));
if($addr >= 1 && $addr <= 4) { // EMWZ: nRotation in 5 minutes
$cf1 = ($cf1 ? $cf1 : 150); //Zählerkonstanzte U/kwh
$cf2 = ($cf2 ? $cf2 : 150);
$corr1=12/$cf1;
$corr2=1/$cf2;
} elseif ($addr >= 5 && $addr <= 8) { // EMEM
$cf1 = ($cf1 ? $cf1 : 0.01);
$cf2 = ($cf2 ? $cf2 : 0.001);
$corr1=$cf1;
$corr2=$cf2;
} elseif($addr >= 9 && $addr <= 12) { // EMGZ: 0.01
$cf1 = ($cf1 ? $cf1 : 0.01);
$cf2 = ($cf2 ? $cf2 : 0.01);
$corr1=$cf1;
$corr2=$cf2;
} else {
IPS_Logmessage($catname,"Wrong Address:$addr");
return;
}
//store default factors
if ($cfnew) {
SetValue($varids['cf_power']['id'],$cf1);
SetValue($varids['cf_energy']['id'],$cf2);
}
/*
Decode Packet
description from CUL_EM.pm
Ettaacc111122223333
tt:type 01=EM-1000s, 02=EM-100-EM, 03=1000GZ
aa:address, depending on the type above 01:01-04, 02:05-08, 03:09-12
cc:counter, will be incremented by one for each message
1111: cumulated value
2222: last value (Not set for type 2)
3333: top value (Not set for type 2)
seqno = number of received datagram in sequence, runs from 2 to 255
total_cnt= total (cumulated) value in ticks as read from the device
basis_cnt= correction to total (cumulated) value in ticks to account for
counter wraparounds
total = total (cumulated) value in device units
current = current value (average over latest 5 minutes) in device units
peak = maximum value in device units
*/
$seqno=hexdec(substr($line,5,2));
//total value
$total_cnt=hexdec(substr($line,9,2).substr($line,7,2));
//counter overflow, max value 65535
if($total_cnt< $total_cnt_last) {
$basis_cnt += 65536 /*[Kein(e)]*/;
SetValue($varids['basis_cnt']['id'],$total);
}
$total = ($basis_cnt+$total_cnt)*$corr2;
SetValue($varids['total_cnt']['id'],$total_cnt);
//check time diff tp previous
$now=time();
$tdiff=$now-$last;
// peak and current (5min) value
if ($type<>2) {
$current_cnt=hexdec(substr($line,13,2).substr($line,11,2));
$peak_cnt=hexdec(substr($line,17,2).substr($line,15,2));
$current = $current_cnt*$corr1;
$peak = $peak_cnt*$corr1;
}else{
//calculate current as counter difference
if ($total_cnt>=$total_cnt_last) {
$current_cnt=$total_cnt-$total_cnt_last;
}else{
//add overflow
$current_cnt=$total_cnt+65536-$total_cnt_last;
}
//type 2 has no peak and current entry
$current = $current_cnt*$corr1;
$peak=0;
$peak_cnt=0;
}
//store in IPS
SetValue($varids['Total']['id'],$total);
SetValue($varids['Actual']['id'],$current);
SetValue($varids['Peak']['id'],$peak);
SetValue($varids['Last']['id'],$now);
//logging to IPS log
$val = sprintf("SEQ: %d CNT: %d Basis: %d DIFF: %d TIME:$tdiff CUM: %0.3f 5MIN: %0.3f PEAK: %d TOP: %0.3f",
$seqno, $total_cnt, $basis_cnt,$current_cnt,$total, $current,$peak_cnt, $peak);
$text= "Type $type Addr:$addr, $val";
//logging
IPS_Logmessage($catname,$text);
logge($emlog,"$line=>Dev $addr:".$text."
");
}//if pregmatch
//-----------------------FS20
elseif (preg_match("/^F[0-9A-F]{8,10}\s*\$/",$line)) {
//F1F1E013A4F
$hcode=substr($line,1,4);
$addr=substr($line,5,2);
$cde=substr($line,7,2);
$id=hex2four($hcode.$addr);
if (strlen($id)==12)$id=substr($id,0,4).' '.substr($id,4,4).' '.substr($id,8,4);
$catname='FS20CUL';
$sensorname='FS20 ';
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Status'=>array('type'=>3,'profile'=>'')
);
$varids=get_ips_vars($id,$vartypes,$catname,$sensorname);
if (is_null($varids)) {
//Error, no vars created
IPS_LogMessage($catname,'No VarIDs!');
return;
}
$fs20_codes = array(
//definitions taken from fhem 10_fs20.pm
"00" => "off",
"01" => "dim06%",
"02" => "dim12%",
"03" => "dim18%",
"04" => "dim25%",
"05" => "dim31%",
"06" => "dim37%",
"07" => "dim43%",
"08" => "dim50%",
"09" => "dim56%",
"0a" => "dim62%",
"0b" => "dim68%",
"0c" => "dim75%",
"0d" => "dim81%",
"0e" => "dim87%",
"0f" => "dim93%",
"10" => "dim100%",
"11" => "on", // Set to previous dim value (before switching it off)
"12" => "toggle", // between off and previous dim val
"13" => "dimup",
"14" => "dimdown",
"15" => "dimupdown",
"16" => "timer",
"17" => "sendstate",
"18" => "off-for-timer",
"19" => "on-for-timer",
"1a" => "on-old-for-timer",
"1b" => "reset",
"1c" => "ramp-on-time", //time to reach the desired dim value on dimmers
"1d" => "ramp-off-time", //time to reach the off state on dimmers
"1e" => "on-old-for-timer-prev", // old val for timer, then go to prev. state
"1f" => "on-100-for-timer-prev", // 100% for timer, then go to previous state
);
$dur = 0;
$cx = hexdec($cde);
if($cx & 0x20) {
$dur = hexdec(substr($line, 9, 2));
$i = ($dur & 0xf0) / 16;
$j = ($dur & 0xf);
$dur = pow(2,$i)*$j*0.25;
$cde = sprintf("%02x", $cx & ~0x20);
}
$v = $fs20_codes[$cde];
if(!$v) $v = "unknown Code $cde" ;
if($dur) $v .= " DUR: $dur" ;
$text= "$v($cde)";
SetValue($varids['Status']['id'],$v);
//logging
IPS_Logmessage($catname,$text);
logge($fs20log,"$line=>Dev $id: ".$text."
");
} //if pregmatch
//------------------FHT----------------------------------
elseif (preg_match("/^T[0-9A-F]{8,11}\s*\$/",$line)) {
//T0A4700BA00
$varids=null;
$dev = substr($line, 1, 4);
$cde = substr($line, 5, 2);
$catname='FHTCUL';
$sensorname='FHT ';
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Low'=>array('type'=>3,'profile'=>''),
'Position'=>array('type'=>3,'profile'=>''),
'Warnings'=>array('type'=>3,'profile'=>''),
'Soll'=>array('type'=>2,'profile'=>'~Temperature'),
'Temperatur'=>array('type'=>2,'profile'=>'~Temperature'),
'Status'=>array('type'=>3,'profile'=>''));
$varids=get_ips_vars($dev,$vartypes,$catname,$sensorname);
if (is_null($varids)) {
//Error, no vars created
IPS_LogMessage($catname,'No VarIDs!');
return;
}
$FHT_codes = array(
"00" => "actuator",
"01" => "actuator1",
"02" => "actuator2",
"03" => "actuator3",
"04" => "actuator4",
"05" => "actuator5",
"06" => "actuator6",
"07" => "actuator7",
"08" => "actuator8",
"14" => "mon-from1",
"15" => "mon-to1",
"16" => "mon-from2",
"17" => "mon-to2",
"18" => "tue-from1",
"19" => "tue-to1",
"1A" => "tue-from2",
"1B" => "tue-to2",
"1C" => "wed-from1",
"1D" => "wed-to1",
"1E" => "wed-from2",
"1F" => "wed-to2",
"20" => "thu-from1",
"21" => "thu-to1",
"22" => "thu-from2",
"23" => "thu-to2",
"24" => "fri-from1",
"25" => "fri-to1",
"26" => "fri-from2",
"27" => "fri-to2",
"28" => "sat-from1",
"29" => "sat-to1",
"2A" => "sat-from2",
"2B" => "sat-to2",
"2C" => "sun-from1",
"2D" => "sun-to1",
"2E" => "sun-from2",
"2F" => "sun-to2",
"3E" => "mode",
"3F" => "holiday1", # Not verified
"40" => "holiday2", # Not verified
"41" => "desired-temp",
"XX" => "measured-temp", # sum of next. two, never really sent
"42" => "measured-low",
"43" => "measured-high",
"44" => "warnings",
"45" => "manu-temp", # No clue what it does.
"4B" => "ack",
"53" => "can-xmit",
"54" => "can-rcv",
"60" => "year",
"61" => "month",
"62" => "day",
"63" => "hour",
"64" => "minute",
"65" => "report1",
"66" => "report2",
"69" => "ack2",
"7D" => "start-xmit",
"7E" => "end-xmit",
"82" => "day-temp",
"84" => "night-temp",
"85" => "lowtemp-offset", # Alarm-Temp.-Differenz
"8A" => "windowopen-temp",
);
// additional warnings
$FHT_warnings = array(
"battery" => 1,
"lowtemp" => 1,
"window" => 1,
"windowsensor" => 1,
);
$FHT_priority = array(
"desired-temp"=> 1,
"mode" => 2,
"report1" => 3,
"report2" => 3,
"holiday1" => 4,
"holiday2" => 5,
"day-temp" => 6,
"night-temp" => 7,
);
$FHT_c2m = array(0 => "auto", 1 => "manual", 2 => "holiday", 3 => "holiday_short");
$text="Dev: $dev,";
if(strlen($line) > 9) $val = substr($line, 9, 2);
# Short message
if(strlen($line) < 9) {
$cmd="FHT Short message: $line";
$val="";
//continue;
goto fhtlog;
}
if(!$val || $cde == "65" || $cde == "66") {
// This is a confirmation message. We reformat it so that
$confirm = 1;
}
$val = hexdec($val);
$cmd = $FHT_codes[$cde];
if(!$cmd) {
$cmd= "(Unknown: $cde =>$val)";
$val="";
//continue;
goto fhtlog;
}
if( preg_match("/-from/",$cmd) || preg_match("/-to/",$cmd)) {
$val = sprintf("%02d:%02d", $val/6, ($val%6)*10);
} elseif($cmd == "mode") {
if(isset($c2m[$val])) $val = $c2m[$val] ;
} elseif(preg_match("/.*-temp/",$cmd)) {
$val=$val/2;
if ($cmd== "desired-temp") {
SetValue($varids['Soll']['id'],$val);
}
$val = sprintf("%.1f", $val);
} elseif($cmd == "lowtemp-offset") {
$val = sprintf("%d.0", $val);
} elseif(preg_match("/^actuator/",$cmd)) {
$sval = substr($line,7,2);
$fv = sprintf("%d%%", (integer)(100*$val/255+0.5));
if(preg_match("/[AB]0/i",$sval)) { $val = $fv; } # sync in the summer
elseif(preg_match("/.0/",$sval)) { $val = "syncnow"; }
elseif(preg_match("/.1/",$sval)) { $val = "99%"; } # FHT set to 30.5, FHT80B=="ON"
elseif(preg_match("/.2/",$sval)) { $val = "0%"; } # FHT set to 5.5
elseif(preg_match("/.6/",$sval)) { $val = "$fv"; }
elseif(preg_match("/.8/",$sval)) { $val = "offset: $fv"; }
elseif(preg_match("/.A/",$sval)) { $val = "lime-protection"; }
elseif(preg_match("/.C/",$sval)) { $val = sprintf("synctime: %d", int($val/2)-1); }
elseif(preg_match("/.E/",$sval)) { $val = "test"; }
elseif(preg_match("/.F/",$sval)) { $val = "pair"; }
else { $val = "unknown_$sval: $fv"; }
$pos=strpos($val,"%");
if (! ($pos===false)) {
SetValue($varids['Position']['id'],$val);
}
} elseif($cmd == "measured-low") {
SetValue($varids['Low']['id'],$val);
//continue;
goto fhtlog;
} elseif($cmd == "measured-high") {
// if(defined($varids['Low']['val'])) {
$low=$varids['Low']['val'];
$off = 0;
$val = $val*256 + $low;
$val /= 10;
SetValue($varids['Temperatur']['id'],$val);
$val = sprintf("%.1f (Celsius)", $val+$off);
$cmd = "measured-temp";
} elseif($cmd == "warnings") {
# initialize values for additional warnings
# parse warnings
if($val & 1) {
$nVal = "Battery low";
$nBattery = "low";
}
if($val & 2) {
if($nVal) $nVal .= "; " ;
$nVal .= "Temperature too low";
$nLowTemp = "warn";
}
if($val &32) {
if($nVal) $nVal .= "; " ;
$nVal .= "Window open";
$nWindow = "open";
}
if($val &16) {
if($nVal) $nVal .= "; " ;
$nVal .= "Fault on window sensor";
$nSensor = "fault";
}
# set default values or new values if they were changed
$valBattery = isset($nBattery)? $nBattery : "ok";
$valLowTemp = isset($nLowTemp)? $nLowTemp : "ok";
$valWindow = isset($nWindow)? $nWindow : "closed";
$valSensor = isset($nSensor)? $nSensor : "ok";
$val = isset($nVal)? $nVal : "none";
# set additional warnings and trigger notify
$text.= " battery: $valBattery";
$text.= " lowtemp: $valLowTemp";
$text.= " window: $valWindow";
$text.= " windowsensor: $valSensor";
SetValue($varids['Warnings']['id'],"$val");
}//if cmd
//finish
fhtlog:
if(substr($line,7,1) == "7") { # Do not store FHZ acks.
$cmd = "FHT:$cmd";
$text.="
".$cmd;
} else {
//if($cmd == "measured-temp")
$text.= " $cmd: $val" ;
SetValue($varids['Status']['id'],"$cmd: $val");
}
//logging
IPS_Logmessage($catname,$text);
logge($fhtlog,"$line=>Dev $dev:".$text."
");
}//if preg
//---------------------Wetter(WS300)-----------------------------------------
elseif (preg_match("/^K[0-9A-F]{6,8}\s*\$/",$line)) {
//K11245265
$tlist = array("0"=>"temp",
"1"=>"temp/hum",
"2"=>"rain",
"3"=>"wind",
"4"=>"temp/hum/press",
"5"=>"brightness",
"6"=>"pyro",
"7"=>"temp/hum");
$a=str_split($line);
$len=strlen($line)-1;
$firstbyte = hexdec($a[1]);
$typebyte=$a[2];
$cde = ($firstbyte&7);
$type = isset($tlist[$typebyte]) ? $tlist[$typebyte] : "unknown";
$typebyte=$typebyte & 7;
$varids=null;
$val="no data";
$catname='WSCUL';
$sensorname='WS ';
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Temperatur'=>array('type'=>2,'profile'=>'~Temperature'),
'Humidity'=>array('type'=>1,'profile'=>'~Humidity')
);
$varids=get_ips_vars($a[1],$vartypes,$catname,$sensorname);
if (is_null($varids)) {
//Error, no vars created
IPS_LogMessage($catname,'No VarIDs!');
return;
}
if (($firstbyte&7)==7) {
if($typebyte == 0 && $len > 6) { # temp
$sgn = ($firstbyte&8) ? -1 : 1;
$tmp = $sgn * ($a[6].$a[3].".".$a[4]);
$val = "T: $tmp";
$hum=0;
SetValue($varids['Temperatur']['id'],$tmp);
SetValue($varids['Humidity']['id'],$hum);
}
if($typebyte == 1 && $len > 8) { # temp/hum
$sgn = ($firstbyte&8) ? -1 : 1;
$tmp = $sgn * ($a[6].$a[3].".".$a[4]);
//$hum = ($a[7].$a[8].".".$a[5]) ;
$hum = ($a[7].$a[8]) ;
$val = "T: $tmp H: $hum";
$devtype = "PS50";
$family = "WS300";
SetValue($varids['Temperatur']['id'],$tmp);
SetValue($varids['Humidity']['id'],$hum);
}
}else{
if ($len == 9 ) { # S300TH
$sgn = ($firstbyte&8) ? -1 : 1;
$tmp = $sgn * ($a[6].$a[3].".".$a[4]);
//$hum = ($a[7].$a[8].".".$a[5]);
$hum = ($a[7].$a[8]) ;
$val = "T: $tmp H: $hum";
$devtype = "S300TH";
SetValue($varids['Temperatur']['id'],$tmp);
SetValue($varids['Humidity']['id'],$hum);
} elseif($len == 15) { # KS300/2
$c = 255;
$rain = sprintf("%0.1f", hexdec("$a[14]$a[11]$a[12]") * $c / 1000);
$wnd = sprintf("%0.1f", "$a[9]$a[10].$a[7]" );
$hum = sprintf( "%02d", "$a[8]$a[5]");
$tmp = sprintf("%0.1f", ("$a[6]$a[3].$a[4]"),
(($a[1] & 0xC) ? -1 : 1));
$ir = ((hexdec($a[1]) & 2)) ? "yes" : "no";
SetValue($varids['Temperatur']['id'],$tmp);
SetValue($varids['Humidity']['id'],$hum);
$val = "T: $tmp H: $hum W: $wnd R: $rain IR: $ir";
}
}
$text="Dev $cde ($type): $val";
IPS_Logmessage($catname,$text);
logge($wslog,"$line (Len:$len)=>".$text."
");
}//if preg
//--------------------HMS-------------------------------------------------------
elseif (preg_match("/^H[0-9A-F]{12}\s*\$/",$line)) {
//H37AE01240000
$codes = array(
0 => "HMS100TF",
1 => "HMS100T",
2 => "HMS100WD",
3 => "RM100-2",
4 => "HMS100TFK", # Depending on the onboard jumper it is 4 or 5
5 => "HMS100TFK",
6 => "HMS100MG",
8 => "HMS100CO",
14 => "HMS100FIT"
);
$type = hexdec(substr($line,6,1));
$stat = $type > 1 ? hexdec(substr($line,7,2)) : hexdec(substr($line,5,2));
$prf = $type > 1 ? "02" : "05";
$bat = $type > 1 ? hexdec(substr($line,5,1))+1 : 1;
$dev = substr($line,1,4);
$val = $type > 1 ? "000000" : substr($line,7);
$catname='HMSCUL';
$sensorname='HMS ';
//if (!isset($sensorname)) $sensorname='HMS ';
switch ($type) {
case 0://TF
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Type'=>array('type'=>3,'profile'=>''),
'Temperatur'=>array('type'=>2,'profile'=>'~Temperature'),
'Humidity'=>array('type'=>1,'profile'=>'~Humidity'),
'Battery'=>array('type'=>0,'profile'=>'~Battery.Reversed')
);
break;
case 1://T
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Type'=>array('type'=>3,'profile'=>''),
'Temperatur'=>array('type'=>2,'profile'=>'~Temperature'),
'Battery'=>array('type'=>0,'profile'=>'~Battery.Reversed')
);
break;
case 4://TFK Switch1
case 5://TFK Switch2
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Type'=>array('type'=>3,'profile'=>''),
'Kontakt'=>array('type'=>0,'profile'=>'~Switch'),
'Battery'=>array('type'=>0,'profile'=>'~Battery.Reversed')
);
break;
case 2://WD
case 3://RM100
case 6://Gas MG
case 8://Gas CO
case 14://FIT
$vartypes=array( 'ID'=>array('type'=>3,'profile'=>''),
'Type'=>array('type'=>3,'profile'=>''),
'Alarm'=>array('type'=>0,'profile'=>'~Alert'),
'Battery'=>array('type'=>0,'profile'=>'~Battery.Reversed')
);
break;
default://type not known
IPS_LogMessage($catname,"Unknown type: $type");
continue 2;
}
$varids=null;
$varids=get_ips_vars($dev,$vartypes,$catname,$sensorname);
if (is_null($varids)) {
//Error, no vars created
IPS_LogMessage($catname,'No VarIDs!');
continue;
}
SetValue($varids['Battery']['id'],($bat==1));
if (! ($varids['Type']['val']) == $codes[$type]) {
SetValue($varids['Type']['id'],$codes[$type]);
}
switch($type) {
case 0: //TF
# Codierung <t1><t0><f0><t2><f2><f1>
$hum=(Integer)(substr($val, 4, 2).substr($val, 2, 1))/10;
SetValue($varids['Humidity']['id'],$hum);
case 1://T
$tmp=(substr($val, 3, 1).substr($val, 0, 2))/10;
if (($stat & 128)>0) $tmp=-$tmp;
SetValue($varids['Temperatur']['id'],$tmp);
break;
case 2:
case 3:
case 6:
case 8:
case 14: SetValue($varids['Alarm']['id'],($stat>0));
break;
case 4:
case 5: SetValue($varids['Kontakt']['id'],($stat>0));
break;
default:
IPS_LogMessage($catname,"Type $type for Dev $HA not known");
break;
}
$text="Dev $dev ($type:".$codes[$type]."): Stat:$stat, Bat: $bat Val: $val";
IPS_Logmessage($catname,$text);
logge($hmslog,"$line =>".$text."
");
}//if preg
}//foreach
//}//if sender
//-------------------------------------------------------------------------------
/**
* IPS Variablen handler
* creates variables as needed
* returns assoc. Array with IPS Variable ID and Value
* @param integer Sensor Address
* @param array Array with Variable Names, Types and Profiles
* @param string Sensor Group Master Categorie Name
* @param string Sensor default name, will be extended with $addr
*/
function get_ips_vars($addr,$vartypes,$cat,$sens) {
$varids=null;
$master=@IPS_GetObjectIDByName($cat,0);
//no master cat, create new
if (!$master) {
$master=IPS_CreateCategory();
IPS_SetName($master,$cat);
IPS_SetParent($master,0);
if ($master>0) {
IPS_LogMessage('CUL', "Master category created, ID=$master
");
}else{
IPS_LogMessage('CUL', "Can't create Master Category
");
return null;
}
}
$id=0;
if ($master>0) {
//get chilren sensors
$Sensors=IPS_GetChildrenIDs($master);
foreach($Sensors as $sid) {
$name=IPS_GetName($sid);
// print "$sid:".$name."
";
//get vars for each sensor
$vars=IPS_GetChildrenIDs($sid);
foreach($vars as $vid) {
$vname=IPS_GetName($vid);
//if ID, here is the address
if ($vname="ID") {
$i=GetValue($vid);
//go out if matches, $id returns the sensor categorie id
if ($i===$addr) {
$id=$sid;
break;
}
}
}
if ($id>0) break;
}
if ($id==0) {
//Sensor with address $addr not found in IPS, create new sensor
$id=ips_createCategory();
ips_setName($id,$sens.' '.$addr);
ips_setParent($id,$master);
//creates all needed variables for the new sensor
foreach (array_keys($vartypes) as $name) {
$typ=$vartypes[$name]['type'];
$profile=$vartypes[$name]['profile'];
$vid=IPS_CreateVariable($typ);
ips_setname($vid,$name);
ips_setParent($vid,$id);
IPS_SetVariableCustomProfile($vid,$profile);
//preload variables
SetValue($vid,0);
$varids[$name]['id']=$vid;
$varids[$name]['val']=0;
//Store address in $ID for next time
if ($name=='ID') {
SetValue($vid,$addr);
$varids[$name]['val']=$addr;
}
}
}else{
//found matching cat, collect ids and vals for this sensor
$vars=IPS_GetChildrenIDs($id);
foreach($vars as $vid) {
$name=IPS_GetName($vid);
$val=GetValue($vid);
$varids[$name]['id']=$vid;
$varids[$name]['val']=$val;
}
}
//returns IDs and Values of this Sensor, Name is Key
return $varids;
}
}
//#############################
//
/**
* converting CUL Hex IDs into ELV-4-Ids
* translated from 10_fs20
* @param string $v Hex-Value
* @returns string ELV-ID
*/
function hex2four($v){
$r = "";
foreach (str_split($v) as $x) {
$r .= sprintf("%d%d", (hexdec($x)/4)+1, (hexdec($x)%4)+1);
}
return $r;
}
//#############################
/**
* converting ELV IDs into CUL Hex-Ids
* translated from 10_fs20
* @param string $v ELV ID
* @returns string Hex- Value
*/
function four2hex($v,$len){
$r = 0;
foreach (str_split($v) as $x) {
$r = $r*4+($x-1);
}
return sprintf("%0*x", $len,$r);
}
/**
* do simple logging
* @param string $logfile Filename for logfile
* @param string $text
* @returns void
*/
function logge($logfile,$text) {
if (strlen($logfile)>0) {
$log=fopen($logfile,"a+");
if ($log) {
$d=date("r");
fwrite($log,"$d $text");
fflush($log);
fclose($log);
}
}
}
?>
- Ereignis unter dem Sript anlegen
Dieses soll das Script aufrufen bei Änderung der oben angelegten Variable unter Punkt 1
Alles weitere macht das Script.
Gruß
MCS-51
Danke an tommi für das Ursprungsscript.
http://www.ip-symcon.de/forum/f52/cul-cun-auslesescript-fuer-em1000-system-11380/