Automation based of YR component weather symbols

Hi, im planing on writing an automation that depends on what type of weather the YR component shows at that specifik time. In the stats window of HA the symbol shows a value that corresponds with the right symbol. For instans now its cloudy and is equal to 46. What I want and is looking for is a list of what each weather symobol have for value but cant find any. Anyone know?

The list with the weather types corresponding to the number.
http://api.met.no/weatherapi/weathericon/1.1/documentation

I made an translation of the weather types and used an template sensor that shows the description.
Next step is to use the night icons when the sun is down by setting is_night = 0 for the icons.

2 Likes

Hi fn87,

Thanks a lot for the link!
Do you think you could pass the code for your template sensor? I was just about to do try this myself as I find it odd to have a number in my front end but I find templating difficult. :slight_smile:

Best regards
John

https://pastebin.com/pZ2cma0C

Translations to Swedish. Hope this helps.

BR
Fredrik

3 Likes

Wonderful!

Stort tack Fredrik!

Good job!

I still have a question (maybe it’s trivial but I can not find it anywhere). How to use it exactly in Hass.io?

I was scratching my head quite a bit at the whole templating ordeal as well, but I managed to implement it like this in my configuration.yaml file:

sensor:
  - platform: yr
  - platform: template
    sensors:     
      yr_symbol_current:
        friendly_name: "Just nu:"
        value_template: >-
          {% if states.sensor.yr_symbol.state | int==1%}Klart
          {% elif states.sensor.yr_symbol.state | int==2%}Lätt monligt
          {% elif states.sensor.yr_symbol.state | int==3%}Halvklart till mulet
          {% elif states.sensor.yr_symbol.state | int==4%}Moln
          {% elif states.sensor.yr_symbol.state | int==5%}Sol med inslag skurar
          {% elif states.sensor.yr_symbol.state | int==6%}Sol med inslag av ĂĄska och skurar
          {% elif states.sensor.yr_symbol.state | int==7%}Sol med inslag av snöblandat regn
          {% elif states.sensor.yr_symbol.state | int==8%}Sol med inslag av snö
          {% elif states.sensor.yr_symbol.state | int==9%}Duggregn
          {% elif states.sensor.yr_symbol.state | int==10%}Regn
          {% elif states.sensor.yr_symbol.state | int==11%}Regn och ĂĄska
          {% elif states.sensor.yr_symbol.state | int==12%}Snöblandat regn
          {% elif states.sensor.yr_symbol.state | int==13%}Snö
          {% elif states.sensor.yr_symbol.state | int==14%}SnowThunder
          {% elif states.sensor.yr_symbol.state | int==15%}Dimma
          {% elif states.sensor.yr_symbol.state | int==16%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==17%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==18%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==19%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==20%}Snöblandat regn och åska
          {% elif states.sensor.yr_symbol.state | int==21%}Sol och snö med inslag av åska
          {% elif states.sensor.yr_symbol.state | int==22%}Lätt regn
          {% elif states.sensor.yr_symbol.state | int==23%}SleetThunder
          {% elif states.sensor.yr_symbol.state | int==24%}DrizzleThunderSun
          {% elif states.sensor.yr_symbol.state | int==25%}RainThunderSun
          {% elif states.sensor.yr_symbol.state | int==26%}LightSleetThunderSun
          {% elif states.sensor.yr_symbol.state | int==27%}HeavySleetThunderSun
          {% elif states.sensor.yr_symbol.state | int==28%}LightSnowThunderSun
          {% elif states.sensor.yr_symbol.state | int==29%}HeavySnowThunderSun
          {% elif states.sensor.yr_symbol.state | int==30%}DrizzleThunder
          {% elif states.sensor.yr_symbol.state | int==31%}LightSleetThunder
          {% elif states.sensor.yr_symbol.state | int==32%}HeavySleetThunder
          {% elif states.sensor.yr_symbol.state | int==33%}LightSnowThunder
          {% elif states.sensor.yr_symbol.state | int==34%}HeavySnowThunder
          {% elif states.sensor.yr_symbol.state | int==35%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==36%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==37%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==38%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==39%}Titta ut!
          {% elif states.sensor.yr_symbol.state | int==40%}DrizzleSun
          {% elif states.sensor.yr_symbol.state | int==41%}Regn skurar
          {% elif states.sensor.yr_symbol.state | int==42%}LightSleetSun
          {% elif states.sensor.yr_symbol.state | int==43%}HeavySleetSun
          {% elif states.sensor.yr_symbol.state | int==44%}LightSnowSun
          {% elif states.sensor.yr_symbol.state | int==45%}HeavysnowSun
          {% elif states.sensor.yr_symbol.state | int==46%}Duggregn
          {% elif states.sensor.yr_symbol.state | int==47%}Lätt snöblandat regn
          {% elif states.sensor.yr_symbol.state | int==48%}Kraftigt snöblandat regn
          {% elif states.sensor.yr_symbol.state | int==49%}Lätt snöfall
          {% elif states.sensor.yr_symbol.state | int==50%}Kraftigt snöfall
          {% endif %}
        entity_picture_template: >-
          {% if is_state('sun.sun', 'above_horizon') %}
          //api.met.no/weatherapi/weathericon/1.1/?symbol={{states.sensor.yr_symbol.state}};is_night=0;content_type=image/png
          {% else %}
          //api.met.no/weatherapi/weathericon/1.1/?symbol={{states.sensor.yr_symbol.state}};is_night=1;content_type=image/png
          {% endif %}

