git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1829 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
#
|
#
|
||||||
# Version 2.17 - August, 2012
|
# Version 2.18 - September, 2012
|
||||||
#
|
#
|
||||||
# Setup bus device in fhem.cfg as
|
# Setup bus device in fhem.cfg as
|
||||||
#
|
#
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
# set <name> interval => set query interval for measurement
|
# set <name> interval => set query interval for measurement
|
||||||
# set <name> memory <page> => 32 byte string into page 0..13
|
# set <name> memory <page> => 32 byte string into page 0..13
|
||||||
# set <name> midnight <channel> => todays starting value for counter
|
# set <name> midnight <channel> => todays starting value for counter
|
||||||
# set <name> init => re-initialize device
|
# set <name> init yes => re-initialize device
|
||||||
#
|
#
|
||||||
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
|
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
|
||||||
# Note: attributes are read only during initialization procedure - later changes are not used.
|
# Note: attributes are read only during initialization procedure - later changes are not used.
|
||||||
@@ -219,7 +219,7 @@ sub OWCOUNT_Define ($$) {
|
|||||||
|
|
||||||
#-- Start timer for initialization in a few seconds
|
#-- Start timer for initialization in a few seconds
|
||||||
InternalTimer(time()+1, "OWCOUNT_InitializeDevice", $hash, 0);
|
InternalTimer(time()+1, "OWCOUNT_InitializeDevice", $hash, 0);
|
||||||
|
|
||||||
#-- Start timer for updates
|
#-- Start timer for updates
|
||||||
InternalTimer(time()+$hash->{INTERVAL}, "OWCOUNT_GetValues", $hash, 0);
|
InternalTimer(time()+$hash->{INTERVAL}, "OWCOUNT_GetValues", $hash, 0);
|
||||||
|
|
||||||
@@ -288,6 +288,12 @@ sub OWCOUNT_InitializeDevice($) {
|
|||||||
$hash->{READINGS}{"$owg_rate[$i]"}{TYPE} = $cnama[1]."_rate";
|
$hash->{READINGS}{"$owg_rate[$i]"}{TYPE} = $cnama[1]."_rate";
|
||||||
$hash->{READINGS}{"$owg_rate[$i]"}{UNIT} = $unarr[0].$runit;
|
$hash->{READINGS}{"$owg_rate[$i]"}{UNIT} = $unarr[0].$runit;
|
||||||
$hash->{READINGS}{"$owg_rate[$i]"}{UNITABBR} = $unarr[1].$runit;
|
$hash->{READINGS}{"$owg_rate[$i]"}{UNITABBR} = $unarr[1].$runit;
|
||||||
|
#-- some special cases
|
||||||
|
# Energy/Power
|
||||||
|
$hash->{READINGS}{"$owg_rate[$i]"}{UNIT} = "kW"
|
||||||
|
if ($unarr[0].$runit eq "kWh/h" );
|
||||||
|
$hash->{READINGS}{"$owg_rate[$i]"}{UNITABBR} = "kW"
|
||||||
|
if ($unarr[1].$runit eq "kWh/h" );
|
||||||
#Log 1,"OWCOUNT InitializeDevice with period $period and UNITABBR = ".$hash->{READINGS}{"$owg_rate[$i]"}{UNITABBR};
|
#Log 1,"OWCOUNT InitializeDevice with period $period and UNITABBR = ".$hash->{READINGS}{"$owg_rate[$i]"}{UNITABBR};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -340,7 +346,9 @@ sub OWCOUNT_FormatValues($) {
|
|||||||
for (my $i=0;$i<int(@owg_fixed);$i++){
|
for (my $i=0;$i<int(@owg_fixed);$i++){
|
||||||
my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i];
|
my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i];
|
||||||
my @cnama = split(/\|/,$cname);
|
my @cnama = split(/\|/,$cname);
|
||||||
$owg_channel[$i]=$cnama[0];
|
$owg_channel[$i]= $cnama[0];
|
||||||
|
$owg_rate[$i] = $cnama[0]."_rate";
|
||||||
|
|
||||||
$offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET};
|
$offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET};
|
||||||
$factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR};
|
$factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR};
|
||||||
$unit = $hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR};
|
$unit = $hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR};
|
||||||
@@ -736,6 +744,8 @@ sub OWCOUNT_Set($@) {
|
|||||||
|
|
||||||
#-- reset the device
|
#-- reset the device
|
||||||
if($key eq "init") {
|
if($key eq "init") {
|
||||||
|
return "OWCOUNT: init needs parameter 'yes'"
|
||||||
|
if($value ne "yes");
|
||||||
OWCOUNT_InitializeDevice($hash);
|
OWCOUNT_InitializeDevice($hash);
|
||||||
return "OWCOUNT: Re-initialized device";
|
return "OWCOUNT: Re-initialized device";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
#
|
#
|
||||||
# Version 2.13 - July, 2012
|
# Version 2.18 - September, 2012
|
||||||
#
|
#
|
||||||
# Setup bus device in fhem.cfg as
|
# Setup bus device in fhem.cfg as
|
||||||
#
|
#
|
||||||
@@ -45,10 +45,13 @@
|
|||||||
# set <name> output <channel-name> ON|OFF => set value for channel (name A, B or defined channel name)
|
# set <name> output <channel-name> ON|OFF => set value for channel (name A, B or defined channel name)
|
||||||
# note: 1 = OFF, 0 = ON in normal usage. See also th enote above
|
# note: 1 = OFF, 0 = ON in normal usage. See also th enote above
|
||||||
# set <name> gpio value => set values for channels (3 = both OFF, 1 = B ON 2 = A ON 0 = both ON)
|
# set <name> gpio value => set values for channels (3 = both OFF, 1 = B ON 2 = A ON 0 = both ON)
|
||||||
|
# set <name> init yes => re-initialize device
|
||||||
#
|
#
|
||||||
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
|
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
|
||||||
# Note: attributes are read only during initialization procedure - later changes are not used.
|
# Note: attributes are read only during initialization procedure - later changes are not used.
|
||||||
#
|
#
|
||||||
|
# attr <name> event on-change/on-update = when to write an event (default= on-update)
|
||||||
|
#
|
||||||
# attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value
|
# attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value
|
||||||
# attr <name> <channel>Unit <string>|<string> = values to display in state variable for on|off condition
|
# attr <name> <channel>Unit <string>|<string> = values to display in state variable for on|off condition
|
||||||
# attr <name> <channel>stateS <string> = character string denoting external shortening condition
|
# attr <name> <channel>stateS <string> = character string denoting external shortening condition
|
||||||
@@ -97,7 +100,8 @@ my %gets = (
|
|||||||
my %sets = (
|
my %sets = (
|
||||||
"interval" => "",
|
"interval" => "",
|
||||||
"output" => "",
|
"output" => "",
|
||||||
"gpio" => ""
|
"gpio" => "",
|
||||||
|
"init" => ""
|
||||||
);
|
);
|
||||||
|
|
||||||
my %updates = (
|
my %updates = (
|
||||||
@@ -131,7 +135,8 @@ sub OWSWITCH_Initialize ($) {
|
|||||||
#Offset = an offset added to the reading
|
#Offset = an offset added to the reading
|
||||||
#Factor = a factor multiplied with (reading+offset)
|
#Factor = a factor multiplied with (reading+offset)
|
||||||
#Unit = a unit of measure
|
#Unit = a unit of measure
|
||||||
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2413,DS2406 loglevel:0,1,2,3,4,5 ";
|
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2413,DS2406 loglevel:0,1,2,3,4,5 ".
|
||||||
|
"event:on-update,on-change";
|
||||||
|
|
||||||
for( my $i=0;$i<int(@owg_fixed);$i++ ){
|
for( my $i=0;$i<int(@owg_fixed);$i++ ){
|
||||||
$attlist .= " ".$owg_fixed[$i]."Name";
|
$attlist .= " ".$owg_fixed[$i]."Name";
|
||||||
@@ -491,12 +496,17 @@ sub OWSWITCH_GetValues($) {
|
|||||||
return "OWSWITCH: Could not get values from device $name";
|
return "OWSWITCH: Could not get values from device $name";
|
||||||
}
|
}
|
||||||
$hash->{PRESENT} = 1;
|
$hash->{PRESENT} = 1;
|
||||||
|
#-- old state, new state
|
||||||
|
my $oldval = $hash->{STATE};
|
||||||
$value=OWSWITCH_FormatValues($hash);
|
$value=OWSWITCH_FormatValues($hash);
|
||||||
#--logging
|
my $newval = $hash->{STATE};
|
||||||
|
#--logging depends on setting of the event-attribute
|
||||||
Log 5, $value;
|
Log 5, $value;
|
||||||
$hash->{CHANGED}[0] = $value;
|
my $ev = defined($attr{$name}{"event"}) ? $attr{$name}{"event"} : "on-update";
|
||||||
|
if( ($ev eq "on-update") || (($ev eq "on-change") && ($newval ne $oldval)) ){
|
||||||
DoTrigger($name, undef);
|
$hash->{CHANGED}[0] = $value;
|
||||||
|
DoTrigger($name, undef);
|
||||||
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@@ -534,6 +544,14 @@ sub OWSWITCH_Set($@) {
|
|||||||
my $condx;
|
my $condx;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $model = $hash->{OW_MODEL};
|
my $model = $hash->{OW_MODEL};
|
||||||
|
|
||||||
|
#-- reset the device
|
||||||
|
if($key eq "init") {
|
||||||
|
return "OWCOUNT: init needs parameter 'yes'"
|
||||||
|
if($value ne "yes");
|
||||||
|
OWSWITCH_InitializeDevice($hash);
|
||||||
|
return "OWCOUNT: Re-initialized device";
|
||||||
|
}
|
||||||
|
|
||||||
#-- set new timer interval
|
#-- set new timer interval
|
||||||
if($key eq "interval") {
|
if($key eq "interval") {
|
||||||
@@ -608,9 +626,9 @@ sub OWSWITCH_Set($@) {
|
|||||||
#-- process results - we have to reread the device
|
#-- process results - we have to reread the device
|
||||||
$hash->{PRESENT} = 1;
|
$hash->{PRESENT} = 1;
|
||||||
OWSWITCH_GetValues($hash);
|
OWSWITCH_GetValues($hash);
|
||||||
OWSWITCH_FormatValues($hash);
|
#OWSWITCH_FormatValues($hash);
|
||||||
Log 4, "OWSWITCH: Set $hash->{NAME} $key $value";
|
Log 4, "OWSWITCH: Set $hash->{NAME} $key $value";
|
||||||
$hash->{CHANGED}[0] = $value;
|
#$hash->{CHANGED}[0] = $value;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user