diff --git a/CHANGED b/CHANGED index 33cbb25d1..ce0573c7b 100644 --- a/CHANGED +++ b/CHANGED @@ -332,4 +332,4 @@ - bugfix: deleted FS20 items are still logging (zombie) (Gerhard, 16.5) - bugfix: added FS20S8, removed stty_parmrk (Martin, 24.5) - feature: added archivedir/archivecmd to the FileLog - - feature: added EM1010PC/EM1000WZ support + - feature: added EM1010PC/EM1000WZ/EM1000EM support diff --git a/FHEM/62_EMEM.pm b/FHEM/62_EMEM.pm new file mode 100755 index 000000000..56c3c7e23 --- /dev/null +++ b/FHEM/62_EMEM.pm @@ -0,0 +1,137 @@ +############################################## +package main; + +use strict; +use warnings; +use Time::HiRes qw(gettimeofday); + +sub EMEM_Get($@); +sub EMEM_Set($@); +sub EMEM_Define($$); +sub EMEM_GetStatus($); + +################################### +sub +EMEM_Initialize($) +{ + my ($hash) = @_; + + $hash->{GetFn} = "EMEM_Get"; + $hash->{DefFn} = "EMEM_Define"; + + $hash->{AttrList} = "dummy:1,0 model;EM1000EM loglevel:0,1,2,3,4,5,6"; +} + +################################### +sub +EMEM_GetStatus($) +{ + my ($hash) = @_; + + if(!$hash->{LOCAL}) { + InternalTimer(gettimeofday()+300, "EMEM_GetStatus", $hash); + } + + my $dnr = $hash->{DEVNR}; + my $name = $hash->{NAME}; + + my $d = IOWrite($hash, sprintf("7a%02x", $dnr-1)); + if(!defined($d)) { + my $msg = "EMWZ $name read error"; + Log GetLogLevel($name,2), $msg; + return $msg; + } + + + if($d eq ((pack('H*',"00") x 45) . pack('H*',"FF") x 6)) { + my $msg = "EMEM no device no. $dnr present"; + Log GetLogLevel($name,2), $msg; + return $msg; + } + + my $pulses=w($d,13); + my $ec=w($d,49) / 10; + if($ec != 0) { + my $msg = "EMEM read error"; + Log GetLogLevel($name,2), $msg; + return $msg; + } + + my $iec = 1000; + my $cur_power = $pulses / 100; + + if($cur_power > 100) { + my $msg = "EMEM Bogus reading: curr. power is reported to be $cur_power"; + Log GetLogLevel($name,2), $msg; + return $msg; + } + + my %vals; + $vals{"5min_pulses"} = $pulses; + $vals{"energy"} = sprintf("%0.3f kWh/h", dw($d,33) / $iec); + $vals{"power"} = sprintf("%.3f", $cur_power); + $vals{"alarm_PA"} = w($d,45) . " Watt"; + $vals{"price_CF"} = sprintf("%.3f", w($d,47)/10000); + $vals{"RperKW_EC"} = $ec; + + my $tn = TimeNow(); + my $idx = 0; + foreach my $k (keys %vals) { + my $v = $vals{$k}; + $hash->{CHANGED}[$idx++] = "$k: $v"; + $hash->{READINGS}{$k}{TIME} = $tn; + $hash->{READINGS}{$k}{VAL} = $v + } + + if(!$hash->{LOCAL}) { + DoTrigger($name, undef) if($init_done); + } + + $hash->{STATE} = "$cur_power kWh"; + + return $hash->{STATE}; +} + +################################### +sub +EMEM_Get($@) +{ + my ($hash, @a) = @_; + + return "argument is missing" if(int(@a) != 2); + + my $d = $hash->{DEVNR}; + my $msg; + + if($a[1] ne "status") { + return "unknown get value, valid is status"; + } + $hash->{LOCAL} = 1; + my $v = EMEM_GetStatus($hash); + delete $hash->{LOCAL}; + + return "$a[0] $a[1] => $v"; +} + +############################# +sub +EMEM_Define($$) +{ + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); + + return "syntax: define EMEM devicenumber" + if(@a != 3 || $a[2] !~ m,^[5-8]$,); + $hash->{DEVNR} = $a[2]; + AssignIoPort($hash); + + + # InternalTimer blocks if init_done is not true + my $oid = $init_done; + $init_done = 1; + EMEM_GetStatus($hash); + $init_done = $oid; + return undef; +} + +1; diff --git a/HISTORY b/HISTORY index cf0dd2060..bf23e221b 100644 --- a/HISTORY +++ b/HISTORY @@ -100,3 +100,7 @@ archive directory. See the attributes archivedir/archivecmd. - Added EM1010PC suppoort (right now only with EM1000WZ). Support added for displaying logs in the fhemweb.pl (webfrontends/pgm2) + +- Pest, Mon May 28 19:39:22 MEST 2007 + - Added 62_EMEM.pm to support EM1000-EM devices. + - doc: Update of commandref.htm (typos and EMEM). diff --git a/docs/commandref.html b/docs/commandref.html index b2c55d72b..290ad46d5 100644 --- a/docs/commandref.html +++ b/docs/commandref.html @@ -672,19 +672,38 @@ split in multiple lines

