2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

36_EC3000.pm: fixed calculation of values (by Fuchks)

36_PCA301.pm & 36_EC3000.pm: added offLevel attribute, changed state reading, initialize stateFormat
see forum: http://forum.fhem.de/index.php/topic,11648.msg236662.html#msg236662


git-svn-id: https://svn.fhem.de/fhem/trunk@8361 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2015-04-03 14:17:49 +00:00
parent 5eeeea420b
commit 8fe5dfb0be
2 changed files with 22 additions and 12 deletions

View File

@ -25,6 +25,7 @@ EC3000_Initialize($)
$hash->{ParseFn} = "EC3000_Parse";
$hash->{AttrFn} = "EC3000_Attr";
$hash->{AttrList} = "IODev".
" offLevel".
" $readingFnAttributes";
}
@ -63,9 +64,7 @@ EC3000_Define($$)
Log3 $name, 1, "$name: no I/O device";
}
#$attr{$name}{devStateIcon} = 'on:on:toggle off:off:toggle *.:light_exclamation:off' if( !defined( $attr{$name}{devStateIcon} ) );
#$attr{$name}{webCmd} = 'on:off:toggle:statusRequest' if( !defined( $attr{$name}{webCmd} ) );
#CommandAttr( undef, "$name userReadings consumptionTotal:consumption monotonic {ReadingsVal(\$name,'consumption',0)}" ) if( !defined( $attr{$name}{userReadings} ) );
$attr{$name}{stateFormat} = 'state (power W)' if( !defined( $attr{$name}{stateFormat} ) );
return undef;
}
@ -118,11 +117,11 @@ EC3000_Parse($$)
@bytes = split( ' ', substr($msg, 6) );
$addr = sprintf( "%02X%02X", $bytes[0], $bytes[1] );
$secondsTotal = $bytes[2]*256*255*255 + $bytes[3]*256*255 + $bytes[4]*256 + $bytes[5];
$secondsOn = $bytes[6]*256*255*255 + $bytes[7]*256*255 + $bytes[8]*256 + $bytes[9];
$consumptionTotal = ($bytes[10]*256*255*255 + $bytes[11]*256*255 + $bytes[12]*256 + $bytes[13] )/1000.0;
$power = ($bytes[14]*256 + $bytes[15] )/10.0;
$powerMax = ($bytes[16]*256 + $bytes[17] )/10.0;
$secondsTotal = ($bytes[2]<<24) + ($bytes[3]<<16) + ($bytes[4]<<8) + $bytes[5];
$secondsOn = ($bytes[6]<<24) + ($bytes[7]<<16) + ($bytes[8]<<8) + $bytes[9];
$consumptionTotal = ( ($bytes[10]<<24) + ($bytes[11]<<16) + ($bytes[12]<<8) + $bytes[13] )/1000.0;
$power = ( ($bytes[14]<<8) + $bytes[15] )/10.0;
$powerMax = ( ($bytes[16]<<8) + $bytes[17] )/10.0;
$resets = $bytes[18];
$reception = $bytes[19];
} else {
@ -159,7 +158,11 @@ EC3000_Parse($$)
readingsBulkUpdate($rhash, "consumption", $consumptionTotal);
readingsBulkUpdate($rhash, "power", $power);
readingsBulkUpdate($rhash, "powerMax", $powerMax);
readingsBulkUpdate($rhash, "state", $power) if( Value($rname) ne $power );
my $state = "on";
$state = "off" if( $power <= AttrVal($rname, "offLevel", 0) );
readingsBulkUpdate($rhash, "state", $state);
readingsEndUpdate($rhash,1);
return @list;
@ -218,6 +221,8 @@ EC3000_Attr(@)
<a name="EC3000_Attr"></a>
<b>Attributes</b>
<ul>
<li>offLevel<br>
a power level less or equal <code>offLevel</code> is considered to be off</li>
</ul><br>
</ul>

View File

@ -28,6 +28,7 @@ PCA301_Initialize($)
$hash->{AttrList} = "IODev"
." readonly:1"
." forceOn:1"
." offLevel"
." $readingFnAttributes";
}
@ -232,6 +233,8 @@ PCA301_Parse($$)
my $power = ($bytes[6]*256 + $bytes[7]) / 10.0;
my $consumption = ($bytes[8]*256 + $bytes[9]) / 100.0;
my $state = $state; $state = $power if( $readonly );
my $off_level = AttrVal($rname, "offLevel", 0);
$state = "off" if( $readonly && $off_level && $power <= $off_level );
readingsBeginUpdate($rhash);
readingsBulkUpdate($rhash, "power", $power) if( $power != ReadingsVal($rname,"power",0) );
readingsBulkUpdate($rhash, "consumption", $consumption) if( $consumption != ReadingsVal($rname,"consumption",0) );
@ -333,10 +336,12 @@ PCA301_Attr(@)
<a name="PCA301_Attr"></a>
<b>Attributes</b>
<ul>
<li>readonly<br>
if set to a value != 0 all switching commands (on, off, toggle, ...) will be disabled.</li>
<li>forceOn<br>
try to switch on the device whenever an off status is received.</li>
try to switch on the device whenever an off status is received.</li>
<li>offLevel<br>
a power level less or equal <code>offLevel</code> is considered to be off.</li>
<li>readonly<br>
if set to a value != 0 all switching commands (on, off, toggle, ...) will be disabled.</li>
</ul><br>
</ul>