Just updated to 2022.7.2 from 2022.6.x. My template fan broke.
I get these error messages in the log:
Logger: homeassistant.components.template.fan
Source: components/template/fan.py:433
Integration: Template (documentation, issues)
First occurred: 12:28:10 (3 occurrences)
Last logged: 12:39:03
Received invalid preset_mode: None for entity fan.mechanische_ventilatie. Expected: Non
&
Logger: homeassistant.helpers.event
Source: components/template/fan.py:398
First occurred: 12:37:53 (2 occurrences)
Last logged: 12:39:03
Error while processing state change for sensor.mechanische_ventilatie_status
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 282, in _async_state_change_dispatcher
hass.async_run_hass_job(job, event)
File "/usr/src/homeassistant/homeassistant/core.py", line 546, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1109, in _refresh
self.hass.async_run_hass_job(self._job, event, updates)
File "/usr/src/homeassistant/homeassistant/core.py", line 546, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 321, in _handle_results
attr.handle_result(
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 126, in handle_result
self.on_update(result)
File "/usr/src/homeassistant/homeassistant/components/template/fan.py", line 398, in _update_percentage
percentage = int(float(percentage))
TypeError: float() argument must be a string or a real number, not 'NoneType'
I believe there were some updates regarding invalid/unavailable states etc in recent releases. But honestly I don’t know where to start looking.
So, you have two separate error messages - one regarding updating preset_mode and the other one regarding percentage.
In your template fan configuration I can see that both are determined from sensor sensor.mechanische_ventilatie_status, so that’s where I would assume that something goes wrong. Does that sensor have those two attributes and do they have valid values?
It has been working fine for at least a year. It broke with the update to 2022.7. So it should be something in Hass. Have there been some breaking changes in REST or in sensor (apart from mqtt)?
You haven’t shared the configuration of that sensor sensor.mechanische_ventilatie_status so I cannot tell you if a change in 2022.7 may have changes its behaviour - that’s why I pointed that one out in particular, and you should look for breaking changes in whatever integration you are using for this sensor.
I’m sorry, I thought I had copied everything. This was missing indeed.
- platform: rest
name: Mechanische ventilatie status
resource: !secret nrf905_status_url
username: !secret nrf905_username
password: !secret nrf905_password
value_template: >
{% if value_json['result'] == 'ok' %}
on
{% else %}
off
{% endif %}
json_attributes_path: $.devices.D2 # This will be different for each fan.
json_attributes:
- voltage
- percentage
- speed
- timer
It might be related to these default values indeed, but weird I didn’t have the issues in 2022.6 already.
Thanks for sharing that bit of the configuation. Is there a chance that this issue only occurs in the rare event that your fan tries to update its percentage and preset_mode values before this rest sensor has successfully updated its state and attributes?
Maybe you could look at the update time of this rest sensor and compare it with the time that error message occurs.
If this is actually the case, then you could change the templates like:
percentage_template: >
{% if not is_state('sensor.mechanische_ventilatie_status', 'unavailable') %}
{{ state_attr('sensor.mechanische_ventilatie_status', 'percentage') }}
{% else %}0{% endif %}
Or, another alternative is to define an availability_template for the fan which includes the availability of all the entities you depend on (you might need to check for values unavailable and unknown):
value_template: "{{ not is_state('sensor.mechanische_ventilatie_status', 'unavailable') and not is_state('switch.on_off_plug_ventilatie', 'unavailable') and ... }}"