hass-template-climate
hass-template-climate copied to clipboard
Cannot use numerical fan speed modes. ['auto', '1', '2', '3']
The problem
Cannot use numerical fan speed modes.
Log reports Received invalid fan mode: 1. Expected: ['auto', '1', '2', '3'] and state does not update.
What version of Template Climate has the issue?
v0.6.1
What version of Home Assistant are you running?
Core 2024.2.5 Supervisor 2024.02.1 Operating System 12.0 Frontend 20240207.1
What type of installation are you running?
Home Assistant OS
Example YAML snippet
No response
Anything in the logs that might be useful for us?
ERROR (MainThread) [custom_components.climate_template.climate] Received invalid fan mode: 1. Expected: ['auto', '1', '2', '3'].
Additional information
No response
Hello,
I checked the code at place and it seems to be issue with integer input vs string expected in comparison. I can try to make fix for this in my forked repo if you are willing to test the patch.
BTW I am not sure, if numeric values are supported. I did checked all core Homeassistant constants:
# Possible fan state
FAN_ON = "on"
FAN_OFF = "off"
FAN_AUTO = "auto"
FAN_LOW = "low"
FAN_MEDIUM = "medium"
FAN_HIGH = "high"
FAN_TOP = "top"
FAN_MIDDLE = "middle"
FAN_FOCUS = "focus"
FAN_DIFFUSE = "diffuse"
from those climate_template imports only subset:
FAN_AUTO,
FAN_LOW,
FAN_MEDIUM,
FAN_HIGH,
therefore using fan modes for Climate entity in climate_template shall use only this set of strings:
"auto", "low", "medium", "high"
Given error message is misleading as it seems to be returning enum values. Please test functionality with string as above - it should work. If so, then this is not a bug ;-)
Hi @litinoveweedle I understood that the fan modes are allowed to be custom per Fan modes here:
https://developers.home-assistant.io/docs/core/entity/climate/
Granted, the Fan Modes are a list of strings, but as you say looks to treat them as integer and not str when using a numeric value.
Of course happy to test.
If I would prepare for you git branch in my repo with proposed fix, are you able to manually place it into your HA (modify climate.py)?
BTW: could you please paste here your config? Maybe explicitly casting you numeric fan mode as string in jinja template could help:
{{ states('input.fan_mode_i_want_set') | string }}
also it should help to declare fan_modes in the configuration as a string .i.e "1"
not 1
Can add the climate.py and test.
Here is a cut down template that exhibits the issue.
- platform: climate_template
name: "Test AC"
unique_id: 766fec37-6033-4206-b80a-a8ffde5ee2d9
modes:
- "fan_only"
- "off"
fan_modes:
- "auto"
- "1"
- "2"
- "3"
current_temperature_template: "{{ states('climate.cc3f1d041688') }}"
current_humidity_template: "{{ states('climate.cc3f1d041688') }}"
hvac_mode_template: "{{ states('climate.cc3f1d041688') }}"
target_temperature_template: "{{ states('climate.cc3f1d041688') }}"
fan_mode_template: "{{ state_attr('climate.cc3f1d041688', 'fan_mode') | string }}"
# actions
set_fan_mode:
- service: climate.set_fan_mode
target:
entity_id: climate.cc3f1d041688
data:
fan_mode: "{{ fan_mode }}"
@litinoveweedle any updates on this? Would also like to test this.
Here is a cut down template that exhibits the issue. Hello, your template seems to be fully ok. So nothing to change there.
@CV8R , @Arn0uDz I actually have some completely rewritten version of climate_template.py ready - it is running from today's 4AM in my HA. :-) I will check it once again later today, and I will commit it to my github repo, under given branch and send you a link to it, you can check it and report if it would be working. One warning, there is also small breaking change regarding set_temperature_action for HEAT_COOL hvac mode, but it not affect @CV8R (based on shared config, you are not using this hvac mode) and hopefully neither you @Arn0uDz. I will post here link to the updated climate_template.py later on.
@litinoveweedle thanks!
I'm not using the heat_cool HVAC mode so that is no problem for me.
Ok, here is climate.py.
Disclaimer: I tested only some functions, and almost whole code was rewritten, so expect bugs ;-) Also some of the configuration parameters and script variables were renamed to align with default HA climate attributes names. For reference check updated Readme. So backup your configuration before changes in case you will need to rollback.
For testing enable debug output for this integration:
logger:
default: warning
logs:
custom_components.climate_template.climate: debug
Please report any further issues to my repo issues directly if possible, thank you.
@litinoveweedle
The main reason i'm using your custom template is so I can use numbered fan speed modes instead of names.
I have no previous config so I can't compare. Tried your updated climate.py and having 2 issues.
- I'm unable to adjust the target temperature. I tried multiple things but getting an error when trying to adjust. I just don't know what to put in the config and there are no examples where I can copy from.
The error message is:
[140289070254272] 'TemplateClimate' object has no attribute '_round_temp_step'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 917, in async_service_temperature_set
await entity.async_set_temperature(**kwargs)
File "/config/custom_components/climate_template/climate.py", line 1147, in async_set_temperature
self._round_temp_step(target_temperature),
^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 328, in __getattribute__
return super().__getattribute__(__name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TemplateClimate' object has no attribute '_round_temp_step'
- The HVAC modes don't translate and format correctly. The fanspeed mode and swingmodes do translate and format correctly.
On the left your template and on the right the original in HA.
My code:
climate:
- platform: climate_template
name: "Airco Zolder Template"
unique_id: climate.airco_zolder_template
hvac_modes:
- "off"
- "cool"
- "heat"
- "fan_only"
- "dry"
swing_modes:
- "off"
- "vertical"
min_temp: 16
max_temp: 31
temp_step: 0.5
fan_modes:
- "auto"
- "1"
- "2"
- "3"
- "4"
- "5"
fan_mode_template: >
{% if state_attr('climate.airco_zolder', 'fan_mode') == diffuse %}
1
{% elif state_attr('climate.airco_zolder', 'fan_mode') == low %}
2
{% elif state_attr('climate.airco_zolder', 'fan_mode') == medium %}
3
{% elif state_attr('climate.airco_zolder', 'fan_mode') == middle %}
4
{% elif state_attr('climate.airco_zolder', 'fan_mode') == high %}
5
{% elif state_attr('climate.airco_zolder', 'fan_mode') == auto %}
auto
{% endif %}
set_fan_mode:
- service: climate.set_fan_mode
target:
entity_id: climate.airco_zolder
data:
fan_mode: >-
{% if fan_mode == '1' %}
diffuse
{% elif fan_mode == '2' %}
low
{% elif fan_mode == '3' %}
medium
{% elif fan_mode == '4' %}
middle
{% elif fan_mode == '5' %}
high
{% elif fan_mode == 'auto' %}
auto
{% endif %}
current_temperature_template: "{{ state_attr('climate.airco_zolder', 'current_temperature') }}"
hvac_mode_template: "{{ states('climate.airco_zolder') }}"
target_temperature_template: "{{ state_attr('climate.airco_zolder', 'temperature') }}"
hvac_action_template: "{{ state_attr('climate.airco_zolder', 'hvac_action') }}"
swing_mode_template: "{{ state_attr('climate.airco_zolder', 'swing_mode') }}"
set_hvac_mode:
- service: climate.set_hvac_mode
data:
entity_id: climate.airco_zolder
hvac_mode: "{{ states('climate.airco_zolder_template') }}"
set_swing_mode:
- service: climate.set_swing_mode
target:
entity_id: climate.airco_zolder
data:
swing_mode: "{{ swing_mode }}"
set_target_temperature:
- service: climate.set_temperature
target:
entity_id: climate.airco_zolder
data:
temperature: "{{ states('climate.airco_zolder_template') }}"
Also note that your new readme file has the following 2 changed options that don't work, it gives an error message.
- min_temperature
- max_temperature
It still wants min_temp and max_temp.
Edit; crossposted this issue to your repo.
You are right, syntax validation broke it, as it seems HA is expected some of the async functions to have given input variable with hardcoded names. It shall be fixed (I check it in my setup). Also translation shall be working now. You can check latest climate.py.
@litinoveweedle Thank you so much! Everything is fully working. Don't forget to comment this to your own repo.
Hey no problem. Thank you very much for testing! You see I did as well post into different repo issue. :-)
Hi @litinoveweedle ,
Nice work! Thank you and apologies for the delay, I was traveling. I have just tested your changes and all appears to be working now. For completeness I added my full config below.
As per your doco I needed to change
modes:
to hvac_modes:
set_temperature:
to set_target_temperature:
"{{ temperature }}"
to "{{ target_temperature }}"
- platform: climate_template
name: "Panasonic Ducted AC"
unique_id: eef60d30-4e1c-11ee-be56-0242ac120002
hvac_modes:
- "heat"
- "cool"
- "dry"
- "fan_only"
- "off"
fan_modes:
- "auto"
- "1"
- "2"
- "3"
min_temp: 16
max_temp: 30
temp_step: 1
precision: 0.1
current_temperature_template: "{{ states('sensor.multisensor_6_family_room_air_temperature_3') | round(0) }}"
current_humidity_template: "{{ states('sensor.multisensor_6_family_room_humidity_3') | round(0) }}"
hvac_mode_template: "{{ states('climate.cc3f1d041688') }}"
target_temperature_template: >-
{% if state_attr('climate.cc3f1d041688','temperature') | is_number %}
{{state_attr('climate.cc3f1d041688','temperature') | round(0) }}
{% else %}
0
{% endif %}
fan_mode_template: "{{ state_attr('climate.cc3f1d041688','fan_mode') }}"
availability_template: >
{% if is_state('climate.cc3f1d041688', 'unavailable') -%}
False
{%- elif is_state('climate.cc3f1d041688', 'unknown') -%}
False
{%- elif is_state('binary_sensor.panasonic_ducted_ac_ping', 'off') -%}
False
{%- else -%}
True
{%- endif %}
set_hvac_mode:
- service: climate.set_hvac_mode
target:
entity_id: climate.cc3f1d041688
data:
hvac_mode: "{{ hvac_mode }}"
set_fan_mode:
- service: climate.set_fan_mode
target:
entity_id: climate.cc3f1d041688
data:
fan_mode: "{{ fan_mode }}"
set_target_temperature:
- service: climate.set_temperature
target:
entity_id: climate.cc3f1d041688
data:
temperature: "{{ target_temperature }}"
icon_template: >-
{% if is_state('climate.cc3f1d041688', 'cool') -%}
mdi:snowflake
{%- elif is_state('climate.cc3f1d041688', 'heat') -%}
mdi:white-balance-sunny
{%- elif is_state('climate.cc3f1d041688', 'dry') -%}
mdi:water-off
{%- elif is_state('climate.cc3f1d041688', 'fan_only') -%}
mdi:fan
{%- endif %}