weatheralerts icon indicating copy to clipboard operation
weatheralerts copied to clipboard

Different icons for each alert type

Open gridlockjoe opened this issue 3 years ago • 9 comments

Is your feature request related to a problem? Please describe. Not a problem, an enhancement

Describe the solution you'd like I have manually edited the weatheralerts_1.yaml file to provide distinct icons for the different alert types. Hope you'll be able to include these in the default code.

Under each of the alerts I replaced

icon_template: hass:alert-rhombus

with:

        icon_template: >-
          {% set mapper =  {
              '911 Telephone Outage Emergency' : 'hass:phone-alert',
              'Administrative Message' : 'hass:message-text',
              'Air Quality Alert' : 'hass:blur',
              'Air Stagnation Advisory' : 'hass:blur',
              'Arroyo And Small Stream Flood Advisory' : 'hass:water-alert',
              'Ashfall Advisory' : 'hass:cloud-alert',
              'Ashfall Warning' : 'hass:cloud-alert',
              'Avalanche Advisory' : 'hass:alert',
              'Avalanche Warning' : 'hass:alert',
              'Avalanche Watch' : 'hass:alert',
              'Beach Hazards Statement' : 'hass:beach',
              'Blizzard Warning' : 'hass:snowflake-alert',
              'Blizzard Watch' : 'hass:snowflake-alert',
              'Blowing Dust Advisory' : 'hass:blur',
              'Blowing Dust Warning' : 'hass:blur',
              'Brisk Wind Advisory' : 'hass:weather-windy',
              'Child Abduction Emergency' : 'hass:human-male-child',
              'Civil Danger Warning' : 'hass:image-filter-hdr',
              'Civil Emergency Message' : 'hass:image-filter-hdr',
              'Coastal Flood Advisory' : 'hass:waves',
              'Coastal Flood Statement' : 'hass:waves',
              'Coastal Flood Warning' : 'hass:waves',
              'Coastal Flood Watch' : 'hass:waves',
              'Dense Fog Advisory' : 'hass:weather-fog',
              'Dense Smoke Advisory' : 'hass:smoke',
              'Dust Advisory' : 'hass:blur',
              'Dust Storm Warning' : 'hass:blur',
              'Earthquake Warning' : 'hass:alert',
              'Evacuation - Immediate' : 'hass:exit-run',
              'Excessive Heat Warning' : 'hass:thermometer-plus',
              'Excessive Heat Watch' : 'hass:thermometer-plus',
              'Extreme Cold Warning' : 'hass:thermometer-minus',
              'Extreme Cold Watch' : 'hass:thermometer-minus',
              'Extreme Fire Danger' : 'hass:fire-alert',
              'Extreme Wind Warning' : 'hass:weather-windy',
              'Fire Warning' : 'hass:fire-alert',
              'Fire Weather Watch' : 'hass:fire-alert',
              'Flash Flood Statement' : 'hass:water-alert',
              'Flash Flood Warning' : 'hass:water-alert',
              'Flash Flood Watch' : 'hass:water-alert',
              'Flood Advisory' : 'hass:water-alert',
              'Flood Statement' : 'hass:water-alert',
              'Flood Warning' : 'hass:water-alert',
              'Flood Watch' : 'hass:water-alert',
              'Freeze Warning' : 'hass:thermometer-minus',
              'Freeze Watch' : 'hass:thermometer-minus',
              'Freezing Fog Advisory' : 'hass:snowflake-alert',
              'Freezing Rain Advisory' : 'hass:snowflake-alert',
              'Freezing Spray Advisory' : 'hass:snowflake-alert',
              'Frost Advisory' : 'hass:snowflake-alert',
              'Gale Warning' : 'hass:weather-windy',
              'Gale Watch' : 'hass:weather-windy',
              'Hard Freeze Warning' : 'hass:thermometer-minus',
              'Hard Freeze Watch' : 'hass:thermometer-minus',
              'Hazardous Materials Warning' : 'hass:radioactive',
              'Hazardous Seas Warning' : 'hass:sail-boat',
              'Hazardous Seas Watch' : 'hass:sail-boat',
              'Hazardous Weather Outlook' : 'hass:message-alert',
              'Heat Advisory' : 'hass:thermometer-plus',
              'Heavy Freezing Spray Warning' : 'hass:snowflake-alert',
              'Heavy Freezing Spray Watch' : 'hass:snowflake-alert',
              'High Surf Advisory' : 'hass:surfing',
              'High Surf Warning' : 'hass:surfing',
              'High Wind Warning' : 'hass:weather-windy',
              'High Wind Watch' : 'hass:weather-windy',
              'Hurricane Force Wind Warning' : 'hass:weather-hurricane',
              'Hurricane Force Wind Watch' : 'hass:weather-hurricane',
              'Hurricane Local Statement' : 'hass:weather-hurricane',
              'Hurricane Warning' : 'hass:weather-hurricane',
              'Hurricane Watch' : 'hass:weather-hurricane',
              'Hydrologic Advisory' : 'hass:message-text',
              'Hydrologic Outlook' : 'hass:message-text',
              'Ice Storm Warning' : 'hass:snowflake-alert',
              'Lake Effect Snow Advisory' : 'hass:snowflake-alert',
              'Lake Effect Snow Warning' : 'hass:snowflake-alert',
              'Lake Effect Snow Watch' : 'hass:snowflake-alert',
              'Lake Wind Advisory' : 'hass:weather-windy',
              'Lakeshore Flood Advisory' : 'hass:waves-arrow-up',
              'Lakeshore Flood Statement' : 'hass:waves-arrow-up',
              'Lakeshore Flood Warning' : 'hass:waves-arrow-up',
              'Lakeshore Flood Watch' : 'hass:waves-arrow-up',
              'Law Enforcement Warning' : 'hass:car-emergency',
              'Local Area Emergency' : 'hass:alert',
              'Low Water Advisory' : 'hass:wave',
              'Marine Weather Statement' : 'hass:sail-boat',
              'Nuclear Power Plant Warning' : 'hass:radioactive',
              'Radiological Hazard Warning' : 'hass:biohazard',
              'Red Flag Warning' : 'fire-alert',
              'Rip Current Statement' : 'hass:surfing',
              'Severe Thunderstorm Warning' : 'hass:weather-lightning',
              'Severe Thunderstorm Watch' : 'hass:weather-lightning',
              'Severe Weather Statement' : 'hass:message-text',
              'Shelter In Place Warning' : 'hass:account-box',
              'Short Term Forecast' : 'hass:message-text',
              'Small Craft Advisory' : 'hass:sail-boat',
              'Small Craft Advisory For Hazardous Seas' : 'hass:sail-boat',
              'Small Craft Advisory For Rough Bar' : 'hass:sail-boat',
              'Small Craft Advisory For Winds' : 'hass:sail-boat',
              'Small Stream Flood Advisory' : 'hass:water-alert',
              'Snow Squall Warning' : 'hass:snowflake-alert',
              'Special Marine Warning' : 'hass:sail-boat',
              'Special Weather Statement' : 'hass:message-alert',
              'Storm Surge Warning' : 'hass:waves-arrow-up',
              'Storm Surge Watch' : 'hass:waves-arrow-up',
              'Storm Warning' : 'hass:weather-lightning',
              'Storm Watch' : 'hass:weather-lightning',
              'Test' : 'hass:message-text',
              'Tornado Warning' : 'hass:weather-tornado',
              'Tornado Watch' : 'hass:weather-tornado',
              'Tropical Depression Local Statement' : 'hass:weather-hurricane',
              'Tropical Storm Local Statement' : 'hass:weather-hurricane',
              'Tropical Storm Warning' : 'hass:weather-hurricane',
              'Tropical Storm Watch' : 'hass:weather-hurricane',
              'Tsunami Advisory' : 'hass:waves-arrow-up',
              'Tsunami Warning' : 'hass:waves-arrow-up',
              'Tsunami Watch' : 'hass:waves-arrow-up',
              'Typhoon Local Statement' : 'hass:weather-hurricane',
              'Typhoon Warning' : 'hass:weather-hurricane',
              'Typhoon Watch' : 'hass:weather-hurricane',
              'Urban And Small Stream Flood Advisory' : 'hass:home-flood',
              'Volcano Warning' : 'hass:image-filter-hdr',
              'Wind Advisory' : 'hass:weather-windy',
              'Wind Chill Advisory' : 'hass:thermometer-minus',
              'Wind Chill Warning' : 'hass:thermometer-minus',
              'Wind Chill Watch' : 'hass:thermometer-minus',
              'Winter Storm Warning' : 'hass:snowflake-alert',
              'Winter Storm Watch' : 'hass:snowflake-alert',
              'Winter Weather Advisory' : 'hass:snowflake-alert' } %}
          {% set state =  states['sensor.weatheralerts_1_alert_1'].attributes.alert_event %}
          {{ mapper[state] if state in mapper else 'hass:alert-rhombus' }}

