jcwillox / hass-template-climate

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

Can't pass changed temperature to set_temperature script #48

Open Garulf opened 1 year ago

Garulf commented 1 year ago

The problem

When climate entity is changed it should pass the changed temperature to the set_temperature script.

What version of Template Climate has the issue?

0.6.1

What version of Home Assistant are you running?

2023.7.3

What type of installation are you running?

Home Assistant Core

Example YAML snippet

climate:
  - platform: climate_template
    name: Ember Mug White
    modes:
      - heat
    current_temperature_template: "{{ states('sensor.ember_mug_dff1840ca9b3_current_temp') }}"
    target_temperature_template: "{{ states('number.ember_mug_dff1840ca9b3_target_temp') }}"
    min_temp: 120
    max_temp: 145
    set_temperature:
      - service: number.set_value
        data:
          value: "{{ temperature }}"
        target:
          entity_id: number.ember_mug_dff1840ca9b3_target_temp

Anything in the logs that might be useful for us?

N/A

Additional information

image

I assume the "128" would be passed, but instead 145 is passed to the set_temperature script.

CDeLeon94 commented 1 year ago

Removing the target_temperature_template was necessary for me to get things working. It appears its an either or situation (Reading state from the template or setting & syncing via the set_temperature action)

devildant commented 1 year ago

I thought of a workaround, with an intermediate input number, and 1 automation

in configuration.yaml:

input_number:
  your_input_name:
    name: your_input_name
    min: 16
    max: 31
    step: 1

inside the set_temperature section inside your impl of climate_template

set_temperature:
      - condition: or
        conditions:
        - condition: numeric_state
          entity_id: climate.your_climate_template_entity_id
          attribute: temperature
          above: input_number.your_input_name
        - condition: numeric_state
          entity_id: climate.your_climate_template_entity_id
          attribute: temperature
          below: input_number.your_input_name
      - your action....

and for automation: for update the transitive input (input_number.your_input_name) and your climate_template (your_input_name) with reference target temperature (number.target_temperature_template_entityid)

alias: Update-Transitive-Input-And-Climate
description: ""
trigger:
  - platform: state
    entity_id:
      - number.target_temperature_template_entityid
    attribute: raw_state
condition: []
action:
  - service: input_number.set_value
    data:
      value: >-
        {{ states('number.target_temperature_template_entityid')  | int
        / 10 | int }}
    target:
      entity_id: input_number.your_input_name
    enabled: true
  - service: climate.set_temperature
    data:
      temperature: >-
        {{ state_attr('number.target_temperature_template_entityid',
        'raw_state')  |  float }}
    target:
      entity_id: climate.your_climate_template_entity_id
    enabled: true
mode: parallel
max: 10
scuba75 commented 1 year ago

this all works correctly for me

- platform: climate_template
  name: Virtual AC
  unique_id: test_virtual_ac
  min_temp: 60
  max_temp: 90
  modes:
    - "off"
    - auto
    - cool
    - heat
    - fan_only
  fan_modes:
    - auto
    - low
    - medium
    - high
  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

the input_number

virtual_ac_target_temp:
  name: Virtual AC target temp
  min: 60
  max: 90
  step: 1
  unit_of_measurement: F