Eugeniusz-Gienek / kodi_weather_ha

GNU General Public License v3.0
7 stars 0 forks source link

Kodi shows an error #5

Open pephumin opened 3 weeks ago

pephumin commented 3 weeks ago
Error Type: <class 'Keyrror'>
Error Contents: 'temperature_unit'

What can I do to fix such error?

Eugeniusz-Gienek commented 3 weeks ago

It means that the response from HA doesn't cobtain "temperature unit". Please verify the correctness of the HA configuration

pephumin commented 2 weeks ago

thank you for your answer. So I tried adding in the missing 'temperature_unit' to my HA config. And now the sensor.dailyweather shows. its state as 'partlycloudy' with lots off attributes as follows:

day0_date: 2024-08-25T05:00:00+00:00 day0_condition: rainy day0_wind_bearing: 357 day0_wind_speed: 16.85 day0_precipitation: 9.45 day0_humidity: 63 day0_temperature: 31.6 day0_temperature_low: 24 day1_date: 2024-08-26T05:00:00+00:00 day1_condition: rainy day1_wind_bearing: 186 day1_wind_speed: 18.36 day1_precipitation: 3.86 day1_humidity: 55 day1_temperature: 33.8 day1_temperature_low: 26.5 day2_date: 2024-08-27T05:00:00+00:00 day2_condition: rainy day2_wind_bearing: 191 day2_wind_speed: 19.4 day2_precipitation: 9.23 day2_humidity: 59 day2_temperature: 32.1 day2_temperature_low: 26.2 day3_date: 2024-08-28T05:00:00+00:00 day3_condition: rainy day3_wind_bearing: 173 day3_wind_speed: 18.22 day3_precipitation: 6.01 day3_humidity: 61 day3_temperature: 31.8 day3_temperature_low: 26.8 day4_date: 2024-08-29T05:00:00+00:00 day4_condition: rainy day4_wind_bearing: 186 day4_wind_speed: 16.63 day4_precipitation: 7.01 day4_humidity: 54 day4_temperature: 33.2 day4_temperature_low: 27.4 day5_date: 2024-08-30T05:00:00+00:00 day5_condition: rainy day5_wind_bearing: 241 day5_wind_speed: 22.21 day5_precipitation: 8.25 day5_humidity: 63 day5_temperature: 30.7 day5_temperature_low: 26.5 days_num: 6 temperature_unit: °C friendly_name: DailyWeather

But Kodi still shows the same error - any suggestions?

Eugeniusz-Gienek commented 2 weeks ago

Looks good for me. Perhaps there is some mistake in the response itself - e.g. it may be encompassed in an array for example

Eugeniusz-Gienek commented 2 weeks ago

Can You please share the config yaml - relevant part?

pephumin commented 2 weeks ago

Sure,. I already use the package function of HA so I created a file called forecast.yaml and placed in the folder as /config/packages/forecasts.yaml. And its contents are shown below.


