hass-template-climate
hass-template-climate copied to clipboard
hvac_mode_template
The problem
Hello!
I have a climate with hvac_mode_template like so:
hvac_mode_template: "{% if is_state('sensor.th2_mode_state', 'HOT') -%}heat{%- else -%}cool{%- endif %}"
set_hvac_mode: some actions, which work otherwise
If i change sensor.th2_mode_state
by other means, then the UI is updated properly.
The problem is, that if I set the hvac_mode_template
template I am no longer able to change the modes on the UI (clicking the flame or snowflake icon doen't do anything)
If I omit the hvac_mode_template
, clicking on the icons works again.
Is this the expected behaviour? If so, how could I use the mode selection while providing its status from an external source?
Thanks, M
What version of Template Climate has the issue?
0.6.1
What version of Home Assistant are you running?
2023.3.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?
No response
Additional information
No response
I have exact the same problem. I dont think this is normal :/
The way you can do this is by using the variable that gets exposed to the action:
set_hvac_mode:
- service: esphome.bedroom
data:
hvac_mode: "{{ hvac_mode }}"
Actions are essentially scripts, and they expose variables for you to use.
Hope this helps!
The way you can do this is by using the variable that gets exposed to the action:
set_hvac_mode: - service: esphome.bedroom data: hvac_mode: "{{ hvac_mode }}"
Actions are essentially scripts, and they expose variables for you to use.
Hope this helps!
But how can i achieve this when i calling a script to set the hvac mode? I use this integration to send commands to a knx bus, without hvac_mode_template i call a script and the commands to knx are working fine but i dont have synchronization with wall mounts controllers of the aircondition. When i use hvac_mode_template i have the synchronization but i can not command them (run the scripts). Any idea would be extremely helpfully.
@harisma-git I have the same issue, have you been able to find a way to do it ?
Unfortunately, no. I have it without synchronization :/
Unfortunately, no. I have it without synchronization :/
Thanks @harisma-git.
@jcwillox any ideas ?
You can pass a variable to a script when you call it in Home Assistant.
let's consider we have the following script:
# Example script
script:
my_script:
sequence:
- service: notify.mobile_app
data:
message: "Received value: {{ value }}"
Now let's call the above example script with an automation and pass a value in a variable:
automation:
- alias: Call Script with Variable
trigger:
platform: state
entity_id: binary_sensor.motion_sensor
to: 'on'
action:
- service: script.turn_on
entity_id: script.my_script
data_template:
value: "Hello, World!"
So in the case of the set_hvac_mode you'll do something like this:
set_hvac_mode:
- service: script.turn_on
entity_id: script.my_script
data_template:
value: "{{ hvac_mode }}"
I hope this helps.
@Tonguc-Endem I dont think this is SUPPOSED to be how this works, but it does seem to work!
@harisma-git I have the same issue, have you been able to find a way to do it ?
Same issue for me
I've been encountering a similar issue. In my case, I'm using a physical switch controls my air conditioning (AC) unit in the bedroom. My goal was to ensure that any changes in the AC's operational state via the physical switch were accurately reflected within the Climate entity in Home Assistant, and vice versa.
To achieve this, I removed hvac_mode_template
and leveraged set_hvac_mode
to directly control the switch based on the HVAC mode changes. Here's the relevant part of my configuration:
climate:
- platform: climate_template
...
set_hvac_mode:
- service: switch.turn_{{ 'off' if hvac_mode == 'off' else 'on' }}
entity_id: switch.bedroom_ac_switch
This configuration snippet ensures that when the HVAC mode of the Climate entity is set to "off" within Home Assistant, the corresponding switch (switch.bedroom_ac_switch in my case) is turned off. Conversely, setting any other mode (implicitly including "auto") turns the switch on, effectively powering the AC unit.
Additionally, I implemented an automation to handle state changes from the physical switch and update the Climate entity's mode accordingly:
automation:
- id: bedroom-ac-switch-sync
alias: Bedroom AC Switch Sync
trigger:
- platform: state
entity_id: switch.bedroom_ac_switch
action:
- service: climate.set_hvac_mode
target:
entity_id: climate.bedroom_ac
data:
hvac_mode: "{{ 'auto' if is_state('switch.bedroom_ac_switch', 'on') else 'off' }}"
This automation ensures that manual toggles of the physical switch are reflected in the Climate entity's operational mode, thus maintaining consistency between the physical switch state and the virtual climate control within Home Assistant.
Thanks @Tonguc-Endem and @harisma-git for your guidance.