User-agent for met.no not working

Hi I want to identify myself in the user-agent for a resource:
Is this correct? It does not seem to work.
I am on an older version of HA.

  - platform: rest
    name: Home
    resource: https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=xx.4370338&lon=xx.3822298
    scan_interval: 3600
    headers:
      User-Agent: Home Assistant MY EMAIL ADDRESS
      Content-Type: application/json
    value_template: "OK"

Why do you need the user-agent? This URL works without too
EDIT and you may want to use lat/lon that are not your address (if these are indeed your address )

EDIT, checked the API and I now understand, it requires a unique identifier, likely to block when too many requests come in, this works for me (obfuscated a few things). Based on the output, you would likely need a bit more fiddling with jq or templates to get usefull data in HA

    - platform: rest
      name: Met_No
      resource: https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=xx.4370338&lon=yy.3822298
      headers:
        User-Agent: "[email protected]"
        Content-Type: "application/json"
      scan_interval: 3600
      value_template: "{{ value_json.type }}"

Location is now hidden thanks :slight_smile:

There was a change in the API yes with the need of the user-agent.

Unfortunatly it still does not show any data. I use the old YR platform and that showed data until the change in the API.
How to make it work now I don´t know.

I get this error in the logs.


[homeassistant.components.yr.sensor] Retrying in 15 minutes: https://api.met.no/weatherapi/locationforecast/2.0/classic?lat=55.4370338&lon=10.3822298&altitude=7 returned 403

If you use the REST as per your initial post then logically this does not show anything. If your user-agent is accepted the best thing it will show is state ‘OK’
You have to specificy a path as for example I did for value_json.type
Do spend some time in reading the documentation
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwiCxJv1zeiIAxW2SaQEHaUxGqYQFnoECCQQAQ&url=https%3A%2F%2Fwww.home-assistant.io%2Fintegrations%2Frest%2F&usg=AOvVaw0FVAn8YKdSwgG1BSnImLn7&opi=89978449

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwiCxJv1zeiIAxW2SaQEHaUxGqYQFnoECB8QAQ&url=https%3A%2F%2Fwww.home-assistant.io%2Fintegrations%2Fsensor.rest%2F&usg=AOvVaw3ucHKDgce4P9SknfqPklkM&opi=89978449

EDIT: and why do you need this approach if there is already an existing integration with met.no ? For me/others it is easier to support if you ask direct questions, vagueness will continue to lead in vague answers or no answers at all

Okay I will try to be more specific.
It actaully shows “OK” and “Feature” with the “value_json.type”
I used the YR platform before the change in API and it showed values fine.
I guess it should fetch the data.

  - platform: yr
    forecast: 2
    monitored_conditions:
      - symbol
      - windSpeed

I have not changed anything. I just read that due to the changes I had to use the user-agent to identify myself.

The met.no integration in the HA version I use is too old. I am on version 0.103.6 (I know I know :wink:)

OK, I was not aware of yr platform’s existance till now. Integrations are built based on the json/response but not sure how it would map to your own pulled json.

EDIT: there is already a workaround I see
Danielhiversen/home_assistant_weather_data: Weather sensor (Replaces the old yr.no sensor) (github.com)

Thanks. I will try it out hopefully tomorrow and let you know.

I tried placing the newest but also older releases into my custom components folder but HA will not start up afterwards.

Can’t help you as abroad … but also afterwards, I donot know yr platform nor this workaround…was just searching for it.
From a HACS pov, I have not yet seen one that brings down HA so check logs a.o.

The log file is not updated when HA won´t restart.
I will try out different things but I had honestly hoped that using the user-agent was enough to solve the problem.

The rest sensor you showed in the first post is just-that, it does not do a thing more than to download the json from the url provided and trat the content along the value_template you used. The yr platform (whatever it does) has no idea of a local json or rest sensor unless there is a way to connect these 2, which I doubt it does.
You seem to have no choice but to use the workaround and get that working

I will try to make the custom component work.
If I succeed I will let you know.

Thanks for helping!! :slight_smile: