From 32f6dc2fe256d2e27d7efcbe0dc58df1092c1a18 Mon Sep 17 00:00:00 2001 From: pahenning Date: Tue, 4 Sep 2012 17:40:59 +0000 Subject: [PATCH] git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1829 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- contrib/1-Wire/21_OWCOUNT.pm | 18 ++++++++++++++---- contrib/1-Wire/21_OWSWITCH.pm | 36 ++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/contrib/1-Wire/21_OWCOUNT.pm b/contrib/1-Wire/21_OWCOUNT.pm index c6c158a4c..46564e2b5 100644 --- a/contrib/1-Wire/21_OWCOUNT.pm +++ b/contrib/1-Wire/21_OWCOUNT.pm @@ -14,7 +14,7 @@ # # Prof. Dr. Peter A. Henning, 2012 # -# Version 2.17 - August, 2012 +# Version 2.18 - September, 2012 # # Setup bus device in fhem.cfg as # @@ -39,7 +39,7 @@ # set interval => set query interval for measurement # set memory => 32 byte string into page 0..13 # set midnight => todays starting value for counter -# set init => re-initialize device +# set init yes => re-initialize device # # Additional attributes are defined in fhem.cfg, in some cases per channel, where =A,B # 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 InternalTimer(time()+1, "OWCOUNT_InitializeDevice", $hash, 0); - + #-- Start timer for updates 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]"}{UNIT} = $unarr[0].$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}; } @@ -340,7 +346,9 @@ sub OWCOUNT_FormatValues($) { for (my $i=0;$i{READINGS}{"$owg_channel[$i]"}{OFFSET}; $factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR}; $unit = $hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR}; @@ -736,6 +744,8 @@ sub OWCOUNT_Set($@) { #-- reset the device if($key eq "init") { + return "OWCOUNT: init needs parameter 'yes'" + if($value ne "yes"); OWCOUNT_InitializeDevice($hash); return "OWCOUNT: Re-initialized device"; } diff --git a/contrib/1-Wire/21_OWSWITCH.pm b/contrib/1-Wire/21_OWSWITCH.pm index 8bd49ccd9..c80ea2a87 100644 --- a/contrib/1-Wire/21_OWSWITCH.pm +++ b/contrib/1-Wire/21_OWSWITCH.pm @@ -17,7 +17,7 @@ # # Prof. Dr. Peter A. Henning, 2012 # -# Version 2.13 - July, 2012 +# Version 2.18 - September, 2012 # # Setup bus device in fhem.cfg as # @@ -45,10 +45,13 @@ # set output 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 # set gpio value => set values for channels (3 = both OFF, 1 = B ON 2 = A ON 0 = both ON) +# set init yes => re-initialize device # # Additional attributes are defined in fhem.cfg, in some cases per channel, where =A,B # Note: attributes are read only during initialization procedure - later changes are not used. # +# attr event on-change/on-update = when to write an event (default= on-update) +# # attr Name | = name for the channel | a type description for the measured value # attr Unit | = values to display in state variable for on|off condition # attr stateS = character string denoting external shortening condition @@ -97,7 +100,8 @@ my %gets = ( my %sets = ( "interval" => "", "output" => "", - "gpio" => "" + "gpio" => "", + "init" => "" ); my %updates = ( @@ -131,7 +135,8 @@ sub OWSWITCH_Initialize ($) { #Offset = an offset added to the reading #Factor = a factor multiplied with (reading+offset) #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{PRESENT} = 1; + #-- old state, new state + my $oldval = $hash->{STATE}; $value=OWSWITCH_FormatValues($hash); - #--logging + my $newval = $hash->{STATE}; + #--logging depends on setting of the event-attribute Log 5, $value; - $hash->{CHANGED}[0] = $value; - - DoTrigger($name, undef); + my $ev = defined($attr{$name}{"event"}) ? $attr{$name}{"event"} : "on-update"; + if( ($ev eq "on-update") || (($ev eq "on-change") && ($newval ne $oldval)) ){ + $hash->{CHANGED}[0] = $value; + DoTrigger($name, undef); + } return undef; } @@ -534,6 +544,14 @@ sub OWSWITCH_Set($@) { my $condx; my $name = $hash->{NAME}; 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 if($key eq "interval") { @@ -608,9 +626,9 @@ sub OWSWITCH_Set($@) { #-- process results - we have to reread the device $hash->{PRESENT} = 1; OWSWITCH_GetValues($hash); - OWSWITCH_FormatValues($hash); + #OWSWITCH_FormatValues($hash); Log 4, "OWSWITCH: Set $hash->{NAME} $key $value"; - $hash->{CHANGED}[0] = $value; + #$hash->{CHANGED}[0] = $value; return undef; }