diff --git a/fhem/FHEM/59_Twilight.pm b/fhem/FHEM/59_Twilight.pm index dac6b67ef..3e0a71abd 100644 --- a/fhem/FHEM/59_Twilight.pm +++ b/fhem/FHEM/59_Twilight.pm @@ -192,10 +192,10 @@ sub Twilight_GetUpdate{ ($sunrise_set[$i]{RISE},$sunrise_set[$i]{SET})= twilight_calc($latitude,$longitude,$sunrise_set[$i]{DEGREE},$declination,$timezone,$midseconds,$timediff); readingsUpdate($hash, $sunrise_set[$i]{SR_NAME}, - $sunrise_set[$i]{RISE} eq "nan" ? "undefined" : + $sunrise_set[$i]{RISE} eq "0" ? "undefined" : strftime("%H:%M:%S",localtime($sunrise_set[$i]{RISE}))); readingsUpdate($hash, $sunrise_set[$i]{SS_NAME}, - $sunrise_set[$i]{SET} eq "nan" ? "undefined" : + $sunrise_set[$i]{SET} eq "2000000000" ? "undefined" : strftime("%H:%M:%S",localtime($sunrise_set[$i]{SET}))); } my $k=0; @@ -204,7 +204,6 @@ sub Twilight_GetUpdate{ my $licht; for(my $i=0;$i < 12;$i++){ $nexttime=$sunrise_set[6-abs($i-6)-$k]{$half}; - next if($nexttime eq "undefined"); if($nexttime > $now && $nexttime!=2000000000){ readingsUpdate($hash,"light", 6-abs($i-6)); if($i<6){ @@ -219,24 +218,25 @@ sub Twilight_GetUpdate{ $nexttime=900 if($nexttime>900); }else{ $nexttime = $nexttime-$now+10; - } - if(!$hash->{LOCAL}) { - InternalTimer(sprintf("%.0f",$now+$nexttime), "Twilight_GetUpdate", $hash, 0); - readingsUpdate($hash,"nextUpdate",strftime("%H:%M:%S",localtime($now+$nexttime))); - } - $hash->{STATE}=$i; - last; + } + if(!$hash->{LOCAL}) { + InternalTimer(sprintf("%.0f",$now+$nexttime), "Twilight_GetUpdate", $hash, 0); + readingsUpdate($hash,"nextUpdate",strftime("%H:%M:%S",localtime($now+$nexttime))); + } + $hash->{STATE}=$i; + last; } - if ($i == 5){ - $k=1; - $half="SET"; - } - if($nexttime<$now && $i==11){ - if(!$hash->{LOCAL}) { - InternalTimer($now+900, "Twilight_GetUpdate", $hash, 0); - } - readingsUpdate($hash,"light", 0); - $hash->{STATE}=0; + + if ($i == 5){ + $k=1; + $half="SET"; + } + if($nexttime<$now && $i==11){ + if(!$hash->{LOCAL}) { + InternalTimer($now+900, "Twilight_GetUpdate", $hash, 0); + } + readingsUpdate($hash,"light", 0); + $hash->{STATE}=0; } } @@ -264,6 +264,8 @@ sub twilight_calc { $sunrise=0; $sunset=2000000000; } + $sunrise = 0 if($sunrise eq "nan"); + $sunset = 2000000000 if($sunset eq "nan"); return $sunrise, $sunset; }