mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-29 23:47:10 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@2715 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
042f22d7c8
commit
3aad251496
@ -320,7 +320,7 @@ sub OWAD_InitializeDevice($) {
|
|||||||
$owg_shigh[$i]=1;
|
$owg_shigh[$i]=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#-- low alarm value
|
#-- low alarm value - no checking for correct parameters
|
||||||
if( AttrVal($name,$owg_fixed[$i]."Low",undef) ){
|
if( AttrVal($name,$owg_fixed[$i]."Low",undef) ){
|
||||||
$owg_vlow[$i] = $main::attr{$name}{$owg_fixed[$i]."Low"};
|
$owg_vlow[$i] = $main::attr{$name}{$owg_fixed[$i]."Low"};
|
||||||
}
|
}
|
||||||
|
@ -242,9 +242,9 @@ sub OWTHERM_InitializeDevice($) {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my @args;
|
my $interface = $hash->{IODev}->{TYPE};
|
||||||
my $ret;
|
my @a = ($name,"",0);
|
||||||
my ($unit,$offset,$factor,$abbr,$vval,$vlow,$vhigh,$statef);
|
my ($unit,$offset,$factor,$abbr,$value);
|
||||||
|
|
||||||
#-- attributes defined ?
|
#-- attributes defined ?
|
||||||
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "▾";
|
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "▾";
|
||||||
@ -276,12 +276,31 @@ sub OWTHERM_InitializeDevice($) {
|
|||||||
|
|
||||||
#-- Set the attribute values if defined
|
#-- Set the attribute values if defined
|
||||||
if( defined($attr{$name}{"tempLow"}) ){
|
if( defined($attr{$name}{"tempLow"}) ){
|
||||||
OWTHERM_Set( $hash,($name,"tempLow",$attr{$name}{"tempLow"}));
|
$value = $attr{$name}{"tempLow"};
|
||||||
|
$a[1] = "tempLow";
|
||||||
|
$a[2] = floor($value/$factor-$offset+0.5);
|
||||||
|
#-- put into device
|
||||||
|
#-- OWX interface
|
||||||
|
if( $interface eq "OWX" ){
|
||||||
|
OWXTHERM_SetValues($hash,@a);
|
||||||
|
#-- OWFS interface
|
||||||
|
}elsif( $interface eq "OWServer" ){
|
||||||
|
OWFSTHERM_SetValues($hash,@a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if( defined($attr{$name}{"tempHigh"}) ){
|
if( defined($attr{$name}{"tempHigh"}) ){
|
||||||
OWTHERM_Set( $hash,($name,"tempHigh",$attr{$name}{"tempHigh"}) );
|
$value = $attr{$name}{"tempHigh"};
|
||||||
|
$a[1] = "tempHigh";
|
||||||
|
$a[2] = floor($value/$factor-$offset+0.5);
|
||||||
|
#-- put into device
|
||||||
|
#-- OWX interface
|
||||||
|
if( $interface eq "OWX" ){
|
||||||
|
OWXTHERM_SetValues($hash,@a);
|
||||||
|
#-- OWFS interface
|
||||||
|
}elsif( $interface eq "OWServer" ){
|
||||||
|
OWFSTHERM_SetValues($hash,@a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#-- Set state to initialized
|
#-- Set state to initialized
|
||||||
readingsSingleUpdate($hash,"state","initialized",1);
|
readingsSingleUpdate($hash,"state","initialized",1);
|
||||||
}
|
}
|
||||||
@ -331,6 +350,10 @@ sub OWTHERM_FormatValues($) {
|
|||||||
#-- no change in any value if invalid reading
|
#-- no change in any value if invalid reading
|
||||||
return if( $owg_temp eq "");
|
return if( $owg_temp eq "");
|
||||||
|
|
||||||
|
#-- check if device needs to be initialized
|
||||||
|
OWTHERM_InitializeDevice($hash)
|
||||||
|
if( $hash->{READINGS}{"state"}{VAL} eq "defined");
|
||||||
|
|
||||||
#-- correct values for proper offset, factor
|
#-- correct values for proper offset, factor
|
||||||
$vval = ($owg_temp + $offset)*$factor;
|
$vval = ($owg_temp + $offset)*$factor;
|
||||||
$vlow = floor(($owg_tl + $offset)*$factor+0.5);
|
$vlow = floor(($owg_tl + $offset)*$factor+0.5);
|
||||||
@ -339,10 +362,6 @@ sub OWTHERM_FormatValues($) {
|
|||||||
$main::attr{$name}{"tempLow"} = $vlow;
|
$main::attr{$name}{"tempLow"} = $vlow;
|
||||||
$main::attr{$name}{"tempHigh"} = $vhigh;
|
$main::attr{$name}{"tempHigh"} = $vhigh;
|
||||||
|
|
||||||
#-- check if device needs to be initialized
|
|
||||||
OWTHERM_InitializeDevice($hash)
|
|
||||||
if( $hash->{READINGS}{"state"}{VAL} eq "defined");
|
|
||||||
|
|
||||||
#-- formats for output
|
#-- formats for output
|
||||||
$statef = "T: %5.2f ".$abbr;
|
$statef = "T: %5.2f ".$abbr;
|
||||||
$svalue = sprintf($statef,$vval);
|
$svalue = sprintf($statef,$vval);
|
||||||
@ -599,7 +618,7 @@ sub OWTHERM_Set($@) {
|
|||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
$hash->{PRESENT} = 1;
|
$hash->{PRESENT} = 1;
|
||||||
#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;
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
#
|
#
|
||||||
# 15_EMX.pm MUST be saved as 15_CUL_EM.pm !!!
|
# 15_EMX.pm MUST be saved as 15_CUL_EM.pm !!!
|
||||||
#
|
#
|
||||||
# FHEM module to read the data from an EM1000 S/IR power sensor
|
# FHEM module to read the data from an EM1000 WZ/EM/GZ power sensor
|
||||||
#
|
#
|
||||||
# Version 1.0 - January 21, 2013
|
# Version 1.1 - February, 2013
|
||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2011
|
# Prof. Dr. Peter A. Henning, 2011
|
||||||
#
|
#
|
||||||
#----------------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Setup as:
|
# Setup as:
|
||||||
# define <emx> EMX <code> <rpkwh>
|
# define <emx> EMX <code> <rpunit>
|
||||||
#
|
#
|
||||||
# where
|
# where
|
||||||
# <name> may be replaced by any name string
|
# <name> may be replaced by any name string
|
||||||
@ -27,20 +27,35 @@
|
|||||||
# attr emx LogM EnergyM
|
# attr emx LogM EnergyM
|
||||||
# attr emx LogY EnergyY
|
# attr emx LogY EnergyY
|
||||||
#
|
#
|
||||||
# NOT YET OPERATIVE:
|
|
||||||
#
|
|
||||||
# Basic fee per Month (€ per Month)
|
# Basic fee per Month (€ per Month)
|
||||||
# attr emx FixedM
|
# attr emx CostM
|
||||||
#
|
#
|
||||||
# Rate during daytime (€ per kWh)
|
# Cost rate during daytime (€ per kWh)
|
||||||
# attr emx RateD <rate in €/kWh>
|
# attr emx CrateD <cost rate in €/unit>
|
||||||
#
|
#
|
||||||
# Start and end of daytime rate - optional
|
# Start and end of daytime cost rate - optional
|
||||||
# attr emx RateDStart <time as hh:mm>
|
# attr emx CrateDStart <time as hh:mm>
|
||||||
# attr emx RateDEnd <time as hh:mm>
|
# attr emx CrateDEnd <time as hh:mm>
|
||||||
#
|
#
|
||||||
# Rate during nighttime (cost per kWh) - only if needed
|
# Cost rate during nighttime (cost per unit) - only if needed
|
||||||
# attr emx RateN <rate in €/kWh>
|
# attr emx CrateN <cost rate in €/unit>
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# This programm is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# The GNU General Public License can be found at
|
||||||
|
# http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||||
|
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||||
|
#
|
||||||
|
# This script is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
########################################################################################
|
########################################################################################
|
||||||
package main;
|
package main;
|
||||||
@ -93,7 +108,7 @@ sub EMX_Initialize ($) {
|
|||||||
$hash->{Match} = "^E0.................\$";
|
$hash->{Match} = "^E0.................\$";
|
||||||
|
|
||||||
$hash->{AttrList} = "IODev " .
|
$hash->{AttrList} = "IODev " .
|
||||||
"model:EMEM,EMWZ,EMGZ loglevel LogM LogY RateD RateDStart RateDEnd RateN BaseFee ".
|
"model:EMEM,EMWZ,EMGZ loglevel LogM LogY CrateD CrateDStart CrateDEnd CrateN CostM ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +160,9 @@ sub EMX_Define ($$) {
|
|||||||
if( $a[2] !~ m/^\d+$/ || $a[2] < 1 || $a[2] > 12 );
|
if( $a[2] !~ m/^\d+$/ || $a[2] < 1 || $a[2] > 12 );
|
||||||
$hash->{CODE} = $a[2];
|
$hash->{CODE} = $a[2];
|
||||||
|
|
||||||
|
#-- TODO: check for consistency of attributes !
|
||||||
|
|
||||||
|
|
||||||
#--counts per unit etc.
|
#--counts per unit etc.
|
||||||
if($a[2] >= 1 && $a[2] <= 4) { # EMWZ
|
if($a[2] >= 1 && $a[2] <= 4) { # EMWZ
|
||||||
$hash->{READINGS}{"reading"}{FACTOR} = $a[3];
|
$hash->{READINGS}{"reading"}{FACTOR} = $a[3];
|
||||||
@ -226,6 +244,7 @@ sub EMX_FormatValues ($) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my ($model,$factor,$period,$unit,$runit,$midnight,$cval,$vval,$rval,$pval,$dval,$deltim,$delcnt,$msg);
|
my ($model,$factor,$period,$unit,$runit,$midnight,$cval,$vval,$rval,$pval,$dval,$deltim,$delcnt,$msg);
|
||||||
my ($svalue,$dvalue,$mvalue) = ("","","");
|
my ($svalue,$dvalue,$mvalue) = ("","","");
|
||||||
|
my $cost;
|
||||||
|
|
||||||
my ($sec, $min, $hour, $day, $month, $year, $wday,$yday,$isdst) = localtime(time);
|
my ($sec, $min, $hour, $day, $month, $year, $wday,$yday,$isdst) = localtime(time);
|
||||||
my ($seco,$mino,$houro,$dayo,$montho,$yearo,$dayrest);
|
my ($seco,$mino,$houro,$dayo,$montho,$yearo,$dayrest);
|
||||||
@ -249,8 +268,7 @@ sub EMX_FormatValues ($) {
|
|||||||
# normal mode: less than 5 minutes from midnight
|
# normal mode: less than 5 minutes from midnight
|
||||||
}else {
|
}else {
|
||||||
$deltim = $hour*60.0+$min+$sec/60.0 - 1435.0;
|
$deltim = $hour*60.0+$min+$sec/60.0 - 1435.0;
|
||||||
#-- TODO abfangen, wenn Messung um Mitternacht !
|
if( $deltim>=0 ){
|
||||||
if( $deltim>0 ){
|
|
||||||
$daybreak = 1;
|
$daybreak = 1;
|
||||||
#-- Timer data from tomorrow
|
#-- Timer data from tomorrow
|
||||||
my ($secn,$minn,$hourn,$dayn,$monthn,$yearn,$wdayn,$ydayn,$isdstn) = localtime(time() + 24*60*60);
|
my ($secn,$minn,$hourn,$dayn,$monthn,$yearn,$wdayn,$ydayn,$isdstn) = localtime(time() + 24*60*60);
|
||||||
@ -289,7 +307,6 @@ sub EMX_FormatValues ($) {
|
|||||||
if( length($emx_cnt_tim) > 0 ){
|
if( length($emx_cnt_tim) > 0 ){
|
||||||
|
|
||||||
#-- correct counter wraparound since last reading
|
#-- correct counter wraparound since last reading
|
||||||
# Careful: we have seen, that sometimes this causes an error when a false message is received
|
|
||||||
if( $emx_cnt < $emx_cnt_prev) {
|
if( $emx_cnt < $emx_cnt_prev) {
|
||||||
$emx_cnt_prev -= 65536;
|
$emx_cnt_prev -= 65536;
|
||||||
}
|
}
|
||||||
@ -320,29 +337,45 @@ sub EMX_FormatValues ($) {
|
|||||||
$vval = int($cval/$factor*1000)/1000;
|
$vval = int($cval/$factor*1000)/1000;
|
||||||
$rval = int($emx_5min*12/$factor*1000)/1000;
|
$rval = int($emx_5min*12/$factor*1000)/1000;
|
||||||
$pval = int($emx_peak/($factor*20)*1000)/1000;
|
$pval = int($emx_peak/($factor*20)*1000)/1000;
|
||||||
$svalue = sprintf("W: %5.2f %s P: %5.2f %s",$vval,$unit,$rval,$runit);
|
|
||||||
} elsif( $model eq "EMEM" ){
|
} elsif( $model eq "EMEM" ){
|
||||||
$vval = int($cval/($factor*10)*1000)/1000;
|
$vval = int($cval/($factor*10)*1000)/1000;
|
||||||
$rval = int($emx_5min*12/$factor*1000)/1000;
|
$rval = int($emx_5min/$factor*1000)/1000;
|
||||||
$pval = int($emx_peak/($factor*20)*1000)/1000;
|
$pval = int($emx_peak/($factor*20)*1000)/1000;
|
||||||
$svalue = sprintf("W: %5.2f %s P: %5.2f %s",$vval,$unit,$rval,$runit);
|
|
||||||
} elsif( $model eq "EMGZ" ){
|
} elsif( $model eq "EMGZ" ){
|
||||||
$vval = int($cval/$factor*1000)/1000;
|
$vval = int($cval/$factor*1000)/1000;
|
||||||
$rval = int($emx_5min*12/$factor*1000)/1000;
|
$rval = int($emx_5min/$factor*1000)/1000;
|
||||||
$pval = int($emx_peak/($factor*20)*1000)/1000;
|
$pval = int($emx_peak/($factor*20)*1000)/1000;
|
||||||
$svalue = sprintf("W: %5.2f %s P: %5.2f %s",$vval,$unit,$rval,$runit);
|
|
||||||
} else {
|
} else {
|
||||||
Log 3,"EMX: Wrong device model $model";
|
Log 3,"EMX: Wrong device model $model";
|
||||||
}
|
}
|
||||||
#-- Calculate cost
|
$svalue = sprintf("W: %5.2f %s P: %5.2f %s Pmax: %5.3f %s",$vval,$unit,$rval,$runit,$pval,$runit);
|
||||||
#--
|
#-- calculate cost
|
||||||
|
if( defined($main::attr{$name}{"CrateD"}) ){
|
||||||
|
#-- single rate counter
|
||||||
|
if( !defined($main::attr{$name}{"CrateN"}) ){
|
||||||
|
$cost = $vval*$main::attr{$name}{"CrateD"};
|
||||||
|
#-- dual rate counter
|
||||||
|
}else{
|
||||||
|
#--determine period 1 = still night, 2 = day, 3 = night again
|
||||||
|
my @crs=split(':',$main::attr{$name}{"CrateDStart"});
|
||||||
|
my @crs=split(':',$main::attr{$name}{"CrateDEnd"});
|
||||||
|
#-- period 1
|
||||||
|
if ( ($hour<=$crs[0]) & ($min<$crs[1]) ){
|
||||||
|
#-- period 2
|
||||||
|
}elsif ( ($hour<=$crs[0]) & ($min<$crs[1]) ){
|
||||||
|
#-- period 3
|
||||||
|
}else{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#-- put into READING
|
#-- put into READING
|
||||||
readingsBulkUpdate($hash,"reading",$vval);
|
readingsBulkUpdate($hash,"reading",$vval);
|
||||||
readingsBulkUpdate($hash,"rate",$rval);
|
readingsBulkUpdate($hash,"rate",$rval);
|
||||||
readingsBulkUpdate($hash,"peak",$pval);
|
readingsBulkUpdate($hash,"peak",$pval);
|
||||||
|
readingsBulkUpdate($hash,"cost",$cost);
|
||||||
|
|
||||||
#-- Daily/monthly cumulated value
|
#-- Daily/monthly accumulated value
|
||||||
if( $daybreak == 1 ){
|
if( $daybreak == 1 ){
|
||||||
my @month = EMX_GetMonth($hash);
|
my @month = EMX_GetMonth($hash);
|
||||||
my $total = $month[0]+$vval;
|
my $total = $month[0]+$vval;
|
||||||
@ -551,10 +584,10 @@ sub EMX_store($) {
|
|||||||
$msg = sprintf "%4d-%02d-%02d midnight %d",$year+1900,$month,$day,$hash->{READINGS}{"count"}{midnight};
|
$msg = sprintf "%4d-%02d-%02d midnight %d",$year+1900,$month,$day,$hash->{READINGS}{"count"}{midnight};
|
||||||
}
|
}
|
||||||
print EMXFILE $msg;
|
print EMXFILE $msg;
|
||||||
Log 1, "EMX_store: $msg";
|
Log 1, "EMX_store: $name $msg";
|
||||||
close(EMXFILE);
|
close(EMXFILE);
|
||||||
} else {
|
} else {
|
||||||
Log 1,"EMX_store: Cannot open EMX_name.dat for writing!";
|
Log 1,"EMX_store: Cannot open EMX_$name.dat for writing!";
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -697,7 +730,7 @@ sub EMX_emu ($$) {
|
|||||||
|
|
||||||
<a name="EMX"></a>
|
<a name="EMX"></a>
|
||||||
<h3>EMX</h3>
|
<h3>EMX</h3>
|
||||||
<p>FHEM module to commmunicate EM1000 power/gas sensors <br />
|
<p>FHEM module to commmunicate with the EM1000 WZ/EM/GZ power/gas sensors <br />
|
||||||
<br /> <b>NOTE:</b> This module is currently NOT registered in the client list of 00_CUL.pm.
|
<br /> <b>NOTE:</b> This module is currently NOT registered in the client list of 00_CUL.pm.
|
||||||
Therefore ist must be saved under the name 15_CUL_EM.pm or entered into the client list manually.
|
Therefore ist must be saved under the name 15_CUL_EM.pm or entered into the client list manually.
|
||||||
<br /></p>
|
<br /></p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user