YR weather error

For some days YR returns lots of errors in the log like this one.

[homeassistant.components.yr.sensor] Retrying in 20 minutes: https://aa015h6buqvih86i1.api.met.no/weatherapi/locationforecast/1.9/?lat=55.4370338&lon=10.3822298&msl=7 returned 404

I remember same issue last year I think. It was solved by changing one little thing in the .py file
This “!= 200:” to this “not in (200, 203):”

Someone knows what the problem is and if it can be solved this way again?

I am on HA 0.103.6

If you copy the above url into a browser it shows:

404 Not Found
The specified version number is end-of-lifed for this product

Okay, is it end of life for the yr component?

I guess it is the version 1.9 that has end of life. Can that be changed?

It’s dead and gone. The Norwegian met office started warning last June that they were planning to shut off the v1.9 api in early 2021 - that was when we had to patch it to ignore the 203 return code. Now the 404 page says it was shut off March 1, 2021.

But I rolled my own easy workaround. I wrote a short Google Sheets script running once an hour in my Google account that grabs the key weather values from a web page (Environment Canada in my case), and sends them to Node Red. Node Red then uses set_state to stuff those values into the former yr sensor fields. At first I didn’t bother replacing the yr component, just disabled pointless polling in its sensor.py file, but then I went ahead and replaced the old yr component with new template sensors of the same name.

Anyway, this gives me full control over what site I get the weather data from, and I can easily adjust the code if there are minor format changes. It looks and works the same in Home Assistant. Since I didn’t change the sensor names, I didn’t have to change any of my automations or Node Red routines either.

Let me know if you want a copy of the Google Sheets script and the Node Red code.

You could use this weather_data platform, which replaced the old yr.no platform. It has been updated to handle the latest MET.no API version. https://github.com/Danielhiversen/home_assistant_weather_data

The change done lately in the weather forcast is that the forcast has gone from number to text and where previously one could get the weather symbol from yr, these must now be stored locally.

1 Like

I actually replaced the old yr py.file with the new weather file late last night and the error was gone, but I am not sure how to use the new weathericon 2.0 service. The only thing I use from yr is actually the symbols :-/

Thanks very much for the solution but I am not using Node Red. I would rather use the new weather_data platform as described below but all the symbols also has a new way of working.

Doesn’t have to be Node Red, that’s just how I prefer to do my automations. You can use the built-in HA automations if you prefer as a way to take externally provided weather values and put them into your HA sensor (but you should check out Node Red - it’s powerful, reliable, stable, and easy to use)

I have tried the updated met.no component, but it doesn’t work with my outdated version of HA, and I can’t update because the Armbian Linux platform I am running on no longer supports recent versions of HA. I decided that if I have to go to the trouble of figuring out the Python code and altering it make it work with my older HA, I should just take the easier path of modifying an existing javascript routine to do exactly what I want, and have it totally under my control in the future. Now I can decide which weather service to use, and I don’t have to wait for somebody else to fix it when it goes wrong.

Okay sounds nice. What about the symbols, are they still possible with your solution?
I just changed a few things in my old yr .py file and it gives me values now and no error but since the symbol service also has changed these no longer show.

The announcement from the Norwegian met service about the v1.9 api shutdown also says that the old online set of icons is gone, but you can download them as a tar library. They are trying to reduce the unnecessary traffic volume downloading the same images repeatedly from their web site.

The Environment Canada “current weather” web page I am using as a source has an icon for current weather condition, which is a gif file on their server. In my code I just grab the icon number and send it to my Node Red code, which plugs it into the full url to retrieve the icon image from the Env Canada web site and then uses set_state entity_picture to insert that into the badge image. Really I should be sending the full url to Node Red to make the code more generic, but this was the easier shortcut. There’s a separate text condition like “Mostly cloudy”, so you don’t have to deal with condition numbers.

This is what the Google Script (javascript) routine looks like for the Environment Canada weather page. Modify as necessary for any other weather page by saving the html source and checking the format for where the key elements are located that you need to pick out.

function getCurrWeather() { 

  /* Get current 7-day forecast web page from Environment Canada for Toronto */
  var response = UrlFetchApp.fetch('https://weather.gc.ca/city/pages/on-143_metric_e.html');
  var pagecontent = String(response);
  
  /* Find the weather parameters in the html response string. The format looks like this:

  <dt>Temperature:</dt>
  <dd class=3D"mrgn-bttm-0 wxo-metric-hide">7.1<

  so we will search for the keyword, skip two right angle brackets, then look for the terminating left angle bracket
  */

  /* Find the current condition text in the response string, something like "Mostly cloudy" */
  var n = pagecontent.indexOf('Condition:');
  n = pagecontent.indexOf('>', n+12);
  n = pagecontent.indexOf('>', n+1);
  var n1 = pagecontent.indexOf('<', n+1);
  var curcond = pagecontent.substr(n+1, n1-n-1);
  /* Logger.log(curcond); */

  /* Find the temperature in deg in the response string */
  var n = pagecontent.indexOf('Temperature:', n+70);
  n = pagecontent.indexOf('>', n+12);
  n = pagecontent.indexOf('>', n+1);
  var n1 = pagecontent.indexOf('<', n+1);
  var curtemp = pagecontent.substr(n+1, n1-n-2);
  /* Logger.log(curtemp); */

  /* Find the pressure in kPa in the response string */
  var n = pagecontent.indexOf('Pressure:', n+70);
  n = pagecontent.indexOf('>', n+12);
  n = pagecontent.indexOf('>', n+1);
  var n1 = pagecontent.indexOf('<', n+1);
  var pkpa = pagecontent.substr(n+1, n1-n-2);
  /* convert to hPa / millibars */
  var curpressure = String(pkpa * 10);
  /* Logger.log(curpressure); */

  /* Find the icon number in the response string (full url is present, but only need icon number */
  var n = pagecontent.indexOf('weathericons/', n+70);
  n = n+12;
  var n1 = pagecontent.indexOf('.', n+1); /* .gif is the terminator 8?
  var curicon = pagecontent.substr(n+1, n1-n-1);
  /* Logger.log(curicon); */

  /* Use http Get with /? parameters to pass values to Node Red on home system */
  var actionurl = 'http://myhomeid.noip.me:1880/weatherep/?temp=' + curtemp + '&press=' + curpressure + '&cond=' + curcond + '&icon=' + curicon
  /* Logger.log(actionurl); */

  var response = UrlFetchApp.fetch(actionurl);
  /* No need to check the response, don't care

}

You go to https://www.google.com/script/start/, log into your account, create a “Project”, create a new script within that Project, and paste in the above code. Select the Run command to test that the script is working. Then you go to Triggers, select Time trigger, and set the script to once per hour (or whatever interval you want). Google scripts are free, as long as you don’t exceed a reasonable run time per day - no danger here.

On the Home Assistant side, the final fetch command in the above script sends the weather parameters to a Node Red flow beginning with a web trigger named “weatherep”. If you instead want to send it to a Home Assistant automation, you have to create an webhook-triggered automation named something similar, and use POST format for the fetch command (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch for how to structure POST).

On the Node Red side, to set the temperature (for example), I use a Call Service node, domain python_script, service set_state, entity_id sensor.yr_temperature, data {“state”:"{{payload.temp}}",“attribution”:“Environment Canada”}. You can experiment with the set_state service in the Home Assistant interface if you want.

For the icon, it’s: entity_id sensor.yr.symbol and data {“entity_picture”:“http://weather.gc.ca/weathericons/{{payload.icon}}.gif”,“attribution”:“Environment Canada”}

If you want to replace the old yr sensor with new template sensors of the same name, it’s:

  - platform: template
    sensors:
      yr_temperature:
        friendly_name: "Temperature"
        unit_of_measurement: "°C"
        value_template: "-"
      yr_pressure:
        friendly_name: "Pressure"
        unit_of_measurement: "hPa"
        value_template: "-"
      yr_symbol:
        friendly_name: "Weather"
        value_template: "unknown"

I don´t know much about the google scripting but I will have a look at it. Thanks :slight_smile:
Anyway I would believe that using the new weatherservice 2.0 and the downloaded symbols in the sensor.py file should also be possible somehow

Definitely try the new met.no service to see if it works for you - it’s probably the simplest fix.

It doesn’t work for me, and I just figured that it would be easier to adapt my own simple Google script to do the job rather than spend the effort messing around with someone else’s Python code.

I will give it a few tries with the sensor.py or else I will have another look at your script :slight_smile: Thanks