define <name> EMWZ <device-number>

- Define up two 4 EM1000WZ attached to the EM1010PC. The device number must + Define up to 4 EM1000WZ attached to the EM1010PC. The device number must be between 1 and 4 (else you have a differnt device connected to the EM1010PC). Defining an EMWZ will schedule an internal task, which reads the status of the device every 5 minutes, and triggers notify/filelog commands.

- Examples: + Example:
+ +

Type EMEM

+

Type FileLog

diff --git a/examples/01_fs20 b/examples/01_fs20 index 3014a0c30..fb19f3422 100644 --- a/examples/01_fs20 +++ b/examples/01_fs20 @@ -11,7 +11,7 @@ attr global logfile /tmp/fhem-%Y-%m.log attr global statefile /tmp/fhem.save # where to save the state of the devices attr global verbose 3 # "normal" verbosity (min 1, max 5) attr global port 7072 # our TCP/IP port (localhost only) -attr global modpath /usr/local/lib # where our FHEM directory is +attr global modpath /usr/local/libusr/local/lib # where our FHEM directory is define FHZ FHZ /dev/tts/USB0 # the serial port of an FHZ 1000 PC diff --git a/examples/02_fs20 b/examples/02_fs20 index 2190921d5..746450dd3 100644 --- a/examples/02_fs20 +++ b/examples/02_fs20 @@ -13,7 +13,7 @@ attr global logfile /tmp/fhem-%Y-%m.log attr global statefile /tmp/fhem.save # where to save the state of the devices attr global verbose 3 # "normal" verbosity attr global port 7072 # our TCP/IP port (localhost only) -attr global modpath /usr/local/lib # where our FHEM directory is +attr global modpath /usr/local/libusr/local/lib # where our FHEM directory is define FHZ FHZ /dev/tts/USB0 # the serial port of an FHZ 1000 PC diff --git a/examples/03_fht b/examples/03_fht index e61ce14f9..c58a0162e 100644 --- a/examples/03_fht +++ b/examples/03_fht @@ -12,7 +12,7 @@ attr global logfile /tmp/fhem-%Y-%m.log attr global statefile /tmp/fhem.save # where to save the state of the devices attr global verbose 3 # "normal" verbosity attr global port 7072 # our TCP/IP port (localhost only) -attr global modpath /usr/local/lib # where our FHEM directory is +attr global modpath /usr/local/libusr/local/lib # where our FHEM directory is define FHZ FHZ /dev/tts/USB0 # the serial port of an FHZ 1000 PC define wz FHT 3232 # type FHT, transmitter code 3232 (default value) diff --git a/examples/04_log b/examples/04_log index f42732064..dd2d174f3 100644 --- a/examples/04_log +++ b/examples/04_log @@ -8,7 +8,7 @@ attr global logfile /tmp/fhem-%Y-%m.log attr global statefile /tmp/fhem.save # where to save the state of the devices attr global verbose 3 # "normal" verbosity attr global port 7072 # our TCP/IP port (localhost only) -attr global modpath /usr/local/lib # where our FHEM directory is +attr global modpath /usr/local/libusr/local/lib # where our FHEM directory is define FHZ FHZ /dev/tts/USB0 # the serial port of an FHZ 1000 PC define wz FHT 3232 # type FHT, transmitter code 3232 (default value) diff --git a/examples/05_rm100 b/examples/05_rm100 index e0bb8b07c..bb2219159 100644 --- a/examples/05_rm100 +++ b/examples/05_rm100 @@ -12,7 +12,7 @@ attr global logfile /tmp/fhem-%Y-%m.log attr global statefile /tmp/fhem.save # where to save the state of the devices attr global verbose 3 # "normal" verbosity (min 1, max 5) attr global port 7072 # our TCP/IP port (localhost only) -attr global modpath /usr/local/lib # where our FHEM directory is +attr global modpath /usr/local/libusr/local/lib # where our FHEM directory is define FHZ FHZ /dev/tts/USB0 # the serial port of an FHZ 1000 PC