Weather.get_forecasts :: Translate

how to translate “cloudy or rainy” to my language (danish)

{{ vejr[‘weather.home’].forecast[1].condition }}

weather.home:
  forecast:
    - condition: cloudy
      precipitation_probability: 0
      datetime: "2024-05-04T10:00:00+00:00"
      wind_bearing: 68.2
      temperature: 13.5
      templow: 12.6
      wind_gust_speed: 2
      wind_speed: 0.89
      precipitation: 0
      humidity: 94
    - condition: rainy
      precipitation_probability: 79.3
      datetime: "2024-05-05T10:00:00+00:00"
      wind_bearing: 108.9
      temperature: 15
      templow: 10.2

i don’t know what i don’t know… but i’ve not seen a way. hopefully someone else will correct me if i’m mistaken.

till then, i’d do a dictionary:

{% set translated_forecasts = {'cloudy': 'overskyet', 'rainy': 'regnfuld'} %}
{{ translated_forecasts.get(vejr['weather.home'].forecast[1].condition) }}

If it’s always a specific future condition you want you could make a template sensor and use the new state_translated function, passing the new sensor to it.

Otherwise, if you’re just displaying forecasts on the UI, it should already be according to your locale.

How are you intending to use this? In a notification?

It’s usually better to state your use case.

1 Like

Thanks, yes it is for a notification. I had hoped that I could make it with the new state_translated option. But yes, I may make a new sensor for it.

data:
  title: "Vejr udsigten for imorgen:"
  data: {}
  message: >-
    Laveste : {{ vejr['weather.home'].forecast[1].templow|float(default=0) }} °C
    Højeste : {{ vejr['weather.home'].forecast[1].temperature|float(default=0)
    }} °C Vind : {{
    vejr['weather.home'].forecast[1].wind_speed|float(default=0)|round(1) }} m/s
    Regn : {{ vejr['weather.home'].forecast[1].precipitation|float(default=0) }}
    mm. {{ vejr['weather.home'].forecast[1].condition }} test 

You can. Make a sensor with the raw condition value – or as many as you need. Then in the notification’s message template field pass the sensor to the function.

Hey Pieter,

could you elaborate a bit on this, I am having trouble getting this to work for weather conditions:

I tested this in the developer tools –> templates with

{{ states(‘sun.sun’) }}

which gives me

above_horizon

while

{{ state_translated(‘sun.sun’) }}

gives me the German

Über dem Horizont

But when I do the same with a weather condition:

{{ states(‘sensor.openweathermap_condition’) }}

gives me

sunny

but

{{ state_translated(‘sensor.openweathermap_condition’) }}

also gives me

sunny

What am I missing?

I’m not sure (I get the same behaviour as you). I think that maybe the translations are missing in the OWM integration’s translation files, although, I’d think that in this case the built-in HA translations for the weather integration would/could be used.

I searched the open issues for HA core on GitHub, but there’s nothing logged for state_translated. So, I’m either missing something or nobody has reported this as an issue.

1 Like