GuyKh / ims-custom-component

The Israel Meteorological Service (IMS) integration component for home assistant
MIT License
43 stars 8 forks source link

Wrong forecast values #60

Closed KotBayun69 closed 9 months ago

KotBayun69 commented 1 year ago

I believe the new get_forecast service reports forecast shifted to one day to the past in Your integration. I mean the first day in the forecast should be today, but actually it is for yesterday.

I accidentally noticed it when called the service from developers tools in Home Assistant. Returned forecast has first entry dated day before at T21:00:00+00:00 , but probably should be at midnight on the current day. It make sense because Israeli local time is UTC+3.

My guess you are using local time when calling the service, but the service is using UTC

KotBayun69 commented 1 year ago

Called the service for hourly forecast and get also forecast for two past hours. E.g current time is 18:15 so first forecast should be for 18:00 but got for 16:00 and 17:00

GuyKh commented 1 year ago

So, not exactly. The results value of get_forecast is just what the api returns (e.g. https://ims.gov.il/he/full_forecast_data/2)

You may have some point that I should filter only the current/future values

KotBayun69 commented 1 year ago

You may have some point that I should filter only the current/future values

So, the actual problem is at API side. Not a surprise we usually get rain forecast for sunny day :)

chepa92 commented 9 months ago

Now via API I've got rain only, and I see rain only in 2 days... API probably not broken

GuyKh commented 9 months ago

@chepa92 - can you elaborate? Is there anything in the logs?

This is what I see: image image

I saw:

2024-01-29 12:54:41.152 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up ims platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 360, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/ims/sensor.py", line 283, in async_setup_entry
    for condition in conditions:
TypeError: 'NoneType' object is not iterable
chepa92 commented 9 months ago

I found a problem, if I select English language, I've got data back 2 days and HA thinks today is -2 days, if select Hebrew everything good.

chepa92 commented 9 months ago

image image as weather I don't see rain and if I use sensors I see rain.. so problem yes exists

GuyKh commented 9 months ago

@chepa92 - I think you can write in Hebrew since I can't understand the problem?

chepa92 commented 9 months ago
  1. as "weather.ims_weather" - no rain
  2. as "sensor.ims_forecast_today" - there is rain
GuyKh commented 9 months ago

@chepa92 - I think I found what you're describing: Data from IMS comes in weather codes - This is the weather_code table (code to description)

Here is the translation from code to:

  1. State (used in Weather entity)
  2. Weather Icon (used in Sensor)

Note that there's some discrepency, e.g. code 1530 is ATTR_CONDITION_PARTLYCLOUDY (HomeAssistant "Partly Cloudy") but also is with icon mdi:weather-partly-rainy.

This is the mix-up, I think - as there's an inherent mismatch between Home Assistant conditions (list here) and MDI (here)

If you want to suggest some different mappings, please do.

For reference -- what @chepa92 described can be seen here:

(Template:)
Weather: {{ states("weather.ims") }}
Sensor: {{ state_attr('sensor.ims_forecast_today', '16:00').weather.value }}

Results in:
Weather: partlycloudy
Sensor: Cloudy, possible rain

More over - the code to description is coming from here

chepa92 commented 9 months ago

image @GuyKh yeap, this is probably a problem, on their site they have 2 icons with 1 drop and 3 drops (weather-rainy, weather-partly-rainy) so yes probably mismatch, I think weather code 1540, 1530 should be a rain with 1 drop

GuyKh commented 9 months ago

@chepa92 the issue is with MDI icons, I can't find any "3 drop" one which suits

chepa92 commented 9 months ago

@GuyKh I think statuses 1540 and 1530 should be weather-partly-rainy icon (official IMS icons have 3 drops not MDI icons, 1 drop is for statuses 1540 and 1530)

GuyKh commented 9 months ago

As you can see here - this is already the case.

chepa92 commented 9 months ago

image but why day is sunny, and hourly is rain?

GuyKh commented 9 months ago

