Possible to template notification_icon?

I’m trying to spruce up some of my notifications and was hoping to use a template in my daily weather notification to have the notification_icon match the forecast conditions. Does anyone know if this is possible? Because I can’t get it to work as expected.

Here’s what I’ve got:

    service: notify.mobile_app_pixel_4_xl
    data:
      title: Tomorrow's Forecast
      notification_icon: mdi:weather-{{ state_attr("weather.home", "forecast")[0].condition }}
      message: |
          Tomorrow will be {{ state_attr("weather.home", "forecast")[0].condition | capitalize }}
          <br>
          High {{ state_attr("weather.home", "forecast")[0].temperature }}° / Low {{ state_attr("weather.home", "forecast")[0].templow }}°
          <br>
          {{ state_attr("weather.home", "forecast")[0].precipitation_probability }}% chance of precipitation.

The template of mdi:weather-{{ state_attr("weather.home", "forecast")[0].condition }} returns mdi:weather-rainy in the template editor as expected but trying to use it in the service call spits out an “extra keys not allowed” error.

1 Like

your YAML is not formatted corrected for notification_icon try this:

service: notify.mobile_app_pixel_4_xl
    data:
      title: Tomorrow's Forecast
      message: |
          Tomorrow will be {{ state_attr("weather.home", "forecast")[0].condition | capitalize }}
          <br>
          High {{ state_attr("weather.home", "forecast")[0].temperature }}° / Low {{ state_attr("weather.home", "forecast")[0].templow }}°
          <br>
          {{ state_attr("weather.home", "forecast")[0].precipitation_probability }}% chance of precipitation.
The template of mdi:weather-{{ state_attr("weather.home", "forecast")[0].condition }}
      data:
        notification_icon: mdi:weather-{{ state_attr("weather.home", "forecast")[0].condition }}

docs that also show the correct example: Introduction | Home Assistant Companion Docs

Dag nabbit! Thanks that fixed it!!

1 Like