Adding experimental UV Index support for weather module (#3108)

This pr adds (config.js toggleable) showUV_Index to the hourly and
current weather modules, with right now only openmeteo configured to
supply the data. Other providers could have support too by adding
`uv_index` to current and hourly.

For example the current weather looks like
![image](https://github.com/MichMich/MagicMirror/assets/124401812/00fdf5db-c0d5-4797-9a31-1d72dd970d26)
positioned after sunset in the top row.



The following "hacks" are included and could be fixed to make it
cleaner, but the functionality is wanted and it works without problem.
- To hide entries where the UV Index is 0 i added an if statement to the
`hourly.njk` which is not how precipitation is handled.
The following are minor things that might not need fixing:
- The forecast option does not have UV support. This might not be
relevant since UV changes throughout the day but i tried to implement a
"max_UV" to openmeteo.js, but am not confident enough in JS to
accomplish that.
- The UV Icon is wi-hot and manually added to the `.njk`'s. This could
be made changeable by a config but does not seem relevant since wi-hot
is not used by anything else as far as i can tell.

---------

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
OWL4C
2023-05-22 08:57:48 +00:00
committed by GitHub
parent 0573d6e772
commit eceec8285d
7 changed files with 35 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ _This release is scheduled to be released on 2023-07-01._
### Added ### Added
- Added UV Index to hourly and current Weather, with support for Openmeteo
- Added tests for serveronly - Added tests for serveronly
- Set Timezone `Europe/Berlin` in unit tests (needed for new formatTime tests) - Set Timezone `Europe/Berlin` in unit tests (needed for new formatTime tests)
- Added no-param-reassign eslint rule and fix warnings - Added no-param-reassign eslint rule and fix warnings

View File

@@ -28,6 +28,12 @@
{% endif %} {% endif %}
</span> </span>
{% endif %} {% endif %}
{% if config.showUVIndex %}
<td class="align-right bright uv-index">
<div class="wi dimmed wi-hot"></div>
{{ current.uv_index }}
</td>
{% endif %}
</div> </div>
{% endif %} {% endif %}
<div class="large light"> <div class="large light">

View File

@@ -32,6 +32,12 @@
{{ f.precipitationProbability | unit("precip", "%") }} {{ f.precipitationProbability | unit("precip", "%") }}
</td> </td>
{% endif %} {% endif %}
{% if config.showUVIndex %}
<td class="align-right dimmed uv-index">
{{ f.uv_index }}
<span class="wi dimmed weathericon wi-hot"></span>
</td>
{% endif %}
</tr> </tr>
{% set currentStep = currentStep + 1 %} {% set currentStep = currentStep + 1 %}
{% endfor %} {% endfor %}

View File

@@ -10,6 +10,14 @@
<td class="align-right bright"> <td class="align-right bright">
{{ hour.temperature | roundValue | unit("temperature") }} {{ hour.temperature | roundValue | unit("temperature") }}
</td> </td>
{% if config.showUVIndex %}
<td class="align-right bright uv-index">
{% if hour.uv_index!=0 %}
{{ hour.uv_index }}
<span class="wi weathericon wi-hot"></span>
{% endif %}
</td>
{% endif %}
{% if config.showPrecipitationAmount %} {% if config.showPrecipitationAmount %}
<td class="align-right bright precipitation-amount"> <td class="align-right bright precipitation-amount">
{{ hour.precipitationAmount | unit("precip", hour.precipitationUnits) }} {{ hour.precipitationAmount | unit("precip", hour.precipitationUnits) }}

View File

@@ -76,8 +76,10 @@ WeatherProvider.register("openmeteo", {
"et0_fao_evapotranspiration", "et0_fao_evapotranspiration",
// Total precipitation (rain, showers, snow) sum of the preceding hour // Total precipitation (rain, showers, snow) sum of the preceding hour
"precipitation", "precipitation",
//Precipitation Probability // Precipitation Probability
"precipitation_probability", "precipitation_probability",
// UV index
"uv_index",
// Snowfall amount of the preceding hour in centimeters. For the water equivalent in millimeter, divide by 7. E.g. 7 cm snow = 10 mm precipitation water equivalent // Snowfall amount of the preceding hour in centimeters. For the water equivalent in millimeter, divide by 7. E.g. 7 cm snow = 10 mm precipitation water equivalent
"snowfall", "snowfall",
// Rain from large scale weather systems of the preceding hour in millimeter // Rain from large scale weather systems of the preceding hour in millimeter
@@ -132,6 +134,8 @@ WeatherProvider.register("openmeteo", {
"winddirection_10m_dominant", "winddirection_10m_dominant",
// The sum of solar radiation on a given day in Megajoules // The sum of solar radiation on a given day in Megajoules
"shortwave_radiation_sum", "shortwave_radiation_sum",
//UV Index
"uv_index_max",
// Daily sum of ET₀ Reference Evapotranspiration of a well watered grass field // Daily sum of ET₀ Reference Evapotranspiration of a well watered grass field
"et0_fao_evapotranspiration" "et0_fao_evapotranspiration"
], ],
@@ -383,7 +387,8 @@ WeatherProvider.register("openmeteo", {
currentWeather.rain = parseFloat(weather.hourly[h].rain); currentWeather.rain = parseFloat(weather.hourly[h].rain);
currentWeather.snow = parseFloat(weather.hourly[h].snowfall * 10); currentWeather.snow = parseFloat(weather.hourly[h].snowfall * 10);
currentWeather.precipitationAmount = parseFloat(weather.hourly[h].precipitation); currentWeather.precipitationAmount = parseFloat(weather.hourly[h].precipitation);
currentWeather.precipitationProbability = parseFloat(weather.precipitation_probability); currentWeather.precipitationProbability = parseFloat(weather.hourly[h].precipitation_probability);
currentWeather.uv_index = parseFloat(weather.hourly[h].uv_index);
return currentWeather; return currentWeather;
}, },
@@ -408,6 +413,7 @@ WeatherProvider.register("openmeteo", {
currentWeather.snow = parseFloat(weather.snowfall_sum * 10); currentWeather.snow = parseFloat(weather.snowfall_sum * 10);
currentWeather.precipitationAmount = parseFloat(weather.precipitation_sum); currentWeather.precipitationAmount = parseFloat(weather.precipitation_sum);
currentWeather.precipitationProbability = parseFloat(weather.precipitation_probability); currentWeather.precipitationProbability = parseFloat(weather.precipitation_probability);
currentWeather.uv_index = parseFloat(weather.uv_index_max);
days.push(currentWeather); days.push(currentWeather);
}); });
@@ -442,6 +448,7 @@ WeatherProvider.register("openmeteo", {
currentWeather.snow = parseFloat(weather.snowfall * 10); currentWeather.snow = parseFloat(weather.snowfall * 10);
currentWeather.precipitationAmount = parseFloat(weather.precipitation); currentWeather.precipitationAmount = parseFloat(weather.precipitation);
currentWeather.precipitationProbability = parseFloat(weather.precipitation_probability); currentWeather.precipitationProbability = parseFloat(weather.precipitation_probability);
currentWeather.uv_index = parseFloat(weather.uv_index);
hours.push(currentWeather); hours.push(currentWeather);
}); });

View File

@@ -30,7 +30,8 @@
} }
.weather .precipitation-amount, .weather .precipitation-amount,
.weather .precipitation-prob { .weather .precipitation-prob,
.weather .uv-index {
padding-left: 20px; padding-left: 20px;
padding-right: 0; padding-right: 0;
} }

View File

@@ -27,6 +27,7 @@ Module.register("weather", {
showPeriodUpper: false, showPeriodUpper: false,
showPrecipitationAmount: false, showPrecipitationAmount: false,
showPrecipitationProbability: false, showPrecipitationProbability: false,
showUVIndex: false,
showSun: true, showSun: true,
showWindDirection: true, showWindDirection: true,
showWindDirectionAsArrow: false, showWindDirectionAsArrow: false,