Animation Badges

J’ai trouvé une solution, mais faut optimiser le code.

j’ai créer un sensor template.

  - platform: template
    sensors:
      weather_icon:
        friendly_name: 'weather_icon'
        value_template: >
          {{states('weather.saint_xxxxxxx')}}
        entity_picture_template: >
          {% set mapper = 
            { 'clear night': 'day',
              'cloudy': 'cloudy',
              'fog': 'cloudy',
              'hail': 'rainy-7',
              'lightning': 'thunder',
              'lightning rainy': 'thunder',
              'mostly cloudy': 'cloudy',
              'partly cloudy': 'cloudy',
              'partlycloudy': 'cloudy-day-3',
              'pouring': 'rainy-6',
              'rainy': 'rainy-5',
              'snowy': 'snowy-6',
              'snowy rainy': 'rainy-7',
              'sunny': 'day',
              'windy': 'cloudy',
              'windy variant': 'cloudy-day-3'} %} 
          {% set state = states('weather.saint_xxxxxx').lower().replace('-',' ') %}
          {{ '/local/weather/animated/{}.svg'.format(mapper[state]) }}

J’ai les icones animé en SVG dans le dossier /config/www/weather/animated/

j’ai eu ce message au démarrage:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1822
First occurred: 16:47:20 (8 occurrences)
Last logged: 16:47:20

Template variable warning: 'dict object' has no attribute 'unknown' when rendering '{% set mapper = { 'clear night': 'day', 'cloudy': 'cloudy', 'fog': 'cloudy', 'hail': 'rainy-7', 'lightning': 'thunder', 'lightning rainy': 'thunder', 'mostly cloudy': 'cloudy', 'partly cloudy': 'cloudy', 'partlycloudy': 'cloudy-day-3', 'pouring': 'rainy-6', 'rainy': 'rainy-5', 'snowy': 'snowy-6', 'snowy rainy': 'rainy-7', 'sunny': 'day', 'windy': 'cloudy', 'windy variant': 'cloudy-day-3'} %} {% set state = states('weather.saint_xxxxxxx').lower().replace('-',' ') %} {{ '/local/weather/animated/{}.svg'.format(mapper[state]) }}'
Template variable warning: 'dict object' has no attribute 'unknown' when rendering '{{states('weather.saint_xxxxxx')}} {% set mapper = { 'clear night': 'day', 'cloudy': 'cloudy', 'fog': 'cloudy', 'hail': 'rainy-7', 'lightning': 'thunder', 'lightning rainy': 'thunder', 'mostly cloudy': 'cloudy', 'partly cloudy': 'cloudy', 'partlycloudy': 'cloudy-day-3', 'pouring': 'rainy-6', 'rainy': 'rainy-5', 'snowy': 'snowy-6', 'snowy rainy': 'rainy-7', 'sunny': 'day', 'windy': 'cloudy', 'windy variant': 'cloudy-day-3'} %} {% set state = states('weather.saint_xxxxxxx').lower().replace('-',' ') %} {{ '/local/weather/animated/{}.svg'.format(mapper[state]) }}'

faut que je rajoute unknown dans les variables, car le temp que l’os boot et ma connexion lente ca met un moment a mettre a jour l’info du capteur :wink:

au final ca donne ca
svg 2

svg

EDIT:

J’ai modifier le code pour l’erreur du unknown en mettant l’icone weather et le problème est résolu :slight_smile:

Sensor template FiNAL:

  - platform: template
    sensors:
      weather_icon:
        friendly_name: 'weather_icon'
        value_template: >
          {{states('weather.saint_xxxxxxx')}}
        entity_picture_template: >
          {% set mapper = 
            { 'clear night': 'day',
              'cloudy': 'cloudy',
              'fog': 'cloudy',
              'hail': 'rainy-7',
              'lightning': 'thunder',
              'lightning rainy': 'thunder',
              'mostly cloudy': 'cloudy',
              'partly cloudy': 'cloudy',
              'partlycloudy': 'cloudy-day-3',
              'pouring': 'rainy-6',
              'rainy': 'rainy-5',
              'snowy': 'snowy-6',
              'snowy rainy': 'rainy-7',
              'sunny': 'day',
              'windy': 'cloudy',
              'unknown': 'weather',
              'windy variant': 'cloudy-day-3'} %} 
          {% set state = states('weather.saint_xxxxxxx').lower().replace('-',' ') %}
          {{ '/local/weather/animated/{}.svg'.format(mapper[state]) }}

J’ai fais de même pour le soleil

  - platform: template
    sensors:
      sun_icon:
        friendly_name: 'sun_icon'
        value_template: >
          {{states('sun.sun')}}
        entity_picture_template: >
          {% set mapper = 
            { 'above_horizon': 'day',
              'below_horizon': 'night',
              'unknown': 'weather'} %} 
          {% set state = states('sun.sun').lower().replace('-',' ') %}
          {{ '/local/weather/animated/{}.svg'.format(mapper[state]) }}

sun

2 « J'aime »