litinoveweedle / hass-template-climate

❄️Templatable Climate Device for Home Assistant, Supports Running Actions On Service Calls.
MIT License
24 stars 1 forks source link

How to set HVAC mode, temp, etc for non-climate entities? #17

Closed BradleyFord closed 4 months ago

BradleyFord commented 4 months ago

The problem

I have data coming in via BACNET, of which all the ACs are coming into one huge device... that is NOT a climate entity. Hence I need to link my generic entities to the set_HVAC_mode, set_target_temperature, etc. In terms of reading in data everything is working perfectly

The challenge I am having is mapping the outputs back down to entities.

In the case of MODE, there are 2 entities:

  1. That I can read to get the current MODE from the AC
  2. That I can set which will be pushed to the AC

Note that these entities are all numeric, hence I am using a template to convert the number into the respective text. I think my template to convert back to numeric is ok.

But some some reason nothing seems to be working... you can see the error that appears when I try to change mode. image

The error is the same for set_fan_mode as well, but I know once I figure out set_hvac_mode it will be the same adjustments needed.

There is a seperate complication, but that is something to solve later. Essentially the entity for turning the AC on or off is seperate from the MODE setting.

What version of Template Climate has the issue?

Latest

What version of Home Assistant are you running?

Latest

What type of installation are you running?

Home Assistant OS

Example YAML snippet

climate:
  - platform: climate_template
    unique_id: l2_ac_office
    name: L2_AC_Office
    hvac_modes:
      - "dry"
      - "off"
      - "cool"
      - "fan_only"
    swing_modes:
      - "off"
      - "vertical"
    fan_modes:
      - "auto"
      - "low"
      - "medium"
      - "high"
    min_temp: 24
    max_temp: 30

    current_temperature_template: "{{ states('sensor.bacnet_roomtemp_020') }}"
    target_temperature_template: "{{ states('number.bacnet_tempadjust_020') }}"
    hvac_mode_template: "{% if states('binary_sensor.bacnet_thermostatus_020') == 'off' %}off{% elif states('sensor.bacnet_airconmodestatus_020') == '1' %}cool{% elif  states('sensor.bacnet_airconmodestatus_020') == '3'%}fan{% elif  states('sensor.bacnet_airconmodestatus_020') == '5'%}dry{% else %}off{% endif %}"
    fan_mode_template: "{% if states('sensor.bacnet_airflowratestatus_020') == '4' %}auto{% elif  states('sensor.bacnet_airflowratestatus_020') == '1'%}low{% elif  states('sensor.bacnet_airflowratestatus_020') == '3'%}medium{% elif  states('sensor.bacnet_airflowratestatus_020') == '2'%}high{% else %}off{% endif %}"

    set_hvac_mode:
      # allows you to control an existing Home Assistant HVAC device
      - service: climate.set_hvac_mode
        data:
          entity_id: select.bacnet_airconmodecommand_020
          hvac_mode: >-
            {% if hvac_mode == 'cool' %}
              1
            {% elif hvac_mode == 'fan_only' %}
              3
            {% elif hvac_mode == 'dry' %}
              5
            {% endif %}

Anything in the logs that might be useful for us?

No response

Additional information

No response

litinoveweedle commented 4 months ago

Hi, sorry for late reply. As mentioned it is not possible to defined/create new hvac modes in HA. Therefore you need to map you function value into hardcoded hvac modes:

    hvac_modes:
      - "dry"
      - "off"
      - "cool"
      - "fan_only"

shall become

    hvac_modes:
      - "dry"
      - "off"
      - "cool"
      - "fan"

and you also need to make similar change in othe parts of your configuration like hvac_mode_template and set_hvac_mode

Don't worry HA documentation was also misleading for me. Simply HVACMode.FAN_ONLY value is fan and not fan_only. I added list of modes into new version of readme to decrease this confusion. ;-)

BradleyFord commented 4 months ago

Thank you for that.

I managed to get my templates working with some help from GravySeal; I have posted it below for anyone elses reference.

The key point in this example is that I am ready 2 seperate entities to determine on/off and the mode.

climate:
  - platform: climate_template
    unique_id: l1_ac_parents
    name: L1_AC_parents
    icon_template: mdi:air-conditioner
    hvac_modes:
      - "dry"
      - "off"
      - "cool"
      - "fan"
    swing_modes:
      - "off"
      - "vertical"
    fan_modes:
      - "auto"
      - "low"
      - "medium"
      - "high"
    min_temp: 24
    max_temp: 30

    current_temperature_template: "{{ states('sensor.bacnet_roomtemp_001') }}"
    target_temperature_template: "{{ states('number.bacnet_tempadjust_001') }}"
    hvac_mode_template: "{% if states('binary_sensor.bacnet_startstopstatus_001') == 'off' %}off{% elif states('sensor.bacnet_airconmodestatus_001') == '1' %}cool{% elif  states('sensor.bacnet_airconmodestatus_001') == '3'%}fan{% elif  states('sensor.bacnet_airconmodestatus_001') == '5'%}dry{% else %}off{% endif %}"
    fan_mode_template: "{% if states('sensor.bacnet_airflowratestatus_001') == '4' %}auto{% elif  states('sensor.bacnet_airflowratestatus_001') == '1'%}low{% elif  states('sensor.bacnet_airflowratestatus_001') == '3'%}medium{% elif  states('sensor.bacnet_airflowratestatus_001') == '2'%}high{% else %}off{% endif %}"

    set_hvac_mode: # send the climates current state.
      - service: select.select_option
        target:
          entity_id:  select.bacnet_airconmodecommand_001
        data:
          option: "{% if hvac_mode == 'cool' %}1{% elif hvac_mode == 'fan' %}3{% elif hvac_mode == 'dry' %}5{% elif hvac_mode == 'off' %}1{% endif %}"
      - service: "{% if hvac_mode == 'off' %}switch.turn_off{% else %}switch.turn_on{% endif %}"
        target:
          entity_id:  switch.bacnet_startstopcommand_001
    set_fan_mode: # send the climates current state.
      - service: select.select_option
        target:
          entity_id: select.bacnet_airflowratecommand_001
        data:
          option: "{% if fan_mode == 'low' %}1{% elif fan_mode == 'medium' %}2{% elif fan_mode == 'high' %}3{% elif fan_mode == 'auto' %}4{% endif %}"
    set_temperature:
      - service: number.set_value
        data:
          value: "{{ temperature }}"
        target:
          entity_id: number.bacnet_tempadjust_001