From 99a1a793deee67507a73c13a6845fe145ae73401 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Wed, 26 Dec 2007 10:46:40 +0000 Subject: [PATCH] 82_M232Voltage by Boris git-svn-id: https://svn.fhem.de/fhem/trunk@133 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 +- fhem/FHEM/80_M232.pm | 2 +- fhem/FHEM/82_M232Voltage.pm | 116 ++++++++++++++++++++++++++++++++++++ fhem/docs/commandref.html | 23 +++++++ 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 fhem/FHEM/82_M232Voltage.pm diff --git a/fhem/CHANGED b/fhem/CHANGED index 3492a668f..bde4601da 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -367,7 +367,8 @@ - feature: HMS100CO (by Peter) - feature: EMGZ (by Peter) - feature: Generate warning if too many commands were sent in the last hour - - doc: linux.html: Introduction (Peter S.) + - doc: linux.html: Introduction (Peter S.) + - feature: contrib/82_M232Voltage.pm (by Boris, 24.12) - TODO emem -2.5kW / getDevData for emwz -1 diff --git a/fhem/FHEM/80_M232.pm b/fhem/FHEM/80_M232.pm index 366302842..5fddeff9f 100644 --- a/fhem/FHEM/80_M232.pm +++ b/fhem/FHEM/80_M232.pm @@ -22,7 +22,7 @@ M232_Initialize($) # Provider $hash->{WriteFn} = "M232_Write"; - $hash->{Clients} = ":M232Counter:"; + $hash->{Clients} = ":M232Counter:M232Voltage:"; # Consumer $hash->{DefFn} = "M232_Define"; diff --git a/fhem/FHEM/82_M232Voltage.pm b/fhem/FHEM/82_M232Voltage.pm new file mode 100644 index 000000000..9bca62636 --- /dev/null +++ b/fhem/FHEM/82_M232Voltage.pm @@ -0,0 +1,116 @@ +# +# +# 82_M232Voltage.pm +# written by Dr. Boris Neubert 2007-12-24 +# e-mail: omega at online dot de +# +############################################## +package main; + +use strict; +use warnings; +use Time::HiRes qw(gettimeofday); + +sub M232Voltage_Get($@); +sub M232Voltage_Define($$); +sub M232Voltage_GetStatus($); + +################################### +sub +M232Voltage_Initialize($) +{ + my ($hash) = @_; + + $hash->{GetFn} = "M232Voltage_Get"; + $hash->{DefFn} = "M232Voltage_Define"; + + $hash->{AttrList} = "dummy:1,0 model;M232Voltage loglevel:0,1,2,3,4,5"; +} + +################################### +sub +M232Voltage_GetStatus($) +{ + my ($hash) = @_; + + if(!$hash->{LOCAL}) { + InternalTimer(gettimeofday()+60, "M232Voltage_GetStatus", $hash, 1); + } + + my $name = $hash->{NAME}; + + my $d = IOWrite($hash, "a" . $hash->{INPUT}); + if(!defined($d)) { + my $msg = "M232Voltage $name read error"; + Log GetLogLevel($name,2), $msg; + return $msg; + } + + my $tn = TimeNow(); + my $value= (hex substr($d,0,3))*5.00/1024.0 * $hash->{FACTOR}; + + $hash->{READINGS}{value}{TIME} = $tn; + $hash->{READINGS}{value}{VAL} = $value; + + $hash->{CHANGED}[0]= "value: $value"; + + if(!$hash->{LOCAL}) { + DoTrigger($name, undef) if($init_done); + } + + $hash->{STATE} = $value; + Log GetLogLevel($name,4), "M232Voltage $name: $value $hash->{UNIT}"; + + return $hash->{STATE}; +} + +################################### +sub +M232Voltage_Get($@) +{ + my ($hash, @a) = @_; + + return "argument is missing" if(int(@a) != 2); + + my $msg; + + if($a[1] ne "status") { + return "unknown get value, valid is status"; + } + $hash->{LOCAL} = 1; + my $v = M232Voltage_GetStatus($hash); + delete $hash->{LOCAL}; + + return "$a[0] $a[1] => $v"; +} + +############################# +sub +M232Voltage_Define($$) +{ + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); + + return "syntax: define M232Voltage an0..an5 [unit [factor]]" + if(int(@a) < 3 && int(@a) > 5); + + my $reading= $a[2]; + return "$reading is not an analog input, valid: an0..an5" + if($reading !~ /^an[0-5]$/) ; + + my $unit= ((int(@a) > 3) ? $a[3] : "volts"); + my $factor= ((int(@a) > 4) ? $a[4] : 1.0); + + $hash->{INPUT}= substr($reading,2); + $hash->{UNIT}= $unit; + $hash->{FACTOR}= $factor; + + AssignIoPort($hash); + + if(!$hash->{LOCAL}) { + InternalTimer(gettimeofday()+60, "M232Voltage_GetStatus", $hash, 0); + } + return undef; +} + +1; diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index ad5df29bb..a85d5f22e 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -822,6 +822,29 @@ split in multiple lines


+ +

Type M232Voltage

+ +

Type SCIVT