From ad34c51d9d4c0ae4582a83e4027826a6a3f6ca87 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:35:05 +0100 Subject: [PATCH] support to weather forecast service Solves #1050 --- ReleaseNotes.md | 11 ++++++--- nspanel_blueprint.yaml | 54 ++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index f2588a4..19310ab 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -32,7 +32,11 @@ Since in this update lots of input to the blueprint changed, we highly recommend   ## Breaking changes -1. The following components are now deprecated: +1. Home Assistant 2023.9.0 or later is now required +This is necessary in order to support the new [Weather Forecast Service](https://www.home-assistant.io/blog/2023/09/06/release-20239/#weather-forecast-service). +The legacy forecast based on attributes will be deprecated in Home Assistant on the begining of 2024. + +2.The following components are now deprecated: - Buttons: - Exit reparse (`button.xxxxx_exit_reparse`) - It shouldn't be necessary with the new TFT upload engine - Services: @@ -60,10 +64,11 @@ packages: - nspanel_esphome_advanced.yaml # activate advanced (legacy) elements - can be useful for troubleshooting ... ``` -2. Very long press on hardware buttons + +3. Very long press on hardware buttons If you have a custom automation using very long hold (more than 15s) of hardware buttons it may fail as now the panel will restart with button hold for 15s. -3. Logger via UART is disable +4. Logger via UART is disable You can add it back as a [customization](https://github.com/Blackymas/NSPanel_HA_Blueprint/wiki/%28EN%29-Customization/_edit#logger-via-uart):   ## Overview of noteworthy changes diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 6f4a4c4..8173203 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -38,7 +38,7 @@ blueprint: source_url: https://github.com/Blackymas/NSPanel_HA_Blueprint/blob/main/nspanel_blueprint.yaml domain: automation homeassistant: - min_version: 2023.5.0 + min_version: 2023.9.0 # yamllint disable rule:line-length input: @@ -8472,6 +8472,7 @@ action: {% else %} Other {% endif %} weather_units: + humidity: '{{ state_attr(weather_entity, "humidity_unit") | default("%") if weather_entity is string and state_attr(weather_entity, "humidity_unit") else "%" }}' hours_of_sun: '{{ state_attr(weather_entity, "hours_of_sun_unit") | default("h") if weather_entity is string and state_attr(weather_entity, "hours_of_sun_unit") else "h" }}' precipitation: '{{ state_attr(weather_entity, "precipitation_unit") | default("") if weather_entity is string and state_attr(weather_entity, "precipitation_unit") }}' precipitation_probability: '{{ state_attr(weather_entity, "precipitation_probability_unit") | default("%") if weather_entity is string and state_attr(weather_entity, "precipitation_probability_unit") else "%" }}' @@ -8512,12 +8513,26 @@ action: - *delay-default ##### Display weather data only when available ##### + - service: weather.get_forecast + target: + entity_id: '{{ weather_entity }}' + data: + type: daily + response_variable: service_response_var - variables: - datetime_is_string: '{{ state_attr(weather_entity, "forecast")[0] is defined and state_attr(weather_entity, "forecast")[0]["datetime"] is string }}' + forecast: > + {{ + service_response_var.forecast + if service_response_var is defined and service_response_var.forecast is defined + else state_attr(weather_entity, "forecast") | default(false) + }} + - condition: '{{ forecast != false }}' + - variables: + datetime_is_string: '{{ forecast[0] is defined and forecast[0]["datetime"] is string }}' forecast_day: > {% if datetime_is_string %} {{ - state_attr(weather_entity, "forecast") | default([]) + forecast | default([]) | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | timestamp_utc ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | timestamp_utc ) @@ -8526,76 +8541,76 @@ action: {% else %} [ { - 'datetime': '{{ state_attr(weather_entity, "forecast") | default([]) + 'datetime': '{{ forecast | default([]) | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="datetime") | list | first | as_timestamp | timestamp_utc - if state_attr(weather_entity, "forecast") | default([]) + if forecast | default([]) | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="datetime") | list | count > 0 else "" }}', - 'condition': '{{ state_attr(weather_entity, "forecast") | default([]) + 'condition': '{{ forecast | default([]) | selectattr("condition", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="condition") | list | first - if state_attr(weather_entity, "forecast") | default([]) + if forecast | default([]) | selectattr("condition", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="condition") | list | count > 0 else "" }}', - 'temperature': '{{ state_attr(weather_entity, "forecast") | default([]) + 'temperature': '{{ forecast | default([]) | selectattr("temperature", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="temperature") | list | first - if state_attr(weather_entity, "forecast") | default([]) + if forecast | default([]) | selectattr("temperature", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="temperature") | list | count > 0 else "" }}', - 'templow': '{{ state_attr(weather_entity, "forecast") | default([]) + 'templow': '{{ forecast | default([]) | selectattr("templow", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="templow") | list | first - if state_attr(weather_entity, "forecast") | default([]) + if forecast | default([]) | selectattr("templow", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="templow") | list | count > 0 else "" }}', - 'precipitation': '{{ state_attr(weather_entity, "forecast") | default([]) + 'precipitation': '{{ forecast | default([]) | selectattr("precipitation", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="precipitation") | list | first - if state_attr(weather_entity, "forecast") | default([]) + if forecast | default([]) | selectattr("precipitation", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="precipitation") | list | count > 0 else "" }}', - 'wind_speed': '{{ state_attr(weather_entity, "forecast") | default([]) + 'wind_speed': '{{ forecast | default([]) | selectattr("wind_speed", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) | selectattr("datetime", "<", (today_at("00:00") + timedelta(days= (page_index+1))) | as_timestamp | as_datetime ) | map(attribute="wind_speed") | list | first - if state_attr(weather_entity, "forecast") | default([]) + if forecast | default([]) | selectattr("wind_speed", "defined") | selectattr("datetime", "defined") | selectattr("datetime", ">=", (today_at("00:00") + timedelta(days= page_index)) | as_timestamp | as_datetime ) @@ -8704,6 +8719,11 @@ action: if forecast_day | selectattr("thunderstorm_probability", "defined") | rejectattr("thunderstorm_probability", "eq", "") | map(attribute="thunderstorm_probability") | map("float") | list | count > 0 ) }} + humidity: > + {{ + forecast_day | selectattr("humidity", "defined") | rejectattr("humidity", "eq", "") | map(attribute="humidity") | map("float") | list | max | round(0) + if forecast_day | selectattr("humidity", "defined") | rejectattr("humidity", "eq", "") | map(attribute="humidity") | map("float") | list | count > 0 + }} parameters: - name: hours_of_sun visibility: '{{ is_number(hours_of_sun) }}' @@ -8730,6 +8750,10 @@ action: visibility: '{{ is_number(wind_speed) }}' value: '{{ (wind_speed ~ " " ~ weather_units.wind_speed) if is_number(wind_speed) }}' icon: '{{ nextion.icon.weather.wind }}' + - name: humidity + visibility: '{{ is_number(humidity) }}' + value: '{{ (humidity ~ " " ~ weather_units.humidity) if is_number(humidity) }}' + icon: '{{ all_icons["water-percent"] }}' - name: pressure visibility: '{{ is_number(pressure) }}' value: '{{ (pressure ~ " " ~ weather_units.pressure) if is_number(pressure) }}'