Let's make sure you understand how this works. The py package / component calls IMS every period of time to a single endpoing: https://ims.gov.il/he/city_portal/2 - (language: he and city: 2 = Tel Aviv).

There it gets 3 types of data. Under analysis field - is the current weather = no forecast. under forecast_data - you get two types of forecasts:

chepa92 commented 9 months ago

@GuyKh so Weather: {{ states("weather.ims_weather") }} should give me real time data? And not today forecast?

GuyKh commented 9 months ago

It should give the analysis value, not forecast

chepa92 commented 9 months ago

And analysis:"weather_code":null.... I just thinking that weather.ims_weather should return weather right now or forecast for today otherwise data is not relevant to show on any dashboard

GuyKh commented 9 months ago

@chepa92 This - is how the WeatherEntity condition is being calculated - some fallback flow there too

chepa92 commented 9 months ago

image image image @GuyKh Everything says it's rainy today, but WeatherEntity still telling it's cloudy, sorry, I don't know how debug this component

GuyKh commented 9 months ago

Checked again with city = 7 (Netanya): Everything says "Rainy" ![Uploading image.png…]()

chepa92 commented 9 months ago

image Both of my HA instances don't see any rain :(

GuyKh commented 9 months ago

@chepa92 - are you talking about city 7 (Netanya)?

chepa92 commented 9 months ago

@GuyKh yes

GuyKh commented 9 months ago

@chepa92 - The only thing I can think of is that this is a sync issue - Can you try to: A) Restart HomeAssistant and see if this changes? B) Remove the integration, restart and re-add it again and see if this changes?

eyarz commented 9 months ago

@GuyKh same issue here after I tried to restart HA and re-install integration. according to HA forecast it is partlycloudy all week when it should also be raining (city code: 20)...

HA image

IMS image

GuyKh commented 9 months ago

Ok, so, once again - @eyarz and @chepa92 Please don't compare the icons in IMS site and the icons in the integration, that's two systems which implement "weather_code - to - icon" individually.

I'm looking at city = 20 = Ramla. Looking at the data that IMS exposes: https://ims.gov.il/en/city_portal/20

https://ims.gov.il/en/city_portal/20
                   ^^^           ^^^
                Language    CityCode

I'm getting in Json:

// Current Weather
data.analysis.weather_code = 1540

// Hourly Forecast
data.forecast_data.hourly."11:00".weather_code = 1540

Looking at the mapping I mentioned above - 1540 is translated to: mdi:weather-partly-rainy (see here)

In the sensor description (sensor.ims_today) - I'm seeing:

11:00: 
weather:
  value: Cloudy, possible rain
  icon: mdi:weather-partly-rainy
temperature:
  value: 15.3
  unit: °C

About WeatherSensor. You can see here - that 1540 is translated to HomeAssistant condition ATTR_CONDITION_PARTLYCLOUDY - This is all the variants in HomeAssistant conditions.

Looking at the IMS weather_code description - when checking 1540:

{
"id": "14",
"desc_en": "Cloudy, possible rain",
"weather_code": "1540",
"ims_order": "14",
"night": "0",
"display": "1",
"desc": "Cloudy, possible rain"
},

So "Cloudy, possible rain" - could be translated to a different condition - but that's a whole different discussion than the saying "Wrong Data" - you're putting on here. Also - as you can see in the SensorDescription "Cloudy, Possible Rain" is there

eyarz commented 9 months ago

thank you for the detailed answer! so basically I should ignore the icons at weather.ims_weather because they are not translated correctly. Is there a recommended way to create a card that can show me a weather forecast correctly?

GuyKh commented 9 months ago

@eyarz I actually suggest you to do the opposite and suggest a fix, i.e. What mapping should we correct?

GuyKh commented 9 months ago

@eyarz @chepa92 - I've done some changes in the icon mapping. Can you update to 0.1.24 and give it a try?

eyarz commented 9 months ago

Wow, that was a quick fix! I updated to version 0.1.24 and the icons looks the same as the IMS forecast 🤩