core
core copied to clipboard
Template weather integration broken
The problem
Even with static data configured, the template weather integration has an unknown state. This seems to be the offending line.
This is a minimal configuration exhibiting the issue:
weather:
- platform: template
name: "Test"
condition_template: "sunny"
temperature_template: 23.5
temperature_unit: "°C"
humidity_template: 0.0
Log:
Apr 18 17:44:53 homeassistant hass[3446845]: 2023-04-18 17:44:53.487 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Apr 18 17:44:53 homeassistant hass[3446845]: Traceback (most recent call last):
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/template_entity.py", line 364, in _async_template_startup
Apr 18 17:44:53 homeassistant hass[3446845]: result_info.async_refresh()
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/event.py", line 953, in async_refresh
Apr 18 17:44:53 homeassistant hass[3446845]: self._refresh(None)
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/event.py", line 1133, in _refresh
Apr 18 17:44:53 homeassistant hass[3446845]: self.hass.async_run_hass_job(self._job, event, updates)
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/core.py", line 593, in async_run_hass_job
Apr 18 17:44:53 homeassistant hass[3446845]: hassjob.target(*args)
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/template_entity.py", line 333, in _handle_results
Apr 18 17:44:53 homeassistant hass[3446845]: self.async_write_ha_state()
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 568, in async_write_ha_state
Apr 18 17:44:53 homeassistant hass[3446845]: self._async_write_ha_state()
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 634, in _async_write_ha_state
Apr 18 17:44:53 homeassistant hass[3446845]: attr.update(self.state_attributes or {})
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/weather/__init__.py", line 606, in state_attributes
Apr 18 17:44:53 homeassistant hass[3446845]: data[ATTR_WEATHER_HUMIDITY] = round(humidity)
Apr 18 17:44:53 homeassistant hass[3446845]: TypeError: type str doesn't define __round__ method
Logger config:
logger:
default: warning
logs:
homeassistant.components.template.weather: debug
What version of Home Assistant Core has the issue?
core-2023.4.5
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Core
Integration causing the issue
Template Weather Provider
Link to integration documentation on our website
https://www.home-assistant.io/integrations/weather.template/
Diagnostics information
No response
Example YAML snippet
weather:
- platform: template
name: "Test"
condition_template: "sunny"
temperature_template: 23.5
temperature_unit: "°C"
humidity_template: 0.0
Anything in the logs that might be useful for us?
Apr 18 17:44:53 homeassistant hass[3446845]: 2023-04-18 17:44:53.487 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Apr 18 17:44:53 homeassistant hass[3446845]: Traceback (most recent call last):
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/template_entity.py", line 364, in _async_template_startup
Apr 18 17:44:53 homeassistant hass[3446845]: result_info.async_refresh()
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/event.py", line 953, in async_refresh
Apr 18 17:44:53 homeassistant hass[3446845]: self._refresh(None)
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/event.py", line 1133, in _refresh
Apr 18 17:44:53 homeassistant hass[3446845]: self.hass.async_run_hass_job(self._job, event, updates)
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/core.py", line 593, in async_run_hass_job
Apr 18 17:44:53 homeassistant hass[3446845]: hassjob.target(*args)
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/template_entity.py", line 333, in _handle_results
Apr 18 17:44:53 homeassistant hass[3446845]: self.async_write_ha_state()
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 568, in async_write_ha_state
Apr 18 17:44:53 homeassistant hass[3446845]: self._async_write_ha_state()
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 634, in _async_write_ha_state
Apr 18 17:44:53 homeassistant hass[3446845]: attr.update(self.state_attributes or {})
Apr 18 17:44:53 homeassistant hass[3446845]: File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/weather/__init__.py", line 606, in state_attributes
Apr 18 17:44:53 homeassistant hass[3446845]: data[ATTR_WEATHER_HUMIDITY] = round(humidity)
Apr 18 17:44:53 homeassistant hass[3446845]: TypeError: type str doesn't define __round__ method
Additional information
https://github.com/home-assistant/core/blob/dev/homeassistant/components/weather/init.py#L606
Hey there @phracturedblue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template
) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of template
can trigger bot actions by commenting:
-
@home-assistant close
Closes the issue. -
@home-assistant rename Awesome new title
Renames the issue. -
@home-assistant reopen
Reopen the issue. -
@home-assistant unassign template
Removes the current integration label and assignees on the issue, add the integration domain after the command.
(message by CodeOwnersMention)
template documentation template source (message by IssueLinks)
I don't disagree that this issue should probably be handled better by this integration (as it does for the temperature value), but a simple workaround is to define a template that casts the value to a float
:
humidity_template: "{{ states('sensor.humidity') | float }}"
Thanks for the workaround.
The one issue is that it's not handling the given configuration properly when the humidity_template
is required, but not available (as in, I don't have a value for it), and 0.0
is considered a float in Python world (I know it's a string in the config).
The bigger problem, however, is that it completely borks the integration. The rest should still work, I'd argue, with a error/warning that it doesn't understand my config for the humidity.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Still needs fixing.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
.