There’s probably a whooole bunch of prettier and better ways to do this, but it works for me. Be wary of what sensor you’re putting in the middle of "states.sensor.NAMEOFSENSORYOUARETEMPLATINGFROM.state" since that might be different depending on what weather sensor you’re using. Use the “states” tab in developer tools to make sure the new template sensor grabs the state of the regular sensor that actually exists in your config.

I’ll think I’ll eventually look into if I can split the templates into a different file templates.yaml like with groups.yaml and so on. But for now I won’t fix it 'cause it ain’t broke :stuck_out_tongue:

2 Likes

Thanks for the help, I have translated into Norwegian.

  - platform: template
      sensors:
    yr_symbol_current:
      friendly_name: "Akkurat nĂĄ:"
      value_template: >-
        {% if states.sensor.yr_symbol.state | int==1%}Klart
        {% elif states.sensor.yr_symbol.state | int==2%}Lettskyet
        {% elif states.sensor.yr_symbol.state | int==3%}Delvis skyet
        {% elif states.sensor.yr_symbol.state | int==4%}Skyet
        {% elif states.sensor.yr_symbol.state | int==5%}Regnbyger
        {% elif states.sensor.yr_symbol.state | int==6%}Regbyger med torden
        {% elif states.sensor.yr_symbol.state | int==7%}Sluddbyger
        {% elif states.sensor.yr_symbol.state | int==8%}Snøbyger
        {% elif states.sensor.yr_symbol.state | int==9%}Regn
        {% elif states.sensor.yr_symbol.state | int==10%}Kraftig regn
        {% elif states.sensor.yr_symbol.state | int==11%}Kraftig regn og torden
        {% elif states.sensor.yr_symbol.state | int==12%}Sludd
        {% elif states.sensor.yr_symbol.state | int==13%}Snø
        {% elif states.sensor.yr_symbol.state | int==14%}Snø og torden
        {% elif states.sensor.yr_symbol.state | int==15%}TĂĄke
        {% elif states.sensor.yr_symbol.state | int==20%}Sluddbyger og torden
        {% elif states.sensor.yr_symbol.state | int==21%}Snøbyger og torden
        {% elif states.sensor.yr_symbol.state | int==22%}Regn og torden
        {% elif states.sensor.yr_symbol.state | int==23%}Sludd og torden
        {% elif states.sensor.yr_symbol.state | int==24%}Lette regbyger og torden
        {% elif states.sensor.yr_symbol.state | int==25%}Kraftige regnbyger og torden
        {% elif states.sensor.yr_symbol.state | int==26%}Lette sluddbyger og torden
        {% elif states.sensor.yr_symbol.state | int==27%}Kraftige sluddbyger og torden
        {% elif states.sensor.yr_symbol.state | int==28%}Lette snøbyger og torden
        {% elif states.sensor.yr_symbol.state | int==29%}Kraftige snøbyger og torden
        {% elif states.sensor.yr_symbol.state | int==30%}Lett regn og torden
        {% elif states.sensor.yr_symbol.state | int==31%}Lettt sludd og torden
        {% elif states.sensor.yr_symbol.state | int==32%}Kraftig sludd og torden
        {% elif states.sensor.yr_symbol.state | int==33%}Lett snø og torden
        {% elif states.sensor.yr_symbol.state | int==34%}Kraftig snø og torden
        {% elif states.sensor.yr_symbol.state | int==40%}Lette regnbyger
        {% elif states.sensor.yr_symbol.state | int==41%}Kraftige regnbyger
        {% elif states.sensor.yr_symbol.state | int==42%}Lette sluddbyger
        {% elif states.sensor.yr_symbol.state | int==43%}Kraftige sluddbyger
        {% elif states.sensor.yr_symbol.state | int==44%}Lette snøbyger
        {% elif states.sensor.yr_symbol.state | int==45%}Kraftige snøbyger
        {% elif states.sensor.yr_symbol.state | int==46%}Lett regn
        {% elif states.sensor.yr_symbol.state | int==47%}Lett sludd
        {% elif states.sensor.yr_symbol.state | int==48%}Kraftig sludd
        {% elif states.sensor.yr_symbol.state | int==49%}Lett snø
        {% elif states.sensor.yr_symbol.state | int==50%}Kraftig snø
        {% endif %}
      entity_picture_template: >-
        {% if is_state('sun.sun', 'above_horizon') %}
        //api.met.no/weatherapi/weathericon/1.1/?symbol={{states.sensor.yr_symbol.state}};is_night=0;content_type=image/png
        {% else %}
        //api.met.no/weatherapi/weathericon/1.1/?symbol={{states.sensor.yr_symbol.state}};is_night=1;content_type=image/png
        {% endif %}
2 Likes

Im trying to use your solution, i can get the correct symbol but the state is not assigned :S I get “Just nu: Okänd”.
I know I’m a bit late, but do you know if something has changed since this was posted?

What sensor are you trying to display in the front end?
I pulled my hair at this for a while too, before realising that the whole template thing makes a new sensor which displays the translated values, while leaving the old sensor.yr_symbol alone.

So basically, make sure that you’re trying to display sensor.yr_symbol_current in your frontend and it should show the correct stuff.

Hi,

I’m trying to incorporate the weather data received from Weather API provided by api.met.no.

I’ m having issue with finding the correct icon to show as the received XML has tag symbol with id and number attribute however I’m unable to understand which icon to display for night/polar icon how to judge it.

Please help.