template: 

  - trigger:
      - platform: event 
        event_type: homeassistant_started
      - platform: event
        event_type:
          - automation_reloaded
          - scene_reloaded
      - platform: time_pattern
        minutes: /15 

    action:
      - service: weather.get_forecasts
        target:
          entity_id: weather.openweathermap 
        data:
          type: hourly
        response_variable: hourly
      - service: weather.get_forecasts 
        target:
          entity_id: weather.openweathermap
        data:
          type: daily
        response_variable: daily

    sensor:

      - name: "DailyWeather"
        state: "{{ states('weather.openweathermap') }}"
        unique_id: weather_daily_all_in_one
        attributes:
          day0_date: "{{ daily['weather.openweathermap'].forecast[0].datetime }}"
          day0_condition: "{{ daily['weather.openweathermap'].forecast[0].condition }}"
          day0_wind_bearing: "{{ daily['weather.openweathermap'].forecast[0].wind_bearing }}"
          day0_wind_speed: "{{ daily['weather.openweathermap'].forecast[0].wind_speed }}"
          day0_precipitation: "{{ daily['weather.openweathermap'].forecast[0].precipitation }}"
          day0_humidity: "{{ daily['weather.openweathermap'].forecast[0].humidity }}"
          day0_temperature: "{{ daily['weather.openweathermap'].forecast[0].temperature }}"
          day0_temperature_low: "{{ daily['weather.openweathermap'].forecast[0].templow }}"
          day1_date: "{{ daily['weather.openweathermap'].forecast[1].datetime }}"
          day1_condition: "{{ daily['weather.openweathermap'].forecast[1].condition }}"
          day1_wind_bearing: "{{ daily['weather.openweathermap'].forecast[1].wind_bearing }}"
          day1_wind_speed: "{{ daily['weather.openweathermap'].forecast[1].wind_speed }}"
          day1_precipitation: "{{ daily['weather.openweathermap'].forecast[1].precipitation }}"
          day1_humidity: "{{ daily['weather.openweathermap'].forecast[1].humidity }}"
          day1_temperature: "{{ daily['weather.openweathermap'].forecast[1].temperature }}"
          day1_temperature_low: "{{ daily['weather.openweathermap'].forecast[1].templow }}"
          day2_date: "{{ daily['weather.openweathermap'].forecast[2].datetime }}"
          day2_condition: "{{ daily['weather.openweathermap'].forecast[2].condition }}"
          day2_wind_bearing: "{{ daily['weather.openweathermap'].forecast[2].wind_bearing }}"
          day2_wind_speed: "{{ daily['weather.openweathermap'].forecast[2].wind_speed }}"
          day2_precipitation: "{{ daily['weather.openweathermap'].forecast[2].precipitation }}"
          day2_humidity: "{{ daily['weather.openweathermap'].forecast[2].humidity }}"
          day2_temperature: "{{ daily['weather.openweathermap'].forecast[2].temperature }}"
          day2_temperature_low: "{{ daily['weather.openweathermap'].forecast[2].templow }}"
          day3_date: "{{ daily['weather.openweathermap'].forecast[3].datetime }}"
          day3_condition: "{{ daily['weather.openweathermap'].forecast[3].condition }}"
          day3_wind_bearing: "{{ daily['weather.openweathermap'].forecast[3].wind_bearing }}"
          day3_wind_speed: "{{ daily['weather.openweathermap'].forecast[3].wind_speed }}"
          day3_precipitation: "{{ daily['weather.openweathermap'].forecast[3].precipitation }}"
          day3_humidity: "{{ daily['weather.openweathermap'].forecast[3].humidity }}"
          day3_temperature: "{{ daily['weather.openweathermap'].forecast[3].temperature }}"
          day3_temperature_low: "{{ daily['weather.openweathermap'].forecast[3].templow }}"
          day4_date: "{{ daily['weather.openweathermap'].forecast[4].datetime }}"
          day4_condition: "{{ daily['weather.openweathermap'].forecast[4].condition }}"
          day4_wind_bearing: "{{ daily['weather.openweathermap'].forecast[4].wind_bearing }}"
          day4_wind_speed: "{{ daily['weather.openweathermap'].forecast[4].wind_speed }}"
          day4_precipitation: "{{ daily['weather.openweathermap'].forecast[4].precipitation }}"
          day4_humidity: "{{ daily['weather.openweathermap'].forecast[4].humidity }}"
          day4_temperature: "{{ daily['weather.openweathermap'].forecast[4].temperature }}"
          day4_temperature_low: "{{ daily['weather.openweathermap'].forecast[4].templow }}"
          day5_date: "{{ daily['weather.openweathermap'].forecast[5].datetime }}"
          day5_condition: "{{ daily['weather.openweathermap'].forecast[5].condition }}"
          day5_wind_bearing: "{{ daily['weather.openweathermap'].forecast[5].wind_bearing }}"
          day5_wind_speed: "{{ daily['weather.openweathermap'].forecast[5].wind_speed }}"
          day5_precipitation: "{{ daily['weather.openweathermap'].forecast[5].precipitation }}"
          day5_humidity: "{{ daily['weather.openweathermap'].forecast[5].humidity }}"
          day5_temperature: "{{ daily['weather.openweathermap'].forecast[5].temperature }}"
          day5_temperature_low: "{{ daily['weather.openweathermap'].forecast[5].templow }}"
          days_num: "{{ 6 }}"
          temperature_unit: "{{ state_attr('weather.openweathermap', 'temperature_unit') }}"

      - name: "HourlyWeather"
        state: "{{ states('weather.openweathermap') }}"
        unique_id: weather_hourly_all_in_one
        attributes:
          hour0_date: "{{ hourly['weather.openweathermap'].forecast[0].datetime }}"
          hour0_condition: "{{ hourly['weather.openweathermap'].forecast[0].condition }}"
          hour0_wind_bearing: "{{ hourly['weather.openweathermap'].forecast[0].wind_bearing }}"
          hour0_wind_speed: "{{ hourly['weather.openweathermap'].forecast[0].wind_speed }}"
          hour0_precipitation: "{{ hourly['weather.openweathermap'].forecast[0].precipitation }}"
          hour0_humidity: "{{ hourly['weather.openweathermap'].forecast[0].humidity }}"
          hour0_temperature: "{{ hourly['weather.openweathermap'].forecast[0].temperature }}"
          hour0_cloud_coverage: "{{ hourly['weather.openweathermap'].forecast[0].cloud_coverage }}"
          hour1_date: "{{ hourly['weather.openweathermap'].forecast[1].datetime }}"
          hour1_condition: "{{ hourly['weather.openweathermap'].forecast[1].condition }}"
          hour1_wind_bearing: "{{ hourly['weather.openweathermap'].forecast[1].wind_bearing }}"
          hour1_wind_speed: "{{ hourly['weather.openweathermap'].forecast[1].wind_speed }}"
          hour1_precipitation: "{{ hourly['weather.openweathermap'].forecast[1].precipitation }}"
          hour1_humidity: "{{ hourly['weather.openweathermap'].forecast[1].humidity }}"
          hour1_temperature: "{{ hourly['weather.openweathermap'].forecast[1].temperature }}"
          hour1_cloud_coverage: "{{ hourly['weather.openweathermap'].forecast[1].cloud_coverage }}"
          hour2_date: "{{ hourly['weather.openweathermap'].forecast[2].datetime }}"
          hour2_condition: "{{ hourly['weather.openweathermap'].forecast[2].condition }}"
          hour2_wind_bearing: "{{ hourly['weather.openweathermap'].forecast[2].wind_bearing }}"
          hour2_wind_speed: "{{ hourly['weather.openweathermap'].forecast[2].wind_speed }}"
          hour2_precipitation: "{{ hourly['weather.openweathermap'].forecast[2].precipitation }}"
          hour2_humidity: "{{ hourly['weather.openweathermap'].forecast[2].humidity }}"
          hour2_temperature: "{{ hourly['weather.openweathermap'].forecast[2].temperature }}"
          hour2_cloud_coverage: "{{ hourly['weather.openweathermap'].forecast[2].cloud_coverage }}"
          hour3_date: "{{ hourly['weather.openweathermap'].forecast[3].datetime }}"
          hour3_condition: "{{ hourly['weather.openweathermap'].forecast[3].condition }}"
          hour3_wind_bearing: "{{ hourly['weather.openweathermap'].forecast[3].wind_bearing }}"
          hour3_wind_speed: "{{ hourly['weather.openweathermap'].forecast[3].wind_speed }}"
          hour3_precipitation: "{{ hourly['weather.openweathermap'].forecast[3].precipitation }}"
          hour3_humidity: "{{ hourly['weather.openweathermap'].forecast[3].humidity }}"
          hour3_temperature: "{{ hourly['weather.openweathermap'].forecast[3].temperature }}"
          hour3_cloud_coverage: "{{ hourly['weather.openweathermap'].forecast[3].cloud_coverage }}"
          hour4_date: "{{ hourly['weather.openweathermap'].forecast[4].datetime }}"
          hour4_condition: "{{ hourly['weather.openweathermap'].forecast[4].condition }}"
          hour4_wind_bearing: "{{ hourly['weather.openweathermap'].forecast[4].wind_bearing }}"
          hour4_wind_speed: "{{ hourly['weather.openweathermap'].forecast[4].wind_speed }}"
          hour4_precipitation: "{{ hourly['weather.openweathermap'].forecast[4].precipitation }}"
          hour4_humidity: "{{ hourly['weather.openweathermap'].forecast[4].humidity }}"
          hour4_temperature: "{{ hourly['weather.openweathermap'].forecast[4].temperature }}"
          hour4_cloud_coverage: "{{ hourly['weather.openweathermap'].forecast[4].cloud_coverage }}"
          hour5_date: "{{ hourly['weather.openweathermap'].forecast[5].datetime }}"
          hour5_condition: "{{ hourly['weather.openweathermap'].forecast[5].condition }}"
          hour5_wind_bearing: "{{ hourly['weather.openweathermap'].forecast[5].wind_bearing }}"
          hour5_wind_speed: "{{ hourly['weather.openweathermap'].forecast[5].wind_speed }}"
          hour5_precipitation: "{{ hourly['weather.openweathermap'].forecast[5].precipitation }}"
          hour5_humidity: "{{ hourly['weather.openweathermap'].forecast[5].humidity }}"
          hour5_temperature: "{{ hourly['weather.openweathermap'].forecast[5].temperature }}"
          hour5_cloud_coverage: "{{ hourly['weather.openweathermap'].forecast[5].cloud_coverage }}"
          hours_num: "{{ 6 }}"
          temperature_unit: "{{ state_attr('weather.openweathermap', 'temperature_unit') }}"

      - name: "WeatherCurrent"
        unique_id: weather_state_current
        state: "{{ states('weather.openweathermap') }}"

      - name: "TempCurrent"
        unique_id: weather_temperature_current
        unit_of_measurement: '°C'
        state: >
          {{ state_attr('weather.openweathermap', 'temperature') }}

      - name: "HumidityCurrent"
        unique_id: weather_humidity_current
        unit_of_measurement: '%'
        state: >
          {{ state_attr('weather.openweathermap', 'humidity') }}

      - name: "WindSpeedCurrent"
        unique_id: weather_wind_speed_current
        unit_of_measurement: 'm/s'
        state: >
          {{ state_attr('weather.openweathermap', 'wind_speed') }}

      - name: "WindBearingCurrent"
        unique_id: weather_wind_bearing_current
        unit_of_measurement: '°'
        state: >
          {{ state_attr('weather.openweathermap', 'wind_bearing') }}

      - name: "PressureCurrent"
        unique_id: weather_pressure_current
        unit_of_measurement: 'hPa'
        state: >
          {{ state_attr('weather.openweathermap', 'pressure') }}

Please note that I manually added the temperature_unit on both DailyWeather and HourlyWeather to cope with the situation as discussed earlier.