jdejaegh / irm-kmi-ha

Home Assistant weather provider using data from Belgian IRM KMI 🇧🇪 🇱🇺 🇳🇱
MIT License
40 stars 0 forks source link

Problem pasing daily forecast #49

Closed Woutch closed 2 months ago

Woutch commented 2 months ago

Describe the bug Daily forecast using the script bellow returns puts a long string in the entity, hourly is getting processed correctly

Script

#weather forcast daily sensor 
- trigger:
    - platform: time_pattern
      minutes: 55

    - platform: homeassistant
      event: start
  action:
    - service: weather.get_forecasts
      data:
        type: daily
      target:
        entity_id: weather.home
      response_variable: daily

  sensor:
    - name: Weather Daily
      state: "{{ states('weather.home') }}"
      attributes:
        temperature: "{{ state_attr('weather.home', 'temperature') }}"
        dew_point: "{{ state_attr('weather.home', 'dew_point') }}"
        temperature_unit: "{{ state_attr('weather.home', 'temperature_unit') }}"
        humidity: "{{ state_attr('weather.home', 'humidity') }}"
        cloud_coverage: "{{ state_attr('weather.home', 'cloud_coverage') }}"
        pressure: "{{ state_attr('weather.home', 'pressure') }}"
        pressure_unit: "{{ state_attr('weather.home', 'pressure_unit') }}"
        wind_bearing: "{{ state_attr('weather.home', 'wind_bearing') }}"
        wind_speed: "{{ state_attr('weather.home', 'wind_speed') }}"
        wind_speed_unit: "{{ state_attr('weather.home', 'wind_speed_unit') }}"
        visibility_unit: "{{ state_attr('weather.home', 'visibility_unit') }}"
        precipitation_unit: "{{ state_attr('weather.home', 'precipitation_unit') }}"
        forecast: "{{ daily['weather.home'].forecast }}"

I have practcally the same script for hourly. T problem lies with the last line: forecast: "{{ daily['weather.home'].forecast }}"

Working hourly: {{ state_attr('sensor.weather_hourly','forecast') }} Output is a array: image

Not working Daily: {{ state_attr('sensor.weather_daily','forecast') }} Ouptus is a string: image

So the following template "{{ state_attr('sensor.weather_daily','forecast')[3]}}" returns the 4th char: d, and not the 4th day.

So something is broken to parse the json into an array I guess? Maybe the single quotes in forecast text? like 's morgens?

Version

Love the integration by the way ;-)

Thanks Wouter

jdejaegh commented 2 months ago

Thanks for the feedback! I did not reproduce the bug yet, I'll try when I have some time and keep you posted.

So something is broken to parse the json into an array I guess? Maybe the single quotes in forecast text? like 's morgens?

This seems like a reasonable guess, the only differences between daily and hourly forecast are: sunset, sunrise and text. Probably one of them is not serializable to JSON as intended

Love the integration by the way ;-)

Thanks! It seems that people love to know when it is going to rain in Belgium :)

Woutch commented 2 months ago

No problem, take your time.

Let me know if I can do something. ;-)

Yes, to see when it will get sunny here is useless :-D

jdejaegh commented 2 months ago

I managed to reproduce the bug and fix it. The fix is included in 0.2.18

The problem was the time of sunset and sunrise not being serialized correctly (it was a datetime object instead of a string as expected by Home Assistant)

Woutch commented 2 months ago

Just updated here. Working perfectly again!

Many thanks!!