diff --git a/packages/custom_weather.yaml b/packages/custom_weather.yaml index 108ffd2..6d3bed3 100644 --- a/packages/custom_weather.yaml +++ b/packages/custom_weather.yaml @@ -881,22 +881,21 @@ sensor: unique_id: 66b5f020-0b5e-48ed-92a2-740d2d708b30 value_template: > {%- macro getReport() -%} - {% if states('sensor.weatheralerts_active_alerts') > '0' %} - {% if is_state('sensor.weatheralerts_alert_1','on') %} - {{ state_attr('sensor.weatheralerts_alert_1','alert_event') }}, - {% endif %} - {% if is_state('sensor.weatheralerts_alert_2','on') %} - {{ state_attr('sensor.weatheralerts_alert_2','alert_event') }}, - {% endif %} - {% if is_state('sensor.weatheralerts_alert_3','on') %} - {{ state_attr('sensor.weatheralerts_alert_3','alert_event') }}, - {% endif %} - {% if is_state('sensor.weatheralerts_alert_4','on') %} - {{ state_attr('sensor.weatheralerts_alert_4','alert_event') }}, - {% endif %} - {% if is_state('sensor.weatheralerts_alert_5','on') %} - {{ state_attr('sensor.weatheralerts_alert_5','alert_event') }} - {% endif %} + {% set alerts = [ + states('sensor.weatheralerts_alert_1_most_recent_active_alert'), + states('sensor.weatheralerts_alert_2_most_recent_active_alert'), + states('sensor.weatheralerts_alert_3_most_recent_active_alert'), + states('sensor.weatheralerts_alert_4_most_recent_active_alert'), + states('sensor.weatheralerts_alert_5_most_recent_active_alert'), + ] %} + {% set main = alerts | reject('eq','unavailable') | select('ne','Flood Warning') | join(", ") | default('') %} + {% set flood = alerts | reject ('eq','unavailable') | select('eq','Flood Warning') | first | default('') %} + {% if flood not in [''] and main not in [''] %} + {{ main + ", " + flood }} + {% elif flood not in [''] and main in [''] %} + {{ flood }} + {% elif main not in [''] and flood in [''] %} + {{ main }} {% else %} 'None' {% endif %} @@ -911,7 +910,43 @@ sensor: {{- cleanup(mother_of_all_macros()) -}} attribute_templates: active_alerts: "{{ states('sensor.weatheralerts_active_alerts') }}" - icon_template: "{{ 'mdi.alert' if states('sensor.weatheralerts_active_alerts') | int > 0 else 'mdi:alert-remove' }}" + icon_template: > + {% if (states('sensor.weatheralerts_active_alerts') | int ) > 0 %} + mdi:alert + {% else %} + mdi:alert-remove + {% endif %} + weather_alerts_active_corrected: + friendly_name: 'Weather Alerts Active - Corrected' + unique_id: e2f51da4-2271-4719-8edf-a28f76ac1e3f + value_template: > + {%- macro getReport() -%} + {% set alerts = [ + states('sensor.weatheralerts_alert_1_most_recent_active_alert'), + states('sensor.weatheralerts_alert_2_most_recent_active_alert'), + states('sensor.weatheralerts_alert_3_most_recent_active_alert'), + states('sensor.weatheralerts_alert_4_most_recent_active_alert'), + states('sensor.weatheralerts_alert_5_most_recent_active_alert'), + ] %} + {% set main = alerts | reject('eq','unavailable') | select('ne','Flood Warning') | list | count | int %} + {% set flood = alerts | reject ('eq','unavailable') | select('eq','Flood Warning') | list | count | int %} + {% set flood1 = 1 if (flood > 0) else 0 %} + {{ (main + flood1) | int }} + {%- endmacro -%} + {%- macro cleanup(data) -%} + {%- for item in data.split("\n") if item | trim != "" -%} + {{ item | trim }} {% endfor -%} + {%- endmacro -%} + {%- macro mother_of_all_macros() -%} + {{ getReport() }} + {%- endmacro -%} + {{- cleanup(mother_of_all_macros()) -}} + icon_template: > + {% if (states('sensor.weatheralerts_active_alerts') | int ) > 0 %} + mdi:alert + {% else %} + mdi:alert-remove + {% endif %} input_boolean: freeze_warning: diff --git a/templates/speech/daily_briefing.yaml b/templates/speech/daily_briefing.yaml index b80cea8..3eb7b69 100644 --- a/templates/speech/daily_briefing.yaml +++ b/templates/speech/daily_briefing.yaml @@ -45,7 +45,7 @@ "The nearest lightning strike is {{ ltgdist }} miles away. " {% endif %} {% if states('sensor.weatheralerts_active_alerts') > '0' %} - "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weatheralerts_active_alerts') }}. They are as follows. " + "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weather_alerts_active_corrected') }}. They are as follows. " {{ states('sensor.weather_alert_string') }}. {% endif %}

diff --git a/templates/speech/morning_briefing.yaml b/templates/speech/morning_briefing.yaml index d8127b1..5bcd320 100644 --- a/templates/speech/morning_briefing.yaml +++ b/templates/speech/morning_briefing.yaml @@ -67,7 +67,7 @@

{% if states('sensor.weatheralerts_active_alerts') > '0' %} - "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weatheralerts_active_alerts') }}. They are as follows. " + "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weather_alerts_active_corrected') }}. They are as follows. " {{ states('sensor.weather_alert_string') }}. {% endif %}

diff --git a/templates/speech/nightly_briefing.yaml b/templates/speech/nightly_briefing.yaml index 911d10f..05e36de 100644 --- a/templates/speech/nightly_briefing.yaml +++ b/templates/speech/nightly_briefing.yaml @@ -73,7 +73,7 @@

{% if states('sensor.weatheralerts_active_alerts') > '0' %} - "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weatheralerts_active_alerts') }}. They are as follows. " + "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weather_alerts_active_corrected') }}. They are as follows. " {{ states('sensor.weather_alert_string') }}. {% endif %}

diff --git a/templates/speech/weather_briefing_full.yaml b/templates/speech/weather_briefing_full.yaml index e1c649e..08338c4 100644 --- a/templates/speech/weather_briefing_full.yaml +++ b/templates/speech/weather_briefing_full.yaml @@ -28,7 +28,7 @@

{% if states('sensor.weatheralerts_active_alerts') > '0' %} - "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weatheralerts_active_alerts') }}. They are as follows. " + "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weather_alerts_active_corrected') }}. They are as follows. " {{ states('sensor.weather_alert_string') }}. {% endif %}

diff --git a/templates/speech/welcome_home.yaml b/templates/speech/welcome_home.yaml index ed5b580..600e27f 100644 --- a/templates/speech/welcome_home.yaml +++ b/templates/speech/welcome_home.yaml @@ -75,7 +75,7 @@

{% if states('sensor.weatheralerts_active_alerts') > '0' %} - "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weatheralerts_active_alerts') }}. They are as follows. " + "Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weather_alerts_active_corrected') }}. They are as follows. " {{ states('sensor.weather_alert_string') }}. {% endif %}