repeating the same code in each alert block, substituting the alert number.

Describe alternatives you've considered I'm sure there's a more elegant way to do this.

gridlockjoe avatar Oct 27 '21 23:10 gridlockjoe

That is the full set of alert types available.

gridlockjoe avatar Oct 27 '21 23:10 gridlockjoe

Now color the alerts with what NWS uses - https://www.weather.gov/help-map

mjnovotny82 avatar Nov 12 '21 20:11 mjnovotny82

Thanks for sharing that! I'll incorporate the icon enhancement into the next update. I'll try to get an option for alert colors when I get around to refactoring the coding of the template.

jlverhagen avatar Dec 18 '21 20:12 jlverhagen

This is now integrated into the default yaml packages. I'm still working on a more comprehensive release and will integrate this feature directly in the sensor python code to eliminate the need for all of the extra yaml coding.

jlverhagen avatar Feb 02 '22 03:02 jlverhagen

I believe a color code attribute in a sensor could be used in the UI to color the alert text. If it works as I think it will, then I'll also add a color code attribute for each alert and include that directly in the sensor python code as well.

jlverhagen avatar Feb 02 '22 03:02 jlverhagen

I have updated the yaml packages with some fixes for the icon code to prevent template errors and a potential fix for the *_most_recent_active_alert sensors to ensure they get the correct icon.

Please report any alert icon related errors or unexpected behavior here.

jlverhagen avatar Feb 04 '22 03:02 jlverhagen

FYI. When I copied your updated icon snippet to be included for my Android HA app notifications, I needed to replace hass:.... to mdi:...., otherwise it was just giving the general Home Assistant status bar icon. https://companion.home-assistant.io/docs/notifications/notifications-basic/#notification-status-bar-icon

I also made that change to the 5 alert icon sections for being displayed on the Lovelace Cards. Both hass:... or mdi:... rendered the same.

Eventually, I would love to get my Android notifications colors into the Lovelace cards text display alerts - lines 2985 - 3121 of my modified weatheralerts yaml file.

weatheralerts_custom.yaml.txt

mjnovotny82 avatar Feb 18 '22 14:02 mjnovotny82

Here is a demo of the notification alerts.

Screenshot_20220218-082023_One UI Home

mjnovotny82 avatar Feb 18 '22 14:02 mjnovotny82

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 06:04 stale[bot]