diff --git a/fhem/CHANGED b/fhem/CHANGED index b2d182f14..48f0945d3 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,6 +1,8 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. - SVN + - feature: YAMAHA_AVR: define separate on and off status intervals for + cyclic status updates - feature: Visualizations (Plots) for SYSMON added - feature: new module 42_SYSMON.pm added (hexenmeister) - feature: YAMAHA_AVR: new readings for radio stations, current title diff --git a/fhem/FHEM/71_YAMAHA_AVR.pm b/fhem/FHEM/71_YAMAHA_AVR.pm index 2432ce61c..446179ccc 100755 --- a/fhem/FHEM/71_YAMAHA_AVR.pm +++ b/fhem/FHEM/71_YAMAHA_AVR.pm @@ -37,6 +37,7 @@ use HttpUtils; sub YAMAHA_AVR_Get($@); sub YAMAHA_AVR_Define($$); sub YAMAHA_AVR_GetStatus($;$); +sub YAMAHA_AVR_ResetTimer($;$); sub YAMAHA_AVR_Undefine($$); @@ -67,7 +68,7 @@ YAMAHA_AVR_GetStatus($;$) $local = 0 unless(defined($local)); - return "" if(!defined($hash->{helper}{ADDRESS}) or !defined($hash->{helper}{INTERVAL})); + return "" if(!defined($hash->{helper}{ADDRESS}) or !defined($hash->{helper}{OFF_INTERVAL}) or !defined($hash->{helper}{ON_INTERVAL})); my $device = $hash->{helper}{ADDRESS}; @@ -87,7 +88,7 @@ YAMAHA_AVR_GetStatus($;$) if(not defined($zone)) { - InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "YAMAHA_AVR_GetStatus", $hash, 0) unless($local == 1); + YAMAHA_AVR_ResetTimer($hash) unless($local == 1); return "No Zone available"; } @@ -98,7 +99,7 @@ YAMAHA_AVR_GetStatus($;$) if(not defined($return) or $return eq "") { readingsSingleUpdate($hash, "state", "absent", 1); - InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "YAMAHA_AVR_GetStatus", $hash, 0) unless($local == 1); + YAMAHA_AVR_ResetTimer($hash) unless($local == 1); return; } @@ -206,7 +207,7 @@ YAMAHA_AVR_GetStatus($;$) readingsEndUpdate($hash, 1); - InternalTimer(gettimeofday()+$hash->{helper}{INTERVAL}, "YAMAHA_AVR_GetStatus", $hash, 0) unless($local == 1); + YAMAHA_AVR_ResetTimer($hash) unless($local == 1); Log3 $name, 4, "YAMAHA_AVR $name: ".$hash->{STATE}; @@ -618,11 +619,21 @@ YAMAHA_AVR_Define($$) # if an update interval was given which is greater than zero, use it. if(defined($a[4]) and $a[4] > 0) { - $hash->{helper}{INTERVAL}=$a[4]; + $hash->{helper}{OFF_INTERVAL} = $a[4]; } else { - $hash->{helper}{INTERVAL}=30; + $hash->{helper}{OFF_INTERVAL} = 30; + } + + + if(defined($a[5]) and $a[5] > 0) + { + $hash->{helper}{ON_INTERVAL} = $a[5]; + } + else + { + $hash->{helper}{ON_INTERVAL} = $hash->{helper}{OFF_INTERVAL}; } @@ -656,8 +667,7 @@ YAMAHA_AVR_Define($$) } # start the status update timer - RemoveInternalTimer($hash); - InternalTimer(gettimeofday()+2, "YAMAHA_AVR_GetStatus", $hash, 0); + YAMAHA_AVR_ResetTimer($hash,2); return undef; } @@ -984,7 +994,28 @@ sub YAMAHA_AVR_getInputs($) } +############################# +sub +YAMAHA_AVR_ResetTimer($;$) +{ + my ($hash, $interval) = @_; + + RemoveInternalTimer($hash); + + if(defined($interval)) + { + InternalTimer(gettimeofday()+$interval, "YAMAHA_AVR_GetStatus", $hash, 0); + } + elsif($hash->{READINGS}{presence}{VAL} eq "present" and $hash->{READINGS}{power}{VAL} eq "on") + { + InternalTimer(gettimeofday()+$hash->{helper}{ON_INTERVAL}, "YAMAHA_AVR_GetStatus", $hash, 0); + } + else + { + InternalTimer(gettimeofday()+$hash->{helper}{OFF_INTERVAL}, "YAMAHA_AVR_GetStatus", $hash, 0); + } +} 1; @@ -998,7 +1029,11 @@ sub YAMAHA_AVR_getInputs($) Define @@ -1199,7 +1243,10 @@ sub YAMAHA_AVR_getInputs($) Definition Zonenauswahl