mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-07 19:04:20 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@1335 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
fc74bd6a23
commit
53450b770f
@ -6,7 +6,7 @@
|
||||
# via an active DS2480/DS2490/DS9097U bus master interface or
|
||||
# via a passive DS9097 interface
|
||||
#
|
||||
# Version 1.07 - March, 2012
|
||||
# Version 1.08 - March, 2012
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
#
|
||||
@ -17,10 +17,12 @@
|
||||
# where <name> may be replaced by any name string
|
||||
# <device> is a serial (USB) device
|
||||
#
|
||||
# get <name> alarms => find alarmed 1-Wire devices
|
||||
# get <name> devices => find all 1-Wire devices
|
||||
# get <name> alarms => find alarmed 1-Wire devices
|
||||
# get <name> devices => find all 1-Wire devices
|
||||
#
|
||||
# set <name> interval => set period for temperature conversion and alarm testing
|
||||
# set <name> interval <seconds> => set period for temperature conversion and alarm testing
|
||||
# set <name> followAlarms on/off => determine whether an alarm is followed by a search for
|
||||
# alarmed devices
|
||||
#
|
||||
# attr <name> buspower real/parasitic - whether the 1-Wire bus is really powered or
|
||||
# the 1-Wire devices take their power from the data wire (parasitic is default !)
|
||||
@ -68,7 +70,8 @@ my %gets = (
|
||||
|
||||
# These occur in a pulldown menu as settable values for the bus master
|
||||
my %sets = (
|
||||
"interval" => "T"
|
||||
"interval" => "T",
|
||||
"followAlarms" => "F"
|
||||
);
|
||||
|
||||
# These are attributes
|
||||
@ -345,7 +348,9 @@ sub OWX_Define ($$) {
|
||||
InternalTimer(gettimeofday()+5, "OWX_Discover", $hash,0);
|
||||
|
||||
#-- Default settings
|
||||
$hash->{interval} = 60; # kick every minute
|
||||
$hash->{interval} = 60; # kick every minute
|
||||
$hash->{followAlarms} = "off";
|
||||
$hash->{ALARMED} = "no";
|
||||
|
||||
#-- InternalTimer blocks if init_done is not true
|
||||
my $oid = $init_done;
|
||||
@ -608,12 +613,12 @@ sub OWX_Kick($) {
|
||||
my $ret;
|
||||
#-- Call us in n seconds again.
|
||||
InternalTimer(gettimeofday()+ $hash->{interval}, "OWX_Kick", $hash,1);
|
||||
|
||||
#-- During reset we see if an alarmed device is present.
|
||||
OWX_Reset($hash);
|
||||
|
||||
|
||||
#-- Only if we have real power on the bus
|
||||
if( defined($attr{$hash->{NAME}}{buspower}) && ($attr{$hash->{NAME}}{buspower} eq "real") ){
|
||||
#-- issue the skip ROM command \xCC followed by start conversion command \x44
|
||||
#-- issue the skip ROM command \xCC followed by start conversion command \x44
|
||||
$ret = OWX_Block($hash,"\xCC\x44");
|
||||
if( $ret eq 0 ){
|
||||
Log 3, "OWX: Failure in temperature conversion\n";
|
||||
@ -808,10 +813,25 @@ sub OWX_Set($@) {
|
||||
} else {
|
||||
$res = 0;
|
||||
}
|
||||
Log GetLogLevel($name,3), "OWX_Set $name ".join(" ",@a)." => $res";
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
return "OWX_Set => $name ".join(" ",@a)." => $res";
|
||||
}
|
||||
|
||||
#-- Set alarm behaviour
|
||||
if( $a[0] eq "followAlarms" ){
|
||||
#-- only values >= 15 secs allowed
|
||||
if( (lc($a[1]) eq "off") && ($hash->{followAlarms} eq "on") ){
|
||||
$hash->{interval} = "off";
|
||||
$res = 1;
|
||||
}elsif( (lc($a[1]) eq "on") && ($hash->{followAlarms} eq "off") ){
|
||||
$hash->{interval} = "off";
|
||||
$res = 1;
|
||||
} else {
|
||||
$res = 0;
|
||||
}
|
||||
|
||||
}
|
||||
Log GetLogLevel($name,3), "OWX_Set $name ".join(" ",@a)." => $res";
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
return "OWX_Set => $name ".join(" ",@a)." => $res";
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
@ -1043,6 +1063,7 @@ sub OWX_Reset_2480 ($) {
|
||||
Log 3, "OWX: Reset failure";
|
||||
return 0;
|
||||
}
|
||||
$hash->{ALARMED} = "no";
|
||||
|
||||
$r2 = ord(substr($res,0,1)) & 3;
|
||||
|
||||
@ -1051,6 +1072,7 @@ sub OWX_Reset_2480 ($) {
|
||||
return 0;
|
||||
}elsif( $r2 ==2 ){
|
||||
Log 1, "OWX: Alarm presence detected";
|
||||
$hash->{ALARMED} = "yes";
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
#
|
||||
# Version 1.07 - March, 2012
|
||||
# Version 1.08 - March, 2012
|
||||
#
|
||||
# Setup bus device in fhem.cfg as
|
||||
#
|
||||
@ -37,12 +37,20 @@
|
||||
#
|
||||
# set <name> interval => set period for measurement
|
||||
#
|
||||
# Additional attributes are defined in fhem.cfg per channel, where <channel>=A,B,C,D
|
||||
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B,C,D
|
||||
# Note: attributes are read only during initialization procedure - later changes are not used.
|
||||
#
|
||||
# attr <name> <channel>Name <string> = a name for the channel
|
||||
# attr <name> <channel>Offset <float> = an offset added to the reading in this channel
|
||||
# attr <name> <channel>Factor <float> = a factor multiplied to (reading+offset) in this channel
|
||||
# attr <name> <channel>Unit <string> = a unit of measurement for this channel
|
||||
# attr <name> stateAL0 "<string>" = character string for denoting low normal condition, default is green down triangle
|
||||
# attr <name> stateAH0 "<string>" = character string for denoting high normal condition, default is green up triangle
|
||||
# attr <name> stateAL1 "<string>" = character string for denoting low alarm condition, default is red down triangle
|
||||
# attr <name> stateAH1 "<string>" = character string for denoting high alarm condition, default is red up triangle
|
||||
# attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value
|
||||
# attr <name> <channel>Unit <string>|<string> = unit of measurement for this channel | its abbreviation
|
||||
# attr <name> <channel>Offset <float> = offset added to the reading in this channel
|
||||
# attr <name> <channel>Factor <float> = factor multiplied to (reading+offset) in this channel
|
||||
# attr <name> <channel>Alarm = alarm setting in this channel, either both, low, high or none (default)
|
||||
# attr <name> <channel>Low <float> = measurement value for low alarm
|
||||
# attr <name> <channel>High <float> = measurement for high alarm
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
@ -70,25 +78,28 @@ use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
##-- value globals
|
||||
#-- value globals
|
||||
my @owg_status;
|
||||
my $owg_state;
|
||||
#-- channel name - fixed is the first array, variable the second
|
||||
my @owg_fixed = ("A","B","C","D");
|
||||
my @owg_channel = ("A","B","C","D");
|
||||
#-- channel values
|
||||
my @owg_fixed = ("A","B","C","D");
|
||||
my @owg_channel;
|
||||
#-- channel values - always the raw values from the device
|
||||
my @owg_val;
|
||||
#-- channel mode
|
||||
#-- channel mode - fixed for now
|
||||
my @owg_mode = ("input","input","input","input");
|
||||
#-- resolution in bit - fixed for now
|
||||
my @owg_resoln = (16,16,16,16);
|
||||
#-- bare range in mV - fixed for now
|
||||
#-- raw range in mV - fixed for now
|
||||
my @owg_range = (5100,5100,5100,5100);
|
||||
#-- alarm status 0 = disabled, 1 = enabled, but not alarmed, 2 = alarmed
|
||||
my @owg_alarmlow = (0,0,0,0);
|
||||
my @owg_alarmhigh = (0,0,0,0);
|
||||
#-- alarm values
|
||||
my @owg_low = (0.0,0.0,0.0,0.0);
|
||||
my @owg_high = (5.0,5.0,5.0,5.0);
|
||||
my @owg_slow;
|
||||
my @owg_shigh;
|
||||
#-- alarm values - always the raw values committed to the device
|
||||
my @owg_vlow;
|
||||
my @owg_vhigh;
|
||||
#-- variables for display strings
|
||||
my ($stateal1,$stateah1,$stateal0,$stateah0);
|
||||
|
||||
my %gets = (
|
||||
"id" => "",
|
||||
@ -132,17 +143,21 @@ sub OWAD_Initialize ($) {
|
||||
$hash->{UndefFn} = "OWAD_Undef";
|
||||
$hash->{GetFn} = "OWAD_Get";
|
||||
$hash->{SetFn} = "OWAD_Set";
|
||||
#name = channel name
|
||||
#offset = a v(oltage) offset added to the reading
|
||||
#factor = a v(oltage) factor multiplied with (reading+offset)
|
||||
#unit = a unit of measure
|
||||
#Name = channel name
|
||||
#Offset = a v(oltage) offset added to the reading
|
||||
#Factor = a v(oltage) factor multiplied with (reading+offset)
|
||||
#Unit = a unit of measure
|
||||
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2450 loglevel:0,1,2,3,4,5 ".
|
||||
"channels ";
|
||||
"stateAL0 stateAL1 stateAH0 stateAH1 ";
|
||||
|
||||
for( my $i=0;$i<4;$i++ ){
|
||||
$attlist .= " ".$owg_fixed[$i]."Name";
|
||||
$attlist .= " ".$owg_fixed[$i]."Offset";
|
||||
$attlist .= " ".$owg_fixed[$i]."Factor";
|
||||
$attlist .= " ".$owg_fixed[$i]."Unit";
|
||||
$attlist .= " ".$owg_fixed[$i]."Alarm";
|
||||
$attlist .= " ".$owg_fixed[$i]."Low";
|
||||
$attlist .= " ".$owg_fixed[$i]."High";
|
||||
}
|
||||
$hash->{AttrList} = $attlist;
|
||||
}
|
||||
@ -195,45 +210,29 @@ sub OWAD_Define ($$) {
|
||||
$crc = sprintf("%02x",OWX_CRC("20.".$id."00"));
|
||||
|
||||
#-- Define device internals
|
||||
$hash->{INTERVAL} = $interval;
|
||||
$hash->{ROM_ID} = "20.".$id.$crc;
|
||||
$hash->{OW_ID} = $id;
|
||||
$hash->{OW_FAMILY} = 20;
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
Log 3, "OWAD: Warning, no 1-Wire I/O device found for $name."
|
||||
if(!defined($hash->{IODev}->{NAME}));
|
||||
|
||||
$modules{OWAD}{defptr}{$id} = $hash;
|
||||
|
||||
$hash->{STATE} = "Defined";
|
||||
Log 3, "OWAD: Device $name defined.";
|
||||
|
||||
#-- Initialization reading according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
OWXAD_SetPage($hash,"alarm");
|
||||
OWXAD_SetPage($hash,"status");
|
||||
#-- OWFS interface
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSAD_GetPage($hash,"reading");
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWAD: Define with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- Start timer for initialization in a few seconds
|
||||
InternalTimer(time()+1, "OWAD_InitializeDevice", $hash, 0);
|
||||
|
||||
#-- Start timer for updates
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 0);
|
||||
|
||||
#-- InternalTimer blocks if init_done is not true
|
||||
#my $oid = $init_done;
|
||||
$hash->{STATE} = "Initialized";
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
@ -248,32 +247,165 @@ sub OWAD_Define ($$) {
|
||||
sub OWAD_InitializeDevice($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
#-- name attribute present ?
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
$stateal1 = defined($attr{$name}{stateAL1}) ? $attr{$name}{stateAL1} : "<span style=\"color:red\">▾</span>";
|
||||
$stateah1 = defined($attr{$name}{stateAH1}) ? $attr{$name}{stateAH1} : "<span style=\"color:red\">▴</span>";
|
||||
$stateal0 = defined($attr{$name}{stateAL0}) ? $attr{$name}{stateAL0} : "<span style=\"color:green\">▾</span>";
|
||||
$stateah0 = defined($attr{$name}{stateAH0}) ? $attr{$name}{stateAH0} : "<span style=\"color:green\">▴</span>";
|
||||
|
||||
#-- Initial readings
|
||||
@owg_val = (0.0,0.0,0.0,0.0);
|
||||
@owg_slow = (0,0,0,0);
|
||||
@owg_shigh = (0,0,0,0);
|
||||
|
||||
#-- Set channel names, channel units and alarm values
|
||||
for( my $i=0;$i<4;$i++) {
|
||||
if( defined($attr{$name}{$owg_fixed[$i]."Name"}) ){
|
||||
$owg_channel[$i]= $attr{$name}{$owg_fixed[$i]."Name"};
|
||||
#-- name
|
||||
my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i]."|voltage";
|
||||
my @cnama = split(/\|/,$cname);
|
||||
Log 1, "OWAD: InitializeDevice with insufficient name specification $cname"
|
||||
if( int(@cnama)!=2 );
|
||||
$owg_channel[$i] = $cnama[0];
|
||||
#-- unit
|
||||
my $unit = defined($attr{$name}{$owg_fixed[$i]."Unit"}) ? $attr{$name}{$owg_fixed[$i]."Unit"} : "Volt|V";
|
||||
my @unarr= split(/\|/,$unit);
|
||||
Log 1, "OWAD: InitializeDevice with insufficient unit specification $unit"
|
||||
if( int(@unarr)!=2 );
|
||||
#-- offset and scale factor
|
||||
my $offset = defined($attr{$name}{$owg_fixed[$i]."Offset"}) ? $attr{$name}{$owg_fixed[$i]."Offset"} : 0.0;
|
||||
my $factor = defined($attr{$name}{$owg_fixed[$i]."Factor"}) ? $attr{$name}{$owg_fixed[$i]."Factor"} : 1.0;
|
||||
#-- put into readings
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{TYPE} = defined($cnama[1]) ? $cnama[1] : "unknown";
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{UNIT} = $unarr[0];
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR} = defined($unarr[1]) ? $unarr[1] : "?";
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{OFFSET} = $offset;
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{FACTOR} = $factor;
|
||||
|
||||
#-- alarm
|
||||
my $alarm = defined($attr{$name}{$owg_fixed[$i]."Alarm"}) ? $attr{$name}{$owg_fixed[$i]."Alarm"} : "none";
|
||||
my $vlow = defined($attr{$name}{$owg_fixed[$i]."Low"}) ? $attr{$name}{$owg_fixed[$i]."Low"} : 0.0;
|
||||
my $vhigh = defined($attr{$name}{$owg_fixed[$i]."High"}) ? $attr{$name}{$owg_fixed[$i]."High"} : 5.0;
|
||||
if( $alarm eq "low" || $alarm eq "both" ){
|
||||
$owg_slow[$i]=1;
|
||||
}
|
||||
if( $alarm eq "high" || $alarm eq "both" ){
|
||||
$owg_shigh[$i]=1;
|
||||
};
|
||||
$owg_vlow[$i] = ($vlow/$factor - $offset);
|
||||
$owg_vhigh[$i] = ($vhigh/$factor - $offset);
|
||||
}
|
||||
|
||||
#-- set status according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
OWXAD_SetPage($hash,"alarm");
|
||||
OWXAD_SetPage($hash,"status");
|
||||
#-- OWFS interface
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSAD_GetPage($hash,"reading");
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWAD: InitializeDevice with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- Initialize all the display stuff
|
||||
OWAD_FormatValues($hash);
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWAD_FormatValues - put together various format strings
|
||||
#
|
||||
# Parameter hash = hash of device addressed, fs = format string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWAD_FormatValues($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my ($offset,$factor,$vval,$vlow,$vhigh);
|
||||
my ($value1,$value2,$value3) = ("","","");
|
||||
my $galarm = 0;
|
||||
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- formats for output
|
||||
for (my $i=0;$i<4;$i++){
|
||||
$offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET};
|
||||
$factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR};
|
||||
#-- correct values for proper offset, factor
|
||||
$vval = int(($owg_val[$i] + $offset)*$factor*1000)/1000;;
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vval;
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn;
|
||||
|
||||
#-- correct alarm values for proper offset, factor
|
||||
$vlow = int(($owg_vlow[$i] + $offset)*$factor*1000)/1000;
|
||||
$vhigh = int(($owg_vhigh[$i] + $offset)*$factor*1000)/1000;
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{VAL} = $vlow;
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{TIME} = $tn;
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{VAL} = $vhigh;
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{TIME} = $tn;
|
||||
|
||||
#-- string buildup for return value, STATE and alarm
|
||||
$value1 .= sprintf( "%s: %5.3f %s", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
|
||||
$value2 .= sprintf( "%s: %5.2f %s ", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
|
||||
$value3 .= sprintf( "%s: " , $owg_channel[$i]);
|
||||
|
||||
#-- Test for alarm condition
|
||||
#-- alarm signature low
|
||||
if( $owg_slow[$i] == 0 ) {
|
||||
#$value2 .= " ";
|
||||
$value3 .= "-";
|
||||
} else {
|
||||
if( $vval > $vlow ){
|
||||
$owg_slow[$i] = 1;
|
||||
$value2 .= $stateal0;
|
||||
$value3 .= $stateal0;
|
||||
} else {
|
||||
$galarm = 1;
|
||||
$owg_slow[$i] = 2;
|
||||
$value2 .= $stateal1;
|
||||
$value3 .= $stateal1;
|
||||
}
|
||||
}
|
||||
#-- alarm signature high
|
||||
if( $owg_shigh[$i] == 0 ) {
|
||||
#$value2 .= " ";
|
||||
$value3 .= "-";
|
||||
} else {
|
||||
if( $vval < $vhigh ){
|
||||
$owg_shigh[$i] = 1;
|
||||
$value2 .= $stateah0;
|
||||
$value3 .= $stateah0;
|
||||
} else {
|
||||
$galarm = 1;
|
||||
$owg_shigh[$i] = 2;
|
||||
$value2 .= $stateah1;
|
||||
$value3 .= $stateah1;
|
||||
}
|
||||
}
|
||||
|
||||
#-- insert comma
|
||||
if( $i<3 ){
|
||||
$value1 .= " ";
|
||||
$value2 .= ", ";
|
||||
$value3 .= ", ";
|
||||
}
|
||||
}
|
||||
|
||||
my $value2 = "";
|
||||
for (my $i=0;$i<4;$i++){
|
||||
#-- Initial readings values
|
||||
$hash->{READINGS}{$owg_channel[$i]}{VAL} = 0.0;
|
||||
$hash->{READINGS}{$owg_channel[$i]}{TIME} = "";
|
||||
#$hash->{READINGS}{$owg_channel[$i]}{UNIT} = "volt";
|
||||
#$hash->{READINGS}{$owg_channel[$i]}{TYPE} = "voltage";
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{VAL} = 0.0;
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{TIME} = "";
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{VAL} = 0.0;
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{TIME} = "";
|
||||
|
||||
$value2 .= sprintf "%s: L- H- ",$owg_channel[$i];
|
||||
}
|
||||
$hash->{READINGS}{alarms}{VAL} = $value2;
|
||||
$hash->{READINGS}{alarms}{TIME} = "";
|
||||
|
||||
|
||||
#-- STATE
|
||||
$hash->{STATE} = $value2;
|
||||
#-- alarm
|
||||
$hash->{ALARM} = $galarm;
|
||||
$hash->{READINGS}{alarms}{VAL} = $value3;
|
||||
$hash->{READINGS}{alarms}{TIME} = $tn;
|
||||
return $value1;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
@ -290,7 +422,7 @@ sub OWAD_Get($@) {
|
||||
my $reading = $a[1];
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
my $value = undef;
|
||||
my ($value,$value2,$value3) = (undef,undef,undef);
|
||||
my $ret = "";
|
||||
my $offset;
|
||||
my $factor;
|
||||
@ -346,22 +478,7 @@ sub OWAD_Get($@) {
|
||||
return "OWAD: Could not get values from device $name";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
my $tn = TimeNow();
|
||||
$value = "";
|
||||
|
||||
for (my $i=0;$i<4;$i++){
|
||||
#-- correct values for proper offset, factor
|
||||
$offset = $attr{$name}{$owg_fixed[$i]."Offset"};
|
||||
$factor = $attr{$name}{$owg_fixed[$i]."Factor"};
|
||||
$owg_val[$i] += $offset if ($offset );
|
||||
$owg_val[$i] *= $factor if ($factor );
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{$owg_channel[$i]}{VAL} = $owg_val[$i];
|
||||
$hash->{READINGS}{$owg_channel[$i]}{TIME} = $tn;
|
||||
$value .= sprintf "%s: %5.3f ",$owg_channel[$i],$owg_val[$i];
|
||||
}
|
||||
return "OWAD: $name.$reading => $value";
|
||||
return "OWAD: $name.$reading => ".OWAD_FormatValues($hash);
|
||||
}
|
||||
|
||||
#-- get alarm values according to interface type
|
||||
@ -382,25 +499,14 @@ sub OWAD_Get($@) {
|
||||
return "OWAD: Could not get values from device $name";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
my $tn = TimeNow();
|
||||
$value = "";
|
||||
OWAD_FormatValues($hash);
|
||||
|
||||
#-- output string looks differently here
|
||||
$value = "";
|
||||
for (my $i=0;$i<4;$i++){
|
||||
#-- correct alarm values for proper offset, factor
|
||||
$offset = $attr{$name}{$owg_fixed[$i]."Offset"};
|
||||
$factor = $attr{$name}{$owg_fixed[$i]."Factor"};
|
||||
$owg_low[$i] += $offset if ($offset );
|
||||
$owg_low[$i] *= $factor if ($factor );
|
||||
$owg_high[$i] += $offset if ($offset );
|
||||
$owg_high[$i] *= $factor if ($factor );
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{VAL} = $owg_low[$i];
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{TIME} = $tn;
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{VAL} = $owg_high[$i];
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{TIME} = $tn;
|
||||
|
||||
$value .= sprintf "%s:[%4.2f,%4.2f] ",$owg_channel[$i],$owg_low[$i],$owg_high[$i];
|
||||
$value .= sprintf "%s:[%4.2f,%4.2f] ",$owg_channel[$i],
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{VAL},
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{VAL};
|
||||
}
|
||||
return "OWAD: $name.$reading => $value";
|
||||
}
|
||||
@ -423,32 +529,8 @@ sub OWAD_Get($@) {
|
||||
return "OWAD: Could not get values from device $name";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
my $tn = TimeNow();
|
||||
$value = "";
|
||||
|
||||
my $value2 = "";
|
||||
for (my $i=0;$i<4;$i++){
|
||||
$value .= sprintf "%s: %s \n",$owg_channel[$i],$owg_status[$i];
|
||||
$value2 .= sprintf "%s: L",$owg_channel[$i];
|
||||
if( $owg_alarmlow[$i] == 0 ) {
|
||||
$value2 .= "- ";
|
||||
}elsif( $owg_alarmlow[$i] == 1 ) {
|
||||
$value2 .= "+ ";
|
||||
}else{
|
||||
$value2 .= "* ";
|
||||
}
|
||||
$value2 .= sprintf " H";
|
||||
if( $owg_alarmhigh[$i] == 0 ) {
|
||||
$value2 .= "- ";
|
||||
}elsif( $owg_alarmhigh[$i] == 1 ) {
|
||||
$value2 .= "+ ";
|
||||
}else{
|
||||
$value2 .= "* ";
|
||||
}
|
||||
}
|
||||
$hash->{READINGS}{alarms}{VAL} = $value2;
|
||||
$hash->{READINGS}{alarms}{TIME} = $tn;
|
||||
return "OWAD: $name.$reading => \n$value";
|
||||
OWAD_FormatValues($hash);
|
||||
return "OWAD: $name.$reading => ".$hash->{READINGS}{alarms}{VAL};
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,7 +542,7 @@ sub OWAD_Get($@) {
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWAD_GetValues($@) {
|
||||
sub OWAD_GetValues($) {
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
@ -498,54 +580,11 @@ sub OWAD_GetValues($@) {
|
||||
return "OWAD: Could not get values from device $name";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
my $tn = TimeNow();
|
||||
$value = "";
|
||||
my $value2 ="";
|
||||
|
||||
for (my $i=0;$i<4;$i++){
|
||||
#-- correct values for proper offset, factor
|
||||
$offset = $attr{$name}{$owg_fixed[$i]."Offset"};
|
||||
$factor = $attr{$name}{$owg_fixed[$i]."Factor"};
|
||||
$owg_val[$i] += $offset if ($offset );
|
||||
$owg_val[$i] *= $factor if ($factor );
|
||||
#-- correct alarm values for proper offset, factor
|
||||
$owg_low[$i] += $offset if ($offset );
|
||||
$owg_low[$i] *= $factor if ($factor );
|
||||
$owg_high[$i] += $offset if ($offset );
|
||||
$owg_high[$i] *= $factor if ($factor );
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{$owg_channel[$i]}{VAL} = $owg_val[$i];
|
||||
$hash->{READINGS}{$owg_channel[$i]}{TIME} = $tn;
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{VAL} = $owg_low[$i];
|
||||
$hash->{READINGS}{$owg_channel[$i]."Low"}{TIME} = $tn;
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{VAL} = $owg_high[$i];
|
||||
$hash->{READINGS}{$owg_channel[$i]."High"}{TIME} = $tn;
|
||||
$value .= sprintf "%s: %5.3f ",$owg_channel[$i],$owg_val[$i];
|
||||
|
||||
$value2 .= sprintf "%s: L",$owg_channel[$i];
|
||||
if( $owg_alarmlow[$i] == 0 ) {
|
||||
$value2 .= "- ";
|
||||
}elsif( $owg_alarmlow[$i] == 1 ) {
|
||||
$value2 .= "+ ";
|
||||
}else{
|
||||
$value2 .= "* ";
|
||||
}
|
||||
$value2 .= sprintf " H";
|
||||
if( $owg_alarmhigh[$i] == 0 ) {
|
||||
$value2 .= "- ";
|
||||
}elsif( $owg_alarmhigh[$i] == 1 ) {
|
||||
$value2 .= "+ ";
|
||||
}else{
|
||||
$value2 .= "* ";
|
||||
}
|
||||
}
|
||||
$hash->{READINGS}{alarms}{VAL} = $value2;
|
||||
$hash->{READINGS}{alarms}{TIME} = $tn;
|
||||
|
||||
$value=OWAD_FormatValues($hash);
|
||||
#--logging
|
||||
Log 5, $value;
|
||||
$hash->{CHANGED}[0] = $value;
|
||||
|
||||
DoTrigger($name, undef);
|
||||
|
||||
return undef;
|
||||
@ -630,14 +669,14 @@ sub OWAD_Set($@) {
|
||||
return "OWAD: Set with wrong value $value for $key, allowed is none/low/high/both"
|
||||
if($value ne "none" && $value ne "low" && $value ne "high" && $value ne "both");
|
||||
if( $value eq "low" || $value eq "both" ){
|
||||
$owg_alarmlow[$channo]=1;
|
||||
$owg_slow[$channo]=1;
|
||||
} else{
|
||||
$owg_alarmlow[$channo]=0;
|
||||
$owg_slow[$channo]=0;
|
||||
}
|
||||
if( $value eq "high" || $value eq "both" ){
|
||||
$owg_alarmhigh[$channo]=1;
|
||||
$owg_shigh[$channo]=1;
|
||||
} else{
|
||||
$owg_alarmhigh[$channo]=0;
|
||||
$owg_shigh[$channo]=0;
|
||||
}
|
||||
|
||||
#-- OWX interface
|
||||
@ -672,17 +711,14 @@ sub OWAD_Set($@) {
|
||||
|
||||
$value /= $factor if ( $factor );
|
||||
$value -= $offset if ( $offset );
|
||||
#-- round to those numbers understood by the device and backward into the value;
|
||||
#-- round to those numbers understood by the device
|
||||
my $value2 = int($value*255000/$owg_range[$channo])*$owg_range[$channo]/255000;
|
||||
$value = $value2;
|
||||
$value += $offset if ( $offset );
|
||||
$value *= $factor if ( $factor );
|
||||
|
||||
#-- set alarm value in the device
|
||||
if( $key =~ m/(.*)Low/ ){
|
||||
$owg_low[$channo] = $value2;
|
||||
$owg_vlow[$channo] = $value2;
|
||||
} elsif( $key =~ m/(.*)High/ ){
|
||||
$owg_high[$channo] = $value2;
|
||||
$owg_vhigh[$channo] = $value2;
|
||||
}
|
||||
|
||||
#-- OWX interface
|
||||
@ -699,58 +735,11 @@ sub OWAD_Set($@) {
|
||||
return "OWAD: Set with wrong IODev type $interface";
|
||||
}
|
||||
}
|
||||
|
||||
#-- process results
|
||||
my $tn = TimeNow();
|
||||
#-- set alarm value in the readings
|
||||
if( $key =~ m/(.*)Low/ ){
|
||||
$hash->{READINGS}{$owg_channel[$channo]."Low"}{VAL} = $value;
|
||||
$hash->{READINGS}{$owg_channel[$channo]."Low"}{TIME} = $tn;
|
||||
#-- Test for alarm condition, her ewith the raw values (uncorrected)
|
||||
if ( $owg_low[$channo] > $owg_val[$channo] ){
|
||||
$owg_alarmlow[$channo] = 2
|
||||
if($owg_alarmlow[$channo] == 1);
|
||||
} elsif ($owg_alarmlow[$channo] == 2) {
|
||||
$condx = 1;
|
||||
$owg_alarmlow[$channo] = 1;
|
||||
}
|
||||
} elsif( $key =~ m/(.*)High/ ){
|
||||
$hash->{READINGS}{$owg_channel[$channo]."High"}{VAL} = $value;
|
||||
$hash->{READINGS}{$owg_channel[$channo]."High"}{TIME} = $tn;
|
||||
#-- Test for new alarm condition
|
||||
$condx = 0;
|
||||
if( $channo && defined($owg_val[$channo]) ){
|
||||
if( $owg_high[$channo] < $owg_val[$channo] ){
|
||||
$owg_alarmhigh[$channo] = 2
|
||||
if($owg_alarmhigh[$channo] == 1);
|
||||
} elsif($owg_alarmhigh[$channo] == 2) {
|
||||
$condx = 1;
|
||||
$owg_alarmhigh[$channo] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#-- set up a new alarm string for the status display
|
||||
my $value2 = "";
|
||||
for (my $i=0;$i<4;$i++){
|
||||
$value2 .= sprintf "%s: L",$owg_channel[$i];
|
||||
if( $owg_alarmlow[$i] == 0 ) {
|
||||
$value2 .= "- ";
|
||||
}elsif( $owg_alarmlow[$i] == 1 ) {
|
||||
$value2 .= "+ ";
|
||||
}else{
|
||||
$value2 .= "* ";
|
||||
}
|
||||
$value2 .= sprintf " H";
|
||||
if( $owg_alarmhigh[$i] == 0 ) {
|
||||
$value2 .= "- ";
|
||||
}elsif( $owg_alarmhigh[$i] == 1 ) {
|
||||
$value2 .= "+ ";
|
||||
}else{
|
||||
$value2 .= "* ";
|
||||
}
|
||||
}
|
||||
$hash->{READINGS}{alarms}{VAL} = $value2;
|
||||
$hash->{READINGS}{alarms}{TIME} = $tn;
|
||||
|
||||
$hash->{PRESENT} = 1;
|
||||
OWAD_FormatValues($hash);
|
||||
|
||||
Log 4, "OWAD: Set $hash->{NAME} $key $value";
|
||||
return undef;
|
||||
}
|
||||
@ -884,8 +873,8 @@ sub OWXAD_GetPage($$) {
|
||||
#=============== get the alarm reading ===============================
|
||||
} elsif ( $page eq "alarm" ) {
|
||||
for( $i=0;$i<4;$i++){
|
||||
$owg_low[$i] = int(ord($data[12+2*$i])/255 * $owg_range[$i])/1000;
|
||||
$owg_high[$i] = int(ord($data[13+2*$i])/255 * $owg_range[$i])/1000;
|
||||
$owg_vlow[$i] = int(ord($data[12+2*$i])/255 * $owg_range[$i])/1000;
|
||||
$owg_vhigh[$i] = int(ord($data[13+2*$i])/255 * $owg_range[$i])/1000;
|
||||
}
|
||||
#=============== get the status reading ===============================
|
||||
} elsif ( $page eq "status" ) {
|
||||
@ -902,26 +891,26 @@ sub OWXAD_GetPage($$) {
|
||||
$owg_range[$i] = ($sb2 & 1) ? 5100 : 2550;
|
||||
#-- low alarm disabled
|
||||
if( ($sb2 & 4)==0 ){
|
||||
$owg_alarmlow[$i] = 0;
|
||||
$owg_slow[$i] = 0;
|
||||
}else {
|
||||
#-- low alarm enabled and not set
|
||||
if ( ($sb2 & 16)==0 ){
|
||||
$owg_alarmlow[$i] = 1;
|
||||
$owg_slow[$i] = 1;
|
||||
#-- low alarm enabled and set
|
||||
}else{
|
||||
$owg_alarmlow[$i] = 2;
|
||||
$owg_slow[$i] = 2;
|
||||
}
|
||||
}
|
||||
#-- high alarm disabled
|
||||
if( ($sb2 & 8)==0 ){
|
||||
$owg_alarmhigh[$i] = 0;
|
||||
$owg_shigh[$i] = 0;
|
||||
}else {
|
||||
#-- high alarm enabled and not set
|
||||
if ( ($sb2 & 32)==0 ){
|
||||
$owg_alarmhigh[$i] = 1;
|
||||
$owg_shigh[$i] = 1;
|
||||
#-- high alarm enabled and set
|
||||
}else{
|
||||
$owg_alarmhigh[$i] = 2;
|
||||
$owg_shigh[$i] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -932,17 +921,17 @@ sub OWXAD_GetPage($$) {
|
||||
$owg_status[$i] .= sprintf "raw range %3.1f V, ",$owg_range[$i]/1000;
|
||||
$owg_status[$i] .= sprintf "resolution %d bit, ",$owg_resoln[$i];
|
||||
$owg_status[$i] .= sprintf "low alarm disabled, "
|
||||
if( $owg_alarmlow[$i]==0 );
|
||||
if( $owg_slow[$i]==0 );
|
||||
$owg_status[$i] .= sprintf "low alarm enabled, "
|
||||
if( $owg_alarmlow[$i]==1 );
|
||||
if( $owg_slow[$i]==1 );
|
||||
$owg_status[$i] .= sprintf "alarmed low, "
|
||||
if( $owg_alarmlow[$i]==2 );
|
||||
if( $owg_slow[$i]==2 );
|
||||
$owg_status[$i] .= sprintf "high alarm disabled"
|
||||
if( $owg_alarmhigh[$i]==0 );
|
||||
if( $owg_shigh[$i]==0 );
|
||||
$owg_status[$i] .= sprintf "high alarm enabled"
|
||||
if( $owg_alarmhigh[$i]==1 );
|
||||
if( $owg_shigh[$i]==1 );
|
||||
$owg_status[$i] .= sprintf "alarmed high"
|
||||
if( $owg_alarmhigh[$i]==2 );
|
||||
if( $owg_shigh[$i]==2 );
|
||||
|
||||
} else {
|
||||
$owg_mode[$i] = "output";
|
||||
@ -999,9 +988,9 @@ sub OWXAD_SetPage($$) {
|
||||
$select=sprintf("\x55%c%c%c%c%c%c%c%c\x55\x10\x00",
|
||||
@owx_ROM_ID);
|
||||
for( $i=0;$i<4;$i++){
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",int($owg_low[$i]*255000/$owg_range[$i]);
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",int($owg_high[$i]*255000/$owg_range[$i]);
|
||||
#print "Setting alarm values to ".int($owg_low[$i]*255000/$owg_range[$i])." ".int($owg_high[$i]*255000/$owg_range[$i])."\n";
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",int($owg_vlow[$i]*255000/$owg_range[$i]);
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",int($owg_vhigh[$i]*255000/$owg_range[$i]);
|
||||
#print "XXXXXX> Setting alarm values to ".int($owg_vlow[$i]*255000/$owg_range[$i])." ".int($owg_vhigh[$i]*255000/$owg_range[$i])."\n";
|
||||
}
|
||||
#=============== set the status ===============================
|
||||
} elsif ( $page eq "status" ) {
|
||||
@ -1015,8 +1004,8 @@ sub OWXAD_SetPage($$) {
|
||||
#-- resolution (TODO: check !)
|
||||
$sb1 = $owg_resoln[$i]-1;
|
||||
#-- alarm enabled
|
||||
$sb2 = ( $owg_alarmlow[$i] > 0 ) ? 4 : 0;
|
||||
$sb2 += ( $owg_alarmhigh[$i] > 0 ) ? 8 : 0;
|
||||
$sb2 = ( $owg_slow[$i] > 0 ) ? 4 : 0;
|
||||
$sb2 += ( $owg_shigh[$i] > 0 ) ? 8 : 0;
|
||||
#-- range
|
||||
$sb2 |= 1
|
||||
if( $owg_range[$i] > 2550 );
|
||||
@ -1026,7 +1015,7 @@ sub OWXAD_SetPage($$) {
|
||||
}
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",$sb1;
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",$sb2;
|
||||
#print "setting status bytes $sb1 $sb2\n";
|
||||
#print "YYYYYYYYYYY>setting status bytes $sb1 $sb2\n";
|
||||
}
|
||||
#=============== wrong value requested ===============================
|
||||
} else {
|
||||
|
@ -12,7 +12,7 @@
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
#
|
||||
# Version 1.07 - March, 2012
|
||||
# Version 1.08 - March, 2012
|
||||
#
|
||||
# Setup bus device in fhem.cfg as
|
||||
#
|
||||
|
@ -16,7 +16,7 @@
|
||||
# Martin Fischer, 2011
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
#
|
||||
# Version 1.07 - March, 2012
|
||||
# Version 1.08 - March, 2012
|
||||
#
|
||||
# Setup bus device in fhem.cfg as
|
||||
#
|
||||
@ -38,13 +38,18 @@
|
||||
# get <name> alarm => alarm temperature settings
|
||||
#
|
||||
# set <name> interval => set period for measurement
|
||||
# set <name> tempLow => lower alarm temperature setting
|
||||
# set <name> tempLow => lower alarm temperature setting
|
||||
# set <name> tempHigh => higher alarm temperature setting
|
||||
#
|
||||
# Additional attributes are defined in fhem.cfg as
|
||||
# Additional attributes are defined in fhem.cfg
|
||||
# Note: attributes "tempXXXX" are read during every update operation.
|
||||
#
|
||||
# attr <name> tempOffset <float> = a temperature offset added to the temperature reading
|
||||
# attr <name> tempUnit <string> = a a unit of measurement, e.g. Celsius/Kelvin/Fahrenheit/Reaumur
|
||||
# attr <name> stateAL "<string>" = character string for denoting low alarm condition, default is red down triangle
|
||||
# attr <name> stateAH "<string>" = character string for denoting high alarm condition, default is red up triangle
|
||||
# attr <name> tempOffset <float> = temperature offset in degree Celsius added to the raw temperature reading
|
||||
# attr <name> tempUnit <string> = unit of measurement, e.g. Celsius/Kelvin/Fahrenheit or C/K/F, default is Celsius
|
||||
# attr <name> tempLow <float> = measurement value for low alarm
|
||||
# attr <name> tempHigh <float> = measurement for high alarm
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
@ -75,10 +80,14 @@ use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
#-- temperature globals
|
||||
my $owg_temp=0;
|
||||
my $owg_th=0;
|
||||
my $owg_tl=0;
|
||||
#-- temperature globals - always the raw values from the device
|
||||
my $owg_temp = 0;
|
||||
my $owg_th = 0;
|
||||
my $owg_tl = 0;
|
||||
|
||||
#-- variables for display strings
|
||||
my $stateal;
|
||||
my $stateah;
|
||||
|
||||
my %gets = (
|
||||
"id" => "",
|
||||
@ -121,10 +130,12 @@ sub OWTEMP_Initialize ($) {
|
||||
$hash->{UndefFn} = "OWTEMP_Undef";
|
||||
$hash->{GetFn} = "OWTEMP_Get";
|
||||
$hash->{SetFn} = "OWTEMP_Set";
|
||||
#offset = a temperature offset added to the temperature reading for correction
|
||||
#scale = a unit of measure: C/F/K/R
|
||||
#tempOffset = a temperature offset added to the temperature reading for correction
|
||||
#tempUnit = a unit of measure: C/F/K
|
||||
$hash->{AttrList}= "IODev do_not_notify:0,1 showtime:0,1 loglevel:0,1,2,3,4,5 ".
|
||||
"tempOffset tempUnit:Celsius,Fahrenheit,Kelvin,Reaumur";
|
||||
"stateAL stateAH ".
|
||||
"tempOffset tempUnit:C,Celsius,F,Fahrenheit,K,Kelvin ".
|
||||
"tempLow tempHigh";
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
@ -179,7 +190,7 @@ sub OWTEMP_Define ($$) {
|
||||
# FF = family id follows from the model
|
||||
# YY must be determined from id
|
||||
if( $model eq "DS1820" ){
|
||||
$fam = 20;
|
||||
$fam = 10;
|
||||
}elsif( $model eq "DS1822" ){
|
||||
$fam = 22;
|
||||
}elsif( $model eq "DS18B20" ){
|
||||
@ -191,38 +202,144 @@ sub OWTEMP_Define ($$) {
|
||||
|
||||
#-- define device internals
|
||||
$hash->{ALARM} = 0;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
$hash->{ROM_ID} = $fam.".".$id.$crc;
|
||||
$hash->{OW_ID} = $id;
|
||||
$hash->{OW_FAMILY} = $fam;
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{ROM_ID} = $fam.".".$id.$crc;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
Log 3, "OWTEMP: Warning, no 1-Wire I/O device found for $name."
|
||||
if(!defined($hash->{IODev}->{NAME}));
|
||||
|
||||
$modules{OWTEMP}{defptr}{$id} = $hash;
|
||||
|
||||
#-- Initial readings temperature sensor
|
||||
$hash->{READINGS}{"temperature"}{VAL} = 0.0;
|
||||
#$hash->{READINGS}{"temperature"}{UNIT} = "celsius";
|
||||
#$hash->{READINGS}{"temperature"}{TYPE} = "temperature";
|
||||
$hash->{READINGS}{"tempLow"}{VAL} = 0.0;
|
||||
$hash->{READINGS}{"tempHigh"}{VAL} = 0.0;
|
||||
$hash->{READINGS}{"temperature"}{TIME} = "";
|
||||
$hash->{READINGS}{"tempLow"}{TIME} = "";
|
||||
$hash->{READINGS}{"tempHigh"}{TIME} = "";
|
||||
$hash->{STATE} = "Defined";
|
||||
$hash->{STATE} = "Defined";
|
||||
Log 3, "OWTEMP: Device $name defined.";
|
||||
|
||||
#-- Start timer for initialization in a few seconds
|
||||
InternalTimer(time()+1, "OWTEMP_InitializeDevice", $hash, 0);
|
||||
|
||||
#-- Start timer for updates
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWTEMP_GetValues", $hash, 0);
|
||||
|
||||
$hash->{STATE} = "Initialized";
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTEMP_InitializeDevice - delayed setting of initial readings and channel names
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTEMP_InitializeDevice($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "<span style=\"color:red\">▾</span>";
|
||||
$stateah = defined($attr{$name}{stateAH}) ? $attr{$name}{stateAH} : "<span style=\"color:red\">▴</span>";
|
||||
|
||||
#-- unit attribute defined ?
|
||||
$hash->{READINGS}{"temperature"}{UNIT} = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : "Celsius";
|
||||
$hash->{READINGS}{"temperature"}{TYPE} = "temperature";
|
||||
|
||||
#-- Initial readings temperature sensor
|
||||
$owg_temp = 0.0;
|
||||
$owg_tl = -15.0;
|
||||
$owg_th = 70.0;
|
||||
|
||||
#-- Initialize all the display stuff
|
||||
OWTEMP_FormatValues($hash);
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTEMP_FormatValues - put together various format strings
|
||||
#
|
||||
# Parameter hash = hash of device addressed, fs = format string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTEMP_FormatValues($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my ($unit,$offset,$factor,$abbr,$vval,$vlow,$vhigh,$statef);
|
||||
my ($value1,$value2,$value3) = ("","","");
|
||||
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- attributes defined ?
|
||||
$unit = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : $hash->{READINGS}{"temperature"}{UNIT};
|
||||
$offset = defined($attr{$name}{"tempoffset"}) ? $attr{$name}{"tempOffset"} : 0.0 ;
|
||||
$factor = 1.0;
|
||||
|
||||
if( $unit eq "Celsius" ){
|
||||
$abbr = "°C";
|
||||
} elsif ($unit eq "Kelvin" ){
|
||||
$abbr = "K";
|
||||
$offset += "273.16"
|
||||
} elsif ($unit eq "Fahrenheit" ){
|
||||
$abbr = "°F";
|
||||
$offset = ($offset+32)/1.8;
|
||||
$factor = 1.8;
|
||||
} else {
|
||||
$abbr="?";
|
||||
Log 1, "OWTEMP_FormatValues: unknown unit $unit";
|
||||
}
|
||||
#-- these values are rather coplex to obtain, therefore save them in the hash
|
||||
$hash->{READINGS}{"temperature"}{UNIT} = $unit;
|
||||
$hash->{READINGS}{"temperature"}{UNITABBR} = $abbr;
|
||||
$hash->{tempf}{offset} = $offset;
|
||||
$hash->{tempf}{factor} = $factor;
|
||||
|
||||
#-- correct values for proper offset, factor
|
||||
$vval = ($owg_temp + $offset)*$factor;
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"temperature"}{VAL} = $vval;
|
||||
$hash->{READINGS}{"temperature"}{TIME} = $tn;
|
||||
|
||||
#-- correct alarm values for proper offset, factor
|
||||
$vlow = ($owg_tl + $offset)*$factor;
|
||||
$vhigh = ($owg_th + $offset)*$factor;
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"tempLow"}{VAL} = $vlow;
|
||||
$hash->{READINGS}{"tempLow"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempHigh"}{VAL} = $vhigh;
|
||||
$hash->{READINGS}{"tempHigh"}{TIME} = $tn;
|
||||
|
||||
#-- formats for output
|
||||
$statef = "%5.2f ".$abbr;
|
||||
$value1 = sprintf($statef,$vval);
|
||||
$value2 = sprintf($statef,$vval);
|
||||
$hash->{ALARM} = 1;
|
||||
|
||||
#-- Test for alarm condition
|
||||
if( ($vval <= $vlow) && ( $vval >= $vhigh ) ){
|
||||
$value2 .= " ".$stateal.$stateah;
|
||||
$value3 .= " ".$stateal.$stateah;
|
||||
}elsif( $vval <= $vlow ){
|
||||
$value2 .= " ".$stateal;
|
||||
$value3 .= " ".$stateal;
|
||||
}elsif( $vval >= $vhigh ){
|
||||
$value2 .= " ".$stateah;
|
||||
$value3 .= " ".$stateah;
|
||||
} else {
|
||||
$hash->{ALARM} = 0;
|
||||
}
|
||||
|
||||
#-- STATE
|
||||
$hash->{STATE} = $value2;
|
||||
#-- alarm
|
||||
#$hash->{READINGS}{alarms}{VAL} = $value3;
|
||||
#$hash->{READINGS}{alarms}{TIME} = $tn;
|
||||
return $value1;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTEMP_Get - Implements GetFn function
|
||||
@ -290,38 +407,15 @@ sub OWTEMP_Get($@) {
|
||||
return "OWTEMP: Could not get values from device $name, return was $ret";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- correct for proper offset
|
||||
my $offset = $attr{$name}{tempOffset};
|
||||
if( $offset ){
|
||||
$owg_temp += $offset;
|
||||
#$owg_tl += $offset;
|
||||
#$owg_tl += $offset;
|
||||
}
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"temperature"}{VAL} = $owg_temp;
|
||||
$hash->{READINGS}{"temperature"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempLow"}{VAL} = $owg_tl;
|
||||
$hash->{READINGS}{"tempLow"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempHigh"}{VAL} = $owg_th;
|
||||
$hash->{READINGS}{"tempHigh"}{TIME} = $tn;
|
||||
|
||||
#-- Test for alarm condition
|
||||
if( ($owg_temp <= $owg_tl) | ($owg_temp >= $owg_th) ){
|
||||
$hash->{STATE} = "Alarmed";
|
||||
$hash->{ALARM} = 1;
|
||||
} else {
|
||||
$hash->{STATE} = "Normal";
|
||||
$hash->{ALARM} = 0;
|
||||
}
|
||||
OWAD_FormatValues($hash);
|
||||
|
||||
#-- return the special reading
|
||||
if ($reading eq "temperature") {
|
||||
return "OWTEMP: $name.temperature => $owg_temp";
|
||||
return "OWTEMP: $name.temperature => ".
|
||||
$hash->{READINGS}{"temperature"}{VAL};
|
||||
} elsif ($reading eq "alarm") {
|
||||
return "OWTEMP: $name.alarm => L $owg_tl H $owg_th";
|
||||
return "OWTEMP: $name.alarm => L ".$hash->{READINGS}{"tempLow"}{VAL}.
|
||||
" H ".$hash->{READINGS}{"tempHigh"}{VAL};
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
@ -338,7 +432,6 @@ sub OWTEMP_GetValues($@) {
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
my $value = "";
|
||||
my $ret = "";
|
||||
|
||||
@ -364,37 +457,11 @@ sub OWTEMP_GetValues($@) {
|
||||
return "OWTEMP: Could not get values from device $name";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- correct for proper offset
|
||||
my $offset = $attr{$name}{tempOffset};
|
||||
if( $offset ){
|
||||
$owg_temp += $offset;
|
||||
#$owg_tl += $offset;
|
||||
#$owg_tl += $offset;
|
||||
}
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"temperature"}{VAL} = $owg_temp;
|
||||
$hash->{READINGS}{"temperature"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempLow"}{VAL} = $owg_tl;
|
||||
$hash->{READINGS}{"tempLow"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempHigh"}{VAL} = $owg_th;
|
||||
$hash->{READINGS}{"tempHigh"}{TIME} = $tn;
|
||||
|
||||
#-- Test for alarm condition
|
||||
if( ($owg_temp <= $owg_tl) | ($owg_temp >= $owg_th) ){
|
||||
$hash->{STATE} = "Alarmed";
|
||||
$hash->{ALARM} = 1;
|
||||
} else {
|
||||
$hash->{STATE} = "Normal";
|
||||
$hash->{ALARM} = 0;
|
||||
}
|
||||
|
||||
$value=OWTEMP_FormatValues($hash);
|
||||
#--logging
|
||||
my $rv = sprintf "temperature: %5.3f tLow: %3.0f tHigh: %3.0f",$owg_temp,$owg_tl,$owg_th;
|
||||
Log 5, $rv;
|
||||
$hash->{CHANGED}[0] = $rv;
|
||||
Log 5, $value;
|
||||
$hash->{CHANGED}[0] = $value;
|
||||
|
||||
DoTrigger($name, undef);
|
||||
|
||||
return undef;
|
||||
@ -428,13 +495,6 @@ sub OWTEMP_Set($@) {
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
|
||||
#-- set warnings
|
||||
if($key eq "tempLow" || $key eq "tempHigh") {
|
||||
# check range
|
||||
return "OWTEMP: Set with wrong temperature value, range is -55°C - 125°C"
|
||||
if(int($value) < -55 || int($value) > 125);
|
||||
}
|
||||
|
||||
#-- set new timer interval
|
||||
if($key eq "interval") {
|
||||
# check value
|
||||
@ -448,11 +508,19 @@ sub OWTEMP_Set($@) {
|
||||
}
|
||||
|
||||
#-- set other values depending on interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- careful: the input values have to be corrected
|
||||
# with the proper offset
|
||||
|
||||
my $interface = $hash->{IODev}->{TYPE};
|
||||
my $offset = $hash->{tempf}{offset};
|
||||
my $factor = $hash->{tempf}{factor};
|
||||
|
||||
#-- find upper and lower boundaries for given offset/factor
|
||||
my $mmin = (-55+$offset)*$factor;
|
||||
my $mmax = (125+$offset)*$factor;
|
||||
return sprintf("OWTEMP: Set with wrong value $value for $key, range is [%3.1f,%3.1f]",$mmin,$mmax)
|
||||
if($value < $mmin || $value > $mmax);
|
||||
|
||||
#-- seems to be ok, put into the device
|
||||
$a[2] = int($value/$factor-$offset);
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXTEMP_SetValues($hash,@a);
|
||||
@ -466,34 +534,7 @@ sub OWTEMP_Set($@) {
|
||||
} else {
|
||||
return "OWTEMP: Set with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- process results
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- correct for proper offset
|
||||
my $offset = $attr{$name}{tempOffset};
|
||||
if( $offset ){
|
||||
$owg_temp += $offset;
|
||||
#$owg_tl += $offset;
|
||||
#$owg_tl += $offset;
|
||||
}
|
||||
|
||||
#-- Test for alarm condition
|
||||
if( ($owg_temp <= $owg_tl) | ($owg_temp >= $owg_th) ){
|
||||
$hash->{STATE} = "Alarmed";
|
||||
$hash->{ALARM} = 1;
|
||||
} else {
|
||||
$hash->{STATE} = "Normal";
|
||||
$hash->{ALARM} = 0;
|
||||
}
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"temperature"}{VAL} = $owg_temp;
|
||||
$hash->{READINGS}{"temperature"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempLow"}{VAL} = $owg_tl;
|
||||
$hash->{READINGS}{"tempLow"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempHigh"}{VAL} = $owg_th;
|
||||
$hash->{READINGS}{"tempHigh"}{TIME} = $tn;
|
||||
OWTEMP_FormatValues($hash);
|
||||
|
||||
Log 4, "OWTEMP: Set $hash->{NAME} $key $value";
|
||||
|
||||
@ -729,22 +770,16 @@ sub OWXTEMP_SetValues($@) {
|
||||
$owx_ROM_ID[$i]=hex(substr($devs,2*$i,2));
|
||||
}
|
||||
|
||||
# define vars
|
||||
#-- define vars
|
||||
my $key = $a[1];
|
||||
my $value = $a[2];
|
||||
|
||||
#-- get the old values
|
||||
$owg_temp = $hash->{READINGS}{"temperature"}{VAL};
|
||||
$owg_tl = $hash->{READINGS}{"tempLow"}{VAL};
|
||||
$owg_th = $hash->{READINGS}{"tempHigh"}{VAL};
|
||||
|
||||
$owg_tl = int($value) if( $key eq "tempLow" );
|
||||
$owg_th = int($value) if( $key eq "tempHigh" );
|
||||
$owg_tl = $value if( $key eq "tempLow" );
|
||||
$owg_th = $value if( $key eq "tempHigh" );
|
||||
|
||||
#-- put into 2's complement formed (signed byte)
|
||||
my $tlp = $owg_tl < 0 ? 128 - $owg_tl : $owg_tl;
|
||||
my $thp = $owg_th < 0 ? 128 - $owg_th : $owg_th;
|
||||
|
||||
|
||||
OWX_Reset($master);
|
||||
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E,
|
||||
|
Loading…
x
Reference in New Issue
Block a user