Translation of a weather entity

Hello everyone,

I’m relatively new to Home Assistant and I’m trying to setup a notification each morning giving the daily forecast.

No issue with the notification sending but I can’t figure out how to translate the state attribute to my language.

Here is my automation :

alias: Notification météo matin
description: ""
trigger:
  - platform: time
    at: "07:40:00"
condition: []
action:
  - service: notify.notify
    metadata: {}
    data:
      title: Météo du jour
      message: >-
        Aujourdhui, le temps sera
        {{state_attr('weather.saint_ciers_de_canesse','forecast')[0].condition}}
        avec des températures minimales de
        {{state_attr('weather.saint_ciers_de_canesse','forecast')[0].templow}}°C
        et maximales de 
        {{state_attr('weather.saint_ciers_de_canesse','forecast')[0].temperature}}°C.
mode: single

And here is the template I’ve tried in my configuration.yaml

template:
    - sensor:
        - name: "Meteo Saint Ciers de Canesse"
          state: >
                {% if is_state('weather.saint_ciers_de_canesse', 'clear') %}
                    Ciel dégagé
                {% elif is_state('weather.saint_ciers_de_canesse', 'clear-night') %}
                    Nuit claire
                {% elif is_state('weather.saint_ciers_de_canesse', 'cloudy') %}
                    Nuageux   
                {% elif is_state('weather.saint_ciers_de_canesse', 'rainy') %}
                    Pluie        
                {% elif is_state('weather.saint_ciers_de_canesse', 'hail') %}
                    Risque de grèle
                {% elif is_state('weather.saint_ciers_de_canesse', 'snowy') %}
                    Neige
                {% elif is_state('weather.saint_ciers_de_canesse', 'windy') %}
                 Venteux
                {% elif is_state('weather.saint_ciers_de_canesse', 'fog') %}
                    Brouillard
                {% elif is_state('weather.saint_ciers_de_canesse', 'partlycloudy') %}
                    Eclaircies
                {% elif is_state('weather.saint_ciers_de_canesse', 'pouring') %}
                    Pluie forte
                {% elif is_state('weather.saint_ciers_de_canesse', 'lightning') %}
                    Orages
                {% elif is_state('weather.saint_ciers_de_canesse', 'sunny') %}
                    Ensoleillé
                {% elif is_state('weather.saint_ciers_de_canesse', 'windy-variant') %}
                    Venteux variable
                {% elif is_state('weather.saint_ciers_de_canesse', 'Exceptional') %}
                    Exceptionnel
                {% elif is_state('weather.saint_ciers_de_canesse', 'snowy-rainy') %}
                    Pluie verglaçante
                {% elif is_state('weather.saint_ciers_de_canesse', 'lightning-rainy') %}
                    Pluie orageuse
                {% else %}
                    error
                {% endif %}

Any help is welcome :pray:

Your sensor.meteo_saint_ciers_de_canesse only translates the state of your weather entity, whereas you need the condition of the forecast attributes translated in your automation.

This might be a useful application for a reusable template, so you can quickly and easily translate it anywhere. Create something like custom_templates/traduire.jinja with this in:

{% macro traduire(mots) -%}
{{ {'clear': 'Ciel dégagé',
    'clear-night': 'Nuit claire',
    'cloudy': 'Nuageux',
    'rainy': 'Pluie',
    'hail': 'Risque de grèle',
    'snowy': 'Neige',
    'windy': 'Venteux',
    'fog': 'Brouillard',
    'partlycloudy': 'Eclaircies',
    'pouring': 'Pluie forte',
    'lightning': 'Orages',
    'sunny': 'Ensoleillé',
    'windy-variant': 'Venteux variable',
    'exceptional': 'Exceptionnel',
    'snowy-rainy': 'Pluie verglaçante',
    'lightning-rainy': 'Pluie orageuse'}.get(mots,'error') -}}
{% endmacro -%}

Restart or call the service as described. Then in your automation:

      message: >-
        {% from 'traduire.jinja' import traduire %}
        Aujourdhui, le temps sera
        {{ traduire(state_attr('weather.saint_ciers_de_canesse','forecast')[0].condition) }}
        avec des températures minimales de
        {{state_attr('weather.saint_ciers_de_canesse','forecast')[0].templow}}°C
        et maximales de 
        {{state_attr('weather.saint_ciers_de_canesse','forecast')[0].temperature}}°C.

and your template sensor:

template:
    - sensor:
        - name: "Meteo Saint Ciers de Canesse"
          state: >
            {% from 'traduire.jinja' import traduire %}
            {{ traduire(states('weather.saint_ciers_de_canesse')) }}
3 Likes

Wow, you’re the man @Troon! Thanks a lot, it worked flawlessly :slight_smile:

1 Like

You could also use this:

Or this 2024.3: Drag 'n Drop it like it's hot! 🎉 - Home Assistant