git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2645 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -119,7 +119,7 @@ sub OWTHERM_Initialize ($) {
|
|||||||
$hash->{GetFn} = "OWTHERM_Get";
|
$hash->{GetFn} = "OWTHERM_Get";
|
||||||
$hash->{SetFn} = "OWTHERM_Set";
|
$hash->{SetFn} = "OWTHERM_Set";
|
||||||
$hash->{AttrFn} = "OWTHERM_Attr";
|
$hash->{AttrFn} = "OWTHERM_Attr";
|
||||||
$hash->{AttrList}= "IODev do_not_notify:0,1 showtime:0,1 model:DS1820,DS18B20,DS1822 loglevel:0,1,2,3,4,5 ".
|
$hash->{AttrList}= "IODev model:DS1820,DS18B20,DS1822 loglevel:0,1,2,3,4,5 ".
|
||||||
"event-on-update-reading event-on-change-reading ".
|
"event-on-update-reading event-on-change-reading ".
|
||||||
"stateAL stateAH ".
|
"stateAL stateAH ".
|
||||||
"tempOffset tempUnit:C,Celsius,F,Fahrenheit,K,Kelvin ".
|
"tempOffset tempUnit:C,Celsius,F,Fahrenheit,K,Kelvin ".
|
||||||
@@ -278,11 +278,8 @@ sub OWTHERM_InitializeDevice($) {
|
|||||||
|
|
||||||
#-- Initial readings temperature sensor
|
#-- Initial readings temperature sensor
|
||||||
$owg_temp = "";
|
$owg_temp = "";
|
||||||
$owg_tl = defined($attr{$name}{"tempLow"}) ? $attr{$name}{"tempLow"} : "";
|
$owg_tl = "";
|
||||||
$owg_th = defined($attr{$name}{"tempHigh"}) ? $attr{$name}{"tempHigh"} : "",
|
$owg_th = "",
|
||||||
|
|
||||||
#-- Output formatting because of reading attributes
|
|
||||||
OWTHERM_FormatValues($hash);
|
|
||||||
|
|
||||||
#-- Set state to initialized
|
#-- Set state to initialized
|
||||||
readingsSingleUpdate($hash,"state","initialized",1);
|
readingsSingleUpdate($hash,"state","initialized",1);
|
||||||
@@ -300,6 +297,7 @@ sub OWTHERM_FormatValues($) {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
my $interface = $hash->{IODev}->{TYPE};
|
||||||
my ($unit,$offset,$factor,$abbr,$vval,$vlow,$vhigh,$statef);
|
my ($unit,$offset,$factor,$abbr,$vval,$vlow,$vhigh,$statef);
|
||||||
my $svalue = "";
|
my $svalue = "";
|
||||||
|
|
||||||
@@ -339,9 +337,28 @@ sub OWTHERM_FormatValues($) {
|
|||||||
$vlow = ($owg_tl + $offset)*$factor;
|
$vlow = ($owg_tl + $offset)*$factor;
|
||||||
$vhigh = ($owg_th + $offset)*$factor;
|
$vhigh = ($owg_th + $offset)*$factor;
|
||||||
|
|
||||||
|
#-- check if the device has to be corrected
|
||||||
|
if( AttrVal($name,"tempLow",undef) ){
|
||||||
|
if( $main::attr{$name}{"tempLow"} != $vlow ){
|
||||||
|
OWTHERM_Set( $hash,("tempLow",$main::attr{$name}{"tempLow"}));
|
||||||
|
$vlow = $main::attr{$name}{"tempLow"};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$main::attr{$name}{"tempLow"} = $vlow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( AttrVal($name,"tempHigh",undef) ){
|
||||||
|
if( $main::attr{$name}{"tempHigh"} != $vhigh ){
|
||||||
|
OWTHERM_Set( $hash,("tempHigh",$main::attr{$name}{"tempHigh"}));
|
||||||
|
$vhigh = $main::attr{$name}{"tempHigh"};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$main::attr{$name}{"tempHigh"} = $vhigh;
|
||||||
|
}
|
||||||
|
|
||||||
#-- formats for output
|
#-- formats for output
|
||||||
$statef = "%5.2f ".$abbr;
|
$statef = "T: %5.2f ".$abbr;
|
||||||
$svalue = "temperature: ".sprintf($statef,$vval);
|
$svalue = sprintf($statef,$vval);
|
||||||
|
|
||||||
#-- Test for alarm condition
|
#-- Test for alarm condition
|
||||||
$hash->{ALARM} = 1;
|
$hash->{ALARM} = 1;
|
||||||
@@ -355,9 +372,7 @@ sub OWTHERM_FormatValues($) {
|
|||||||
$hash->{ALARM} = 0;
|
$hash->{ALARM} = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-- put into READINGS and attributes
|
#-- put into READINGS
|
||||||
$main::attr{$name}{"tempLow"} = $vlow;
|
|
||||||
$main::attr{$name}{"tempHigh"} = $vhigh;
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdate($hash,"temperature",$vval);
|
readingsBulkUpdate($hash,"temperature",$vval);
|
||||||
#-- STATE
|
#-- STATE
|
||||||
@@ -501,7 +516,6 @@ sub OWTHERM_GetValues($@) {
|
|||||||
|
|
||||||
$value=OWTHERM_FormatValues($hash);
|
$value=OWTHERM_FormatValues($hash);
|
||||||
Log 5, $value;
|
Log 5, $value;
|
||||||
#-- one thing remains to do:
|
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@@ -534,7 +548,7 @@ sub OWTHERM_Set($@) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $model = $hash->{OW_MODEL};
|
my $model = $hash->{OW_MODEL};
|
||||||
|
|
||||||
#-- set new timer interval
|
#-- set new timer interval
|
||||||
if($key eq "interval") {
|
if($key eq "interval") {
|
||||||
# check value
|
# check value
|
||||||
return "OWTHERM: Set with short interval, must be > 1"
|
return "OWTHERM: Set with short interval, must be > 1"
|
||||||
@@ -547,37 +561,37 @@ sub OWTHERM_Set($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#-- set tempLow or tempHigh
|
#-- set tempLow or tempHigh
|
||||||
my $interface = $hash->{IODev}->{TYPE};
|
if( (lc($key) eq "templow") || (lc($key) eq "temphigh")) {
|
||||||
my $offset = defined($hash->{tempf}{offset}) ? $hash->{tempf}{offset} : 0.0;
|
my $interface = $hash->{IODev}->{TYPE};
|
||||||
my $factor = defined($hash->{tempf}{factor}) ? $hash->{tempf}{factor} : 1.0;
|
my $offset = defined($hash->{tempf}{offset}) ? $hash->{tempf}{offset} : 0.0;
|
||||||
|
my $factor = defined($hash->{tempf}{factor}) ? $hash->{tempf}{factor} : 1.0;
|
||||||
|
|
||||||
#-- find upper and lower boundaries for given offset/factor
|
#-- find upper and lower boundaries for given offset/factor
|
||||||
my $mmin = (-55+$offset)*$factor;
|
my $mmin = (-55+$offset)*$factor;
|
||||||
my $mmax = (125+$offset)*$factor;
|
my $mmax = (125+$offset)*$factor;
|
||||||
return sprintf("OWTHERM: Set with wrong value $value for $key, range is [%3.1f,%3.1f]",$mmin,$mmax)
|
return sprintf("OWTHERM: Set with wrong value $value for $key, range is [%3.1f,%3.1f]",$mmin,$mmax)
|
||||||
if($value < $mmin || $value > $mmax);
|
if($value < $mmin || $value > $mmax);
|
||||||
|
|
||||||
#-- seems to be ok, put into the device after correcting for offset and factor
|
#-- seems to be ok, put into the device after correcting for offset and factor
|
||||||
$a[2] = int($value/$factor-$offset);
|
$a[2] = int($value/$factor-$offset);
|
||||||
|
|
||||||
#-- OWX interface
|
#-- OWX interface
|
||||||
Log 1,"SETTING DEVICE with ".join(' ',@a)." and present=".$hash->{PRESENT}.
|
if( $interface eq "OWX" ){
|
||||||
" and state=".$hash->{READINGS}{"state"}{VAL};
|
$ret = OWXTHERM_SetValues($hash,@a);
|
||||||
if( $interface eq "OWX" ){
|
#-- OWFS interface
|
||||||
$ret = OWXTHERM_SetValues($hash,@a);
|
}elsif( $interface eq "OWServer" ){
|
||||||
#-- OWFS interface
|
$ret = OWFSTHERM_SetValues($hash,@a);
|
||||||
}elsif( $interface eq "OWServer" ){
|
} else {
|
||||||
$ret = OWFSTHERM_SetValues($hash,@a);
|
return "OWTHERM: Set with wrong IODev type $interface";
|
||||||
|
}
|
||||||
return $ret
|
return $ret
|
||||||
if(defined($ret));
|
if(defined($ret));
|
||||||
} else {
|
|
||||||
return "OWTHERM: Set with wrong IODev type $interface";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#-- process results - we have to reread the device
|
#-- process results - we have to reread the device
|
||||||
$hash->{PRESENT} = 1;
|
$hash->{PRESENT} = 1;
|
||||||
#OWTHERM_GetValues($hash);
|
#OWTHERM_GetValues($hash);
|
||||||
OWTHERM_FormatValues($hash);
|
#OWTHERM_FormatValues($hash);
|
||||||
Log 4, "OWTHERM: Set $hash->{NAME} $key $value";
|
Log 4, "OWTHERM: Set $hash->{NAME} $key $value";
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@@ -666,25 +680,9 @@ sub OWFSTHERM_GetValues($) {
|
|||||||
return "empty return from OWServer"
|
return "empty return from OWServer"
|
||||||
if( ($owg_temp eq "") || ($ow_thn eq "") || ($ow_tln eq "") );
|
if( ($owg_temp eq "") || ($ow_thn eq "") || ($ow_tln eq "") );
|
||||||
|
|
||||||
#return "wrong data length from OWServer"
|
|
||||||
# if( (int(@ral) != $cnumber{$attr{$name}{"model"}}) || (int(@rax) != $cnumber{$attr{$name}{"model"}}) );
|
|
||||||
|
|
||||||
#-- process alarm settings
|
#-- process alarm settings
|
||||||
#-- first reading of the device
|
$owg_tl = $ow_tln;
|
||||||
if( $owg_th eq ""){
|
$owg_th = $ow_thn;
|
||||||
$owg_th = $ow_thn;
|
|
||||||
#-- device must be changed
|
|
||||||
}elsif( $owg_th != $ow_thn ){
|
|
||||||
OWFSTHERM_SetValues($hash,"temphigh",$owg_th);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-- first reading of the device
|
|
||||||
if( $owg_tl eq ""){
|
|
||||||
$owg_tl = $ow_tln;
|
|
||||||
#-- device must be changed
|
|
||||||
}elsif( $owg_tl != $ow_tln ){
|
|
||||||
OWFSTHERM_SetValues($hash,"templow",$owg_tl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef
|
return undef
|
||||||
}
|
}
|
||||||
@@ -827,25 +825,9 @@ sub OWXTHERM_GetValues($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#-- process alarm settings
|
#-- process alarm settings
|
||||||
#-- first reading of the device
|
$owg_tl = $ow_tln;
|
||||||
if( $owg_th eq ""){
|
$owg_th = $ow_thn;
|
||||||
$owg_th = $ow_thn;
|
|
||||||
#-- device must be changed
|
|
||||||
}elsif( $owg_th != $ow_thn ){
|
|
||||||
$change=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#-- first reading of the device
|
|
||||||
if( $owg_tl eq ""){
|
|
||||||
$owg_tl = $ow_tln;
|
|
||||||
#-- device must be changed
|
|
||||||
}elsif( $owg_tl != $ow_tln ){
|
|
||||||
$change=1;
|
|
||||||
}
|
|
||||||
#-- change device settings
|
|
||||||
if( $change==1){
|
|
||||||
OWXTHERM_SetValues($hash,("both","0.0"));
|
|
||||||
}
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,6 +846,7 @@ sub OWXTHERM_SetValues($@) {
|
|||||||
my ($i,$j,$k);
|
my ($i,$j,$k);
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
#-- ID of the device
|
#-- ID of the device
|
||||||
my $owx_dev = $hash->{ROM_ID};
|
my $owx_dev = $hash->{ROM_ID};
|
||||||
#-- hash of the busmaster
|
#-- hash of the busmaster
|
||||||
@@ -878,8 +861,8 @@ sub OWXTHERM_SetValues($@) {
|
|||||||
if( $value eq "");
|
if( $value eq "");
|
||||||
|
|
||||||
#-- $owg_tl and $owg_th are preset and may be changed here
|
#-- $owg_tl and $owg_th are preset and may be changed here
|
||||||
$owg_tl = $value if( $key eq "tempLow" );
|
$owg_tl = $value if( lc($key) eq "templow" );
|
||||||
$owg_th = $value if( $key eq "tempHigh" );
|
$owg_th = $value if( lc($key) eq "temphigh");
|
||||||
|
|
||||||
#-- put into 2's complement formed (signed byte)
|
#-- put into 2's complement formed (signed byte)
|
||||||
my $tlp = $owg_tl < 0 ? 128 - $owg_tl : $owg_tl;
|
my $tlp = $owg_tl < 0 ? 128 - $owg_tl : $owg_tl;
|
||||||
@@ -896,7 +879,7 @@ sub OWXTHERM_SetValues($@) {
|
|||||||
# 3. \x48 sent by WriteBytePower after match ROM => command ok, no effect on EEPROM
|
# 3. \x48 sent by WriteBytePower after match ROM => command ok, no effect on EEPROM
|
||||||
|
|
||||||
my $select=sprintf("\x4E%c%c\x48",$thp,$tlp);
|
my $select=sprintf("\x4E%c%c\x48",$thp,$tlp);
|
||||||
my $res=OWX_Complex($master,$owx_dev,$select,0);
|
my $res=OWX_Complex($master,$owx_dev,$select,3);
|
||||||
|
|
||||||
if( $res eq 0 ){
|
if( $res eq 0 ){
|
||||||
return "OWXTHERM: Device $owx_dev not accessible";
|
return "OWXTHERM: Device $owx_dev not accessible";
|
||||||
|
|||||||
Reference in New Issue
Block a user