After changes in how the weather works in HA now, I completely dropped integration for my own set of REST sensors working with Weatherbit. Everything worked fine until update to 2024.8. After upgrade, for every sensor I created I get in log file error message (posting just example for one sensor, all looks the same):
2024-08-08 20:57:14.664 ERROR (MainThread) [homeassistant.components.sensor] Error adding entity sensor.condition_0 for domain sensor with platform rest
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
await coro
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1365, in add_to_platform_finish
await self.async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 162, in async_added_to_hass
await super().async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/components/rest/entity.py", line 43, in async_added_to_hass
self._update_from_rest_data()
File "/usr/src/homeassistant/homeassistant/components/rest/sensor.py", line 187, in _update_from_rest_data
self._process_manual_data(raw_value)
File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 250, in _process_manual_data
self._render_templates(variables)
File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 190, in _render_templates
rendered[key] = self._config[key].async_render(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 597, in async_render
compiled = self._compiled or self._ensure_compiled(limited, strict, log_fn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 798, in _ensure_compiled
assert self.hass is not None, "hass variable not set on template"
^^^^^^^^^^^^^^^^^^^^^
AssertionError: hass variable not set on template
Sensor are visible in Developer Tools → States, but only holds some old value as state, with no attributes created.
Here is the code for the sensor resulting in error above:
rest:
- resource: http://192.168.52.53:8123/local/weatherbit_forecast.json
sensor:
- name: condition_0
value_template: "{{ value_json.data[0].weather.description }}"
icon: >
{% set condition = value_json.data[0].weather.code %}
{% if condition == 200 %} mdi:weather-partly-lightning
{% elif condition == 201 %} mdi:weather-partly-lightning
{% elif condition == 202 %} mdi:weather-partly-lightning
{% elif condition == 203 %} mdi:weather-partly-lightning
{% elif condition == 230 %} mdi:weather-lightning
{% elif condition == 231 %} mdi:weather-lightning-rainy
{% elif condition == 232 %} mdi:weather-lightning-rainy
{% elif condition == 233 %} mdi:weather-lightning-rainy
{% elif condition == 300 %} mdi:weather-rainy
{% elif condition == 301 %} mdi:weather-rainy
{% elif condition == 302 %} mdi:weather-rainy
{% elif condition == 500 %} mdi:weather-pouring
{% elif condition == 501 %} mdi:weather-pouring
{% elif condition == 502 %} mdi:weather-pouring
{% elif condition == 511 %} mdi:weather-pouring
{% elif condition == 520 %} mdi:weather-pouring
{% elif condition == 521 %} mdi:weather-partly-rainy
{% elif condition == 522 %} mdi:weather-pouring
{% elif condition == 600 %} mdi:weather-partly-snowy
{% elif condition == 601 %} mdi:weather-snowy
{% elif condition == 602 %} mdi:weather-snowy-heavy
{% elif condition == 610 %} mdi:weather-partly-snowy-rainy
{% elif condition == 611 %} mdi:weather-snowy-rainy
{% elif condition == 612 %} mdi:weather-snowy-rainy
{% elif condition == 621 %} mdi:weather-partly-snowy
{% elif condition == 622 %} mdi:weather-snowy-heavy
{% elif condition == 623 %} mdi:weather-snowy
{% elif condition == 700 %} mdi:weather-hazy
{% elif condition == 711 %} mdi:weather-hazy
{% elif condition == 721 %} mdi:weather-hazy
{% elif condition == 731 %} mdi:weather-dust
{% elif condition == 741 %} mdi:weather-fog
{% elif condition == 751 %} mdi:weather-hazy
{% elif condition == 800 %} mdi:weather-sunny
{% elif condition == 801 %} mdi:weather-partly-cloudy
{% elif condition == 802 %} mdi:weather-partly-cloudy
{% elif condition == 803 %} mdi:weather-partly-cloudy
{% elif condition == 804 %} mdi:weather-cloudy
{% else %} mdi:cloud-question-outline
{% endif %}
Source (intermediate step) JSON file is created properly and contains all necessary data. Here is sample with needed nodes:
{
"city_name":"Zielonka",
"country_code":"PL",
"data":[
{
"app_max_temp":24.5,
"app_min_temp":17.5,
"clouds":46,
"clouds_hi":44,
"clouds_low":50,
"clouds_mid":35,
"datetime":"2024-08-09",
"dewpt":14.8,
"high_temp":24.7,
"low_temp":17.3,
"max_dhi":null,
"max_temp":24.7,
"min_temp":17.5,
"moon_phase":0.33,
"moon_phase_lunation":0.19,
"moonrise_ts":1723192128,
"moonset_ts":1723233117,
"ozone":322,
"popp":40,
"precip":1.8959961,
"pres":1004,
"rh":73,
"slp":1015,
"snow":0,
"snow_depth":0,
"sunrise_ts":1723172933,
"sunset_ts":1723227058,
"temp":20.4,
"ts":1723154460,
"uv":7,
"valid_date":"2024-08-09",
"vis":24,
"weather":{
"icon":"r01d",
"description":"Light rain",
"code":500
},
"wind_cdir":"W",
"wind_cdir_full":"west",
"wind_dir":276,
"wind_gust_spd":5.2,
"wind_spd":2
},
........
}
What is wrong here? Frankly speaking this error message gives me no clue what is not right…