change formated output, add hourly support for DarkSky - thanks to Lippie, multiple factor to wind speed and many bugfix

This commit is contained in:
Marko Oldenburg 2019-01-13 21:13:54 +01:00
parent 0fee7ac3bd
commit 957adf8454
3 changed files with 80 additions and 14 deletions

View File

@ -289,7 +289,7 @@ sub Weather_WriteReadings($$) {
my $val= 'T: ' . $dataRef->{current}->{temperature} . '°C' my $val= 'T: ' . $dataRef->{current}->{temperature} . '°C'
.' ' . substr($status_items_txt_i18n{1}, 0, 1) . ': ' . $dataRef->{current}->{humidity} . '%' .' ' . substr($status_items_txt_i18n{1}, 0, 1) . ': ' . $dataRef->{current}->{humidity} . '%'
.' ' . substr($status_items_txt_i18n{0}, 0, 1) . ': ' . $dataRef->{current}->{wind} . 'km/h' .' ' . substr($status_items_txt_i18n{0}, 0, 1) . ': ' . $dataRef->{current}->{wind} . 'km/h'
.' P:' . $dataRef->{current}->{pressure} . 'mbar'; .' P: ' . $dataRef->{current}->{pressure} . 'hPa';
Log3 $hash, 4, "$name: $val"; Log3 $hash, 4, "$name: $val";
readingsBulkUpdate($hash, 'state', $val); readingsBulkUpdate($hash, 'state', $val);
@ -620,7 +620,7 @@ sub WeatherAsHtmlD($;$)
<a name="Weatherdefine"></a> <a name="Weatherdefine"></a>
<b>Define</b><br><br> <b>Define</b><br><br>
<ul> <ul>
<code>define &lt;name&gt; Weather [API=&lt;API&gt;[,&lt;apiotions&gt;]] [apikey=&lt;apikey&gt;] <code>define &lt;name&gt; Weather [API=&lt;API&gt;[,&lt;apioptions&gt;]] [apikey=&lt;apikey&gt;]
[location=&lt;location&gt;] [interval=&lt;interval&gt;] [lang=&lt;lang&gt;]</code><br><br> [location=&lt;location&gt;] [interval=&lt;interval&gt;] [lang=&lt;lang&gt;]</code><br><br>
@ -783,7 +783,7 @@ sub WeatherAsHtmlD($;$)
<a name="Weatherdefine"></a> <a name="Weatherdefine"></a>
<b>Define</b><br><br> <b>Define</b><br><br>
<ul> <ul>
<code>define &lt;name&gt; Weather [API=&lt;API&gt;[,&lt;apiotions&gt;]] [apikey=&lt;apikey&gt;] <code>define &lt;name&gt; Weather [API=&lt;API&gt;[,&lt;apioptions&gt;]] [apikey=&lt;apikey&gt;]
[location=&lt;location&gt;] [interval=&lt;interval&gt;] [lang=&lt;lang&gt;]</code><br><br> [location=&lt;location&gt;] [interval=&lt;interval&gt;] [lang=&lt;lang&gt;]</code><br><br>
Die Parameter haben die folgende Bedeutung:<br> Die Parameter haben die folgende Bedeutung:<br>

View File

@ -7,6 +7,7 @@
# All rights reserved # All rights reserved
# #
# Special thanks goes to: # Special thanks goes to:
# - Lippie hourly forecast code
# #
# #
# This script is free software; you can redistribute it and/or modify # This script is free software; you can redistribute it and/or modify
@ -228,10 +229,10 @@ sub _ProcessingRetrieveData($$) {
sprintf( "%.1f", $data->{currently}->{pressure} ) + 0.5 sprintf( "%.1f", $data->{currently}->{pressure} ) + 0.5
), ),
'wind' => int( 'wind' => int(
sprintf( "%.1f", $data->{currently}->{windSpeed} ) + 0.5 sprintf( "%.1f", ($data->{currently}->{windSpeed} * 3.6) ) + 0.5
), ),
'wind_speed' => int( 'wind_speed' => int(
sprintf( "%.1f", $data->{currently}->{windSpeed} ) + 0.5 sprintf( "%.1f", ($data->{currently}->{windSpeed} * 3.6) ) + 0.5
), ),
'wind_direction' => $data->{currently}->{windBearing}, 'wind_direction' => $data->{currently}->{windBearing},
'windGust' => int( 'windGust' => int(
@ -430,12 +431,12 @@ sub _ProcessingRetrieveData($$) {
$data->{daily}->{data}->[$i]->{windBearing}, $data->{daily}->{data}->[$i]->{windBearing},
'wind' => int( 'wind' => int(
sprintf( "%.1f", sprintf( "%.1f",
$data->{daily}->{data}->[$i]->{windSpeed} ) ($data->{daily}->{data}->[$i]->{windSpeed} * 3.6) )
+ 0.5 + 0.5
), ),
'wind_speed' => int( 'wind_speed' => int(
sprintf( "%.1f", sprintf( "%.1f",
$data->{daily}->{data}->[$i]->{windSpeed} ) ($data->{daily}->{data}->[$i]->{windSpeed} * 3.6) )
+ 0.5 + 0.5
), ),
'windGust' => int( 'windGust' => int(
@ -481,6 +482,71 @@ sub _ProcessingRetrieveData($$) {
$i++; $i++;
} }
if ( ref( $data->{hourly}->{data} ) eq "ARRAY"
and scalar( @{ $data->{hourly}->{data} } ) > 0 )
{
### löschen des alten Datensatzes
delete $self->{cached}->{forecast}->{hourly};
my $i = 0;
foreach ( @{ $data->{hourly}->{data} } ) {
push(
@{ $self->{cached}->{forecast}->{hourly} },
{
'pubDate' => strftime(
"%a, %e %b %Y %H:%M %p",
localtime(
$data->{hourly}->{data}->[$i]->{'time'}
)
),
'day_of_week' => strftime(
"%a",
localtime(
$data->{hourly}->{data}->[$i]->{'time'}
)
),
'temperature' => sprintf( "%.1f", $data->{hourly}->{data}->[$i]->{temperature} ),
'code' =>
$codes{ $data->{hourly}->{data}->[$i]->{icon} },
'iconAPI' => $data->{hourly}->{data}->[$i]->{icon},
'condition' => encode_utf8(
$data->{hourly}->{data}->[$i]->{summary}
),
'ozone' => $data->{hourly}->{data}->[$i]->{ozone},
'uvIndex' =>
$data->{hourly}->{data}->[$i]->{uvIndex},
'precipIntensity' =>
$data->{hourly}->{data}->[$i]->{precipIntensity},
'dewPoint' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{dewPoint} ),
'humidity' =>
$data->{hourly}->{data}->[$i]->{humidity} * 100,
'cloudCover' =>
$data->{hourly}->{data}->[$i]->{cloudCover} * 100,
'precipType' =>
$data->{hourly}->{data}->[$i]->{precipType},
'wind_direction' =>
$data->{hourly}->{data}->[$i]->{windBearing},
'wind' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{windSpeed} ),
'wind_speed' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{windSpeed} ),
'windGust' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{windGust} ),
'precipProbability' =>
$data->{hourly}->{data}->[$i]->{precipProbability},
'pressure' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{pressure} ),
'visibility' => sprintf( "%.1f",
$data->{hourly}->{data}->[$i]->{visibility} ),
}
);
$i++;
}
}
} }
} }
} }

View File

@ -300,9 +300,9 @@ sub _ProcessingRetrieveData($$) {
'pressure' => 'pressure' =>
int( sprintf( "%.1f", $data->{main}->{pressure} ) + 0.5 ), int( sprintf( "%.1f", $data->{main}->{pressure} ) + 0.5 ),
'wind' => 'wind' =>
int( sprintf( "%.1f", $data->{wind}->{speed} ) + 0.5 ), int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ),
'wind_speed' => 'wind_speed' =>
int( sprintf( "%.1f", $data->{wind}->{speed} ) + 0.5 ), int( sprintf( "%.1f", ($data->{wind}->{speed} * 3.6) ) + 0.5 ),
'wind_direction' => $data->{wind}->{deg}, 'wind_direction' => $data->{wind}->{deg},
'cloudCover' => $data->{clouds}->{all}, 'cloudCover' => $data->{clouds}->{all},
'visibility' => 'visibility' =>
@ -415,12 +415,12 @@ sub _ProcessingRetrieveData($$) {
), ),
'wind' => int( 'wind' => int(
sprintf( "%.1f", sprintf( "%.1f",
$data->{list}->[$i]->{wind}->{speed} ) ($data->{list}->[$i]->{wind}->{speed} * 3.6) )
+ 0.5 + 0.5
), ),
'wind_speed' => int( 'wind_speed' => int(
sprintf( "%.1f", sprintf( "%.1f",
$data->{list}->[$i]->{wind}->{speed} ) ($data->{list}->[$i]->{wind}->{speed} * 3.6) )
+ 0.5 + 0.5
), ),
'cloudCover' => 'cloudCover' =>