DavidFW1960 / bom_forecast

BOM Australian Weather Forecast via FTP
17 stars 17 forks source link

JSON API for weather #5

Closed dmitryos closed 4 years ago

dmitryos commented 4 years ago

Hi David, Recently found a bit more reliable way for myself to track the weather. https://weather.bom.gov.au/location/r659gg5-gosford. It has json API behind and I think easier to parse data. This is just in case you missed that site (for me I found it accidentally and haven't heard before). Thank you for your plugin anyway!!! Dmitry

DavidFW1960 commented 4 years ago

Thanks for that info... How do you download the data? There doesn't seem to be any details on that there....

dmitryos commented 4 years ago

I just used the network tab to see what is behind the scene:

image

It works with GET too.

DavidFW1960 commented 4 years ago

ok.. so how are you then reading that into HA to create sensors?.... oh just regular rest sensors?

dmitryos commented 4 years ago

Sorry, mate. I just installed HA last week and was trying to it setup up.. Stuck with UI card for BOM from you (need time to understand how HA can be configured with js). This is why I came to this Weather page to have it loaded in iframe for the moment. And found it is a bit easier to parse than FTP data where you can get data only for the big cities and towns but here looks like one can have for any location and API will combine data for us from different XML files (I mean how it is done on FTP server).

So, I cannot answer you at the moment about the sensors - still learning curve for me all the connections inside HA and how to config them.

Plus... I'm C# guy.. Looking a bit also at the NetDaemon in case I need to develop something. Sorry :)

DavidFW1960 commented 4 years ago

Interested in your progress. I think the api is missing some of the FTP information and the observations are handled by an inbuilt BOM integration in HA. The API seems to provide extra info though..

Interesting.. seems to perhaps be more data. I see 4 pages of data https://api.weather.bom.gov.au/v1/locations/r659gg5 - general site info https://api.weather.bom.gov.au/v1/locations/r659gg/warnings - weather warnings for district https://api.weather.bom.gov.au/v1/locations/r659gg/forecasts/daily forecast info for 7 days https://api.weather.bom.gov.au/v1/locations/r659gg/forecasts/3-hourly 3 hourly forecasts..

You could use rest sensors to read all that in if you wanted to and then the card in a different repo to display the data image Good find!

dmitryos commented 4 years ago

There are another ones: https://api.weather.bom.gov.au/v1/locations/r659gg/observations - has also general current info https://api.weather.bom.gov.au/v1/locations/r659gg/forecast/rain - rain status? :)

Every time when I see your card I envy you :) I see all the data from your FTP, I was able to add the card js to the page but the card is empty :) And this time you made me jealous than usual that I found the reason YAY (or at least where to look at):

TypeError: Cannot read property 'state' of undefined at HTMLElement.get current [as current] (bom-weather-card.js:415) at HTMLElement.render (bom-weather-card.js:26) at HTMLElement.update (app.664a8247.js:1) at HTMLElement.performUpdate (app.664a8247.js:1) at HTMLElement._enqueueUpdate (app.664a8247.js:1)

Will check it out later today...

DavidFW1960 commented 4 years ago

The FTP component only gets forecast data. T he inbuilt BOM sensor gets the observations. My card here https://github.com/DavidFW1960/bom-weather-card takes data from both sensors to show the above card. The card needs to be 'installed in Lovelace along with the icons. Icons manually but you can use HACS to install the FTP and the card. If you don't parse through the required entities the card won't be displayed at all. Checkout the readme for the card to see how to set it up and configure it. Its reasonably straight forward. (easy for me to say lol but most people manage)

dmitryos commented 4 years ago

Yay, Finally!!!

image

The reason for my problems were that I "knew what I was doing" (from the very first run of the app :) ) and I combined data from bom sensor for my local town and your plug-in from Melborne (as I didn't have my town in the list of the big names). So the names of the entities I had to provide for the js card were completely mix of two different names of the town in the middle. Anyway - Thank you for your help!!!! The first step is done for me now :)

DavidFW1960 commented 4 years ago

See NaN for todays low? Did you add the template sensor for that? BOM doesn't report the low or high for today once the value has been reached.. Interested in how you are parsing the data from the api into HA.. Can you share the code?

dmitryos commented 4 years ago

It looks like I don't have proper attributes in the sensor:

image

image

cannot find where to take min and max temperature....

dmitryos commented 4 years ago

I fixed it temporarily:

  bom_today_max:
    entity_id:
      - sensor.bom_melbourne_max_temp_c_0
      - sensor.bom_mentone_air_temp_c
    value_template: >
      {%- if states('sensor.bom_melbourne_max_temp_c_0') == 'n/a' -%} 
        {{ states('sensor.bom_mentone_air_temp_c') }}
      {% else %}
        {{ states('sensor.bom_melbourne_max_temp_c_0') }}
      {% endif %}
  bom_today_min:
    entity_id:
      - sensor.bom_melbourne_min_temp_c_0
      - sensor.bom_mentone_air_temp_c
    value_template: >
      {%- if states('sensor.bom_melbourne_min_temp_c_0') == 'n/a' -%} 
        {{ states('sensor.bom_mentone_air_temp_c') }}
      {% else %}
        {{ states('sensor.bom_melbourne_min_temp_c_0') }}
      {% endif %}

but this is just to substitute with the current values. Not the real max and min...

DavidFW1960 commented 4 years ago

It is a substitute of course but like I said, BOM does not report them after the min/max has 'passed' Typically ~4am for min and 3pm for max. If you look in the weather card repo I have template sensors that use the statistics sensor to report the minimum/maximum for the last 24hrs. If you want it more accurate, my personal repo config in the weather package you will see I use a custom component called average that reports the min/max since midnight when the forecast value changes to N/A

dmitryos commented 4 years ago

Just in case: found this project: https://github.com/chris-horner/SocketWeather

You were right about the rest component. Tried on couple of values and it worked perfectly. Might change couple of values from Melbourne to my town for better figures.

BTW. Wondering if you thought about to to change the labels for min and max after ~3pm like BOM site does and show min of today and tomorrow's max?

DavidFW1960 commented 4 years ago

min of today and tomorrow's max?

well tomorrows max/min are shown already.. The average/statistics sensor correctly shows todays min and max (if you use average anyway)

https://github.com/chris-horner/SocketWeather

I remember pocket weather. Nice project.

dmitryos commented 4 years ago

Thank you for the average suggestion. I'll do it that way then. I think we can closer the issue now :) Really appreciate for help!!

DavidFW1960 commented 4 years ago

see https://github.com/DavidFW1960/home-assistant/blob/master/packages/weather.yaml line 286 for my actual config for the average.. I seem to have a mix of the statistics and average sensor in there. The Average one is a custom component and is better than stats but I didn't include that in the package so people could just use core stuff.

parse through this to the card:

            entity_daytime_high: sensor.bom_today_max_average
            entity_daytime_low: sensor.bom_today_min_average
dmitryos commented 4 years ago

oh!!! that is a separate component: average!!! When initially I copied your config I didn't know that was a separate component and didn't add this platform to yaml. Of course because of that the js card showed NaN after 3pm!! I added it now and everything starts working! Again, look! Really appreciate your help - it gave me understanding about the connection of yaml, components and js. At least now I have a better picture of the configuration of the application!!!

On Wed, Aug 19, 2020 at 1:40 PM DavidFW1960 notifications@github.com wrote:

see https://github.com/DavidFW1960/home-assistant/blob/master/packages/weather.yaml line 286 for my actual config for the average.. I seem to have a mix of the statistics and average sensor in there. The Average one is a custom component and is better than stats but I didn't include that in the package so people could just use core stuff.

parse through this to the card:

        entity_daytime_high: sensor.bom_today_max_average
        entity_daytime_low: sensor.bom_today_min_average

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DavidFW1960/bom_forecast/issues/5#issuecomment-675833399, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOWW65DOW5UJTVAQGN54KLSBNCS5ANCNFSM4QCIFEUA .

bremor commented 4 years ago

Very cool. Looks like an unofficial internal API for their new(ish) weather platform, with even more granular information. For the purposes of rebuilding the bom core component I will stick with the well documented FTP offering (even though it's a bit crap)

DavidFW1960 commented 4 years ago

Fair enough.