jcwillox / hass-template-climate

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

Entity state is always "Off" even though all controls work as expected #51

Closed akshay7394 closed 9 months ago

akshay7394 commented 9 months ago

The problem

For some reason, the state of the entity is perpetually "Off", even when I successfully turn on the entity and/or change modes via the entity card. It still shows the target temperature as expected, and the currently-running mode too - it simply doesn't change state from "Off" to anything else.

This isn't a dealbreaker by any means, since I still get 90% of the functionality, it just looks v confusing on my dashboard. I'm not sure what I'm doing wrong, would love some guidance!

What version of Template Climate has the issue?

0.6.1

What version of Home Assistant are you running?

2023.11.2

What type of installation are you running?

Home Assistant OS

Example YAML snippet

# Climate
climate:
  - platform: climate_template
    name: my AC
    unique_id: my_room_ac
    current_temperature_template: >
      {% if is_state('input_boolean.my_ac', 'on') %}
        {% set default_date = '1900-01-01T00:00:00.000000+00:00' %}
        {% set scene1 = states('scene.set_ac_cold_24') if states('scene.set_ac_cold_24') != 'unknown' else default_date %}
        {% set scene2 = states('scene.set_ac_cold_21') if states('scene.set_ac_cold_21') != 'unknown' else default_date %}
        {% set scene3 = states('scene.set_ac_cold_18') if states('scene.set_ac_cold_18') != 'unknown' else default_date %}
        {% if scene1 >= scene2 and scene1 >= scene3 %}
          24
        {% elif scene2 >= scene1 and scene2 >= scene3 %}
          21
        {% else %}
          18
        {% endif %}
      {% else %}
        off
      {% endif %}
    target_temperature_template: >
      {% if is_state('input_boolean.my_ac', 'on') %}
        {% set default_date = '1900-01-01T00:00:00.000000+00:00' %}
        {% set scene1 = states('scene.set_ac_cold_24') if states('scene.set_ac_cold_24') != 'unknown' else default_date %}
        {% set scene2 = states('scene.set_ac_cold_21') if states('scene.set_ac_cold_21') != 'unknown' else default_date %}
        {% set scene3 = states('scene.set_ac_cold_18') if states('scene.set_ac_cold_18') != 'unknown' else default_date %}
        {% if scene1 >= scene2 and scene1 >= scene3 %}
          24
        {% elif scene2 >= scene1 and scene2 >= scene3 %}
          21
        {% else %}
          18
        {% endif %}
      {% endif %}
    hvac_mode_template: >
      {% if is_state('input_boolean.my_ac', 'on') %}
        {% set default_date = '1900-01-01T00:00:00.000000+00:00' %}
        {% set scene1 = states('scene.set_ac_cold_24') if states('scene.set_ac_cold_24') != 'unknown' else default_date %}
        {% set scene2 = states('scene.set_ac_cold_21') if states('scene.set_ac_cold_21') != 'unknown' else default_date %}
        {% set scene3 = states('scene.set_ac_cold_18') if states('scene.set_ac_cold_18') != 'unknown' else default_date %}
        {% if scene1 >= scene2 and scene1 >= scene3 %}
          "fan_only"
        {% elif scene2 >= scene1 and scene2 >= scene3 %}
          "auto"
        {% else %}
          "cool"
        {% endif %}
      {% else %}
        "off"
      {% endif %}

    modes:
      - "off"
      - "cool"
      - "auto"
      - "fan_only"
    min_temp: 18
    max_temp: 24
    set_hvac_mode:
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ hvac_mode == 'cool' }}"
            sequence:
              - service: input_boolean.turn_on
                entity_id: input_boolean.my_ac
              - service: scene.turn_on
                entity_id: scene.set_ac_cold_18
          - conditions:
              - condition: template
                value_template: "{{ hvac_mode == 'auto' }}"
            sequence:
              - service: input_boolean.turn_on
                entity_id: input_boolean.my_ac
              - service: scene.turn_on
                entity_id: scene.set_ac_cold_21
          - conditions:
              - condition: template
                value_template: "{{ hvac_mode == 'fan_only' }}"
            sequence:
              - service: input_boolean.turn_on
                entity_id: input_boolean.my_ac
              - service: scene.turn_on
                entity_id: scene.set_ac_cold_24
          - conditions:
              - condition: template
                value_template: "{{ hvac_mode == 'off' }}"
            sequence:
              - service: input_boolean.turn_off
                entity_id: input_boolean.my_ac
      - service: input_boolean.turn_on
        entity_id: input_boolean.my_ac

Anything in the logs that might be useful for us?

No errors in the logs, since everything except state is triggering successfully.

Additional information

Love this integration! Does a fantastic job helping me consolidate my smart plug & IR controls. I'm able to perfectly control the HVAC modes & power states of my AC via this climate entity template, barring the state issue i mentioned.

scuba75 commented 9 months ago

try removing the ""

hvac_mode_template: >
      {% if is_state('input_boolean.my_ac', 'on') %}
        {% set default_date = '1900-01-01T00:00:00.000000+00:00' %}
        {% set scene1 = states('scene.set_ac_cold_24') if states('scene.set_ac_cold_24') != 'unknown' else default_date %}
        {% set scene2 = states('scene.set_ac_cold_21') if states('scene.set_ac_cold_21') != 'unknown' else default_date %}
        {% set scene3 = states('scene.set_ac_cold_18') if states('scene.set_ac_cold_18') != 'unknown' else default_date %}
        {% if scene1 >= scene2 and scene1 >= scene3 %}
          fan_only
        {% elif scene2 >= scene1 and scene2 >= scene3 %}
          auto
        {% else %}
          cool
        {% endif %}
      {% else %}
        off
      {% endif %}
akshay7394 commented 9 months ago

Well. I did that, I now seem to have the exact opposite problem - now it shows all active States perfectly, but never displays 'off' (even though it seems to correctly turn off the AC).

I also surely seem to have lost the ability to turn the input_Boolean to off manually somehow by doing this, despite being able to turn off the AC via the climate entity?

scuba75 commented 9 months ago

I think you may have to leave the quotes around off. Forgot about this.

May need to be 'off'

hvac_mode_template: >
      {% if is_state('input_boolean.my_ac', 'on') %}
        {% set default_date = '1900-01-01T00:00:00.000000+00:00' %}
        {% set scene1 = states('scene.set_ac_cold_24') if states('scene.set_ac_cold_24') != 'unknown' else default_date %}
        {% set scene2 = states('scene.set_ac_cold_21') if states('scene.set_ac_cold_21') != 'unknown' else default_date %}
        {% set scene3 = states('scene.set_ac_cold_18') if states('scene.set_ac_cold_18') != 'unknown' else default_date %}
        {% if scene1 >= scene2 and scene1 >= scene3 %}
          fan_only
        {% elif scene2 >= scene1 and scene2 >= scene3 %}
          auto
        {% else %}
          cool
        {% endif %}
      {% else %}
        "off"
      {% endif %}
akshay7394 commented 9 months ago

That doesn't seem to have changed anything unfortunately 😅 same as my previous comment, controls work but 'Off' state is never shown, even when the climate entity turns off as expected.

Although I do seem to have regained control over the input_boolean now.

akshay7394 commented 9 months ago

Yup, just tried again to make sure. Both 'off' and "off" don't change the problem, the modes successfully change but I can't seem to get the status to change to "Off" when the AC is turned off

scuba75 commented 9 months ago

weird. I just made a test one and it all works as expected

- platform: climate_template
  name: Virtual AC
  unique_id: test_virtual_ac
  min_temp: 60
  max_temp: 90
  modes:
    - "off"
    - auto
    - cool
    - heat
    - fan_only
  current_temperature_template: "{{ int(states('sensor.della_virtual_tempurature'), 77) }}"
  target_temperature_template: "{{ states('input_number.virtual_ac_target_temp') }}"
  hvac_mode_template: >
    {% if is_state('input_boolean.virtual_ac_power_switch', 'on') %}
      {% if is_state('input_select.virtual_ac_mode_switch', 'cold') %}
      cool
      {% elif is_state('input_select.virtual_ac_mode_switch', 'hot') %}
      heat
      {% elif is_state('input_select.virtual_ac_mode_switch', 'fan') %}
      fan_only
      {% elif is_state('input_select.virtual_ac_mode_switch', 'auto') %}
      auto
      {% endif %}
    {% else %}
    off
    {% endif %}
  set_temperature:
    - service: input_number.set_value
      data:
        value: "{{ temperature }}"
      target:
        entity_id: input_number.virtual_ac_target_temp
  set_hvac_mode:
    - choose:
      - conditions:
          - condition: template
            value_template: "{{ hvac_mode == 'off' }}"
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.virtual_ac_power_switch
      - conditions:
          - condition: template
            value_template: "{{ hvac_mode == 'cool' }}"
        sequence:
          - service: input_select.select_option
            data:
              option: cold
            target:
              entity_id: input_select.virtual_ac_mode_switch
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.virtual_ac_power_switch
      - conditions:
          - condition: template
            value_template: "{{ hvac_mode == 'heat' }}"
        sequence:
          - service: input_select.select_option
            data:
              option: hot
            target:
              entity_id: input_select.virtual_ac_mode_switch
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.virtual_ac_power_switch
      - conditions:
          - condition: template
            value_template: "{{ hvac_mode == 'fan_only' }}"
        sequence:
          - service: input_select.select_option
            data:
              option: fan
            target:
              entity_id: input_select.virtual_ac_mode_switch
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.virtual_ac_power_switch
      - conditions:
          - condition: template
            value_template: "{{ hvac_mode == 'auto' }}"
        sequence:
          - service: input_select.select_option
            data:
              option: auto
            target:
              entity_id: input_select.virtual_ac_mode_switch
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.virtual_ac_power_switch

other parts:

virtual_ac_mode_switch:
  name: Virutal AC mode switch
  options:
    - auto
    - hot
    - cold
    - fan

virtual_ac_power_switch:
  name: Virtual AC power switch

virtual_ac_target_temp:
  name: Virtual AC target temp
  min: 60
  max: 90
  step: 1
  unit_of_measurement: F
akshay7394 commented 9 months ago

I just figured it out, my problem was these two lines at the end:

  - service: input_boolean.turn_on
    entity_id: input_boolean.my_ac

It was turning my AC on at the end of every command. D'oh. 🤦🏽‍♂️