Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_temperature does not work! #67

Open
douglascrc-git opened this issue Apr 20, 2024 · 7 comments
Open

set_temperature does not work! #67

douglascrc-git opened this issue Apr 20, 2024 · 7 comments

Comments

@douglascrc-git
Copy link

The problem

I have this code
` - platform: climate_template
name: Bedroom Aircon
modes:
- "heat"
- "off"
- "cool"
min_temp: 5
max_temp: 30

# get current temp.
current_temperature_template: "{{ states('sensor.temperatura_termostato_baterias') }}"

# get current humidity.
current_humidity_template: "{{ states('sensor.sensorhumedadytemperatura_humidity') }}"
target_temperature_template: "{{ state_attr('climate.termostato_zona_z1', 'temperature') }}"
# set current temp.
set_temperature:
  - condition: template
    value_template: "{{ state_attr('climate.termostato_zona_z1', 'temperature') != state_attr('climate.Bedroom_Aircon', 'temperature') }}"
  - service: climate.set_temperature
    data:
      entity_id: climate.termostato_zona_z1
      temperature: "{{ state_attr('climate.Bedroom_Aircon', 'temperature') }}"

`

I've been trying to get the Bedroom Aircon thermostat to obtain the target temperature from the termostato_zona_z1 thermostat and, moreover, when I change the target temperature of the Bedroom Aircon, it should also modify the temperature of the termostato_zona_z1 thermostat. But for some reason, the set_temperature action isn't working.

I tried removing this line target_temperature_template: "{{ state_attr('climate.termostato_zona_z1', 'temperature') }}", and the set_temperature action works. But leaving both lines doesn't work.

Is there any way to solve this?

What version of Template Climate has the issue?

No response

What version of Home Assistant are you running?

No response

What type of installation are you running?

None

Example YAML snippet

- platform: climate_template
    name: Bedroom Aircon
    modes:
      - "heat"
      - "off"
      - "cool"
    min_temp: 5
    max_temp: 30

    # get current temp.
    current_temperature_template: "{{ states('sensor.temperatura_termostato_baterias') }}"

    # get current humidity.
    current_humidity_template: "{{ states('sensor.sensorhumedadytemperatura_humidity') }}"
    target_temperature_template: "{{ state_attr('climate.termostato_zona_z1', 'temperature') }}"
    # set current temp.
    set_temperature:
      - condition: template
        value_template: "{{ state_attr('climate.termostato_zona_z1', 'temperature') != state_attr('climate.Bedroom_Aircon', 'temperature') }}"
      - service: climate.set_temperature
        data:
          entity_id: climate.termostato_zona_z1
          temperature: "{{ state_attr('climate.Bedroom_Aircon', 'temperature') }}"

Anything in the logs that might be useful for us?

No response

Additional information

No response

@andrus2049
Copy link

IMO you can't call
service: climate.set_temperature
inside the climate template set_temperature:, because it's calling itself.

When temperature is set on the card, you have to directly invoke your specific device function (aircon), and in the service call or property set you can refer to the {{ temperature }} value

ex.:

          sequence:
            - service: number.set_value
              data:
                value: "{{ temperature | float(1) }}"
              target:
                 xxxxxxxxxxxxx

@douglascrc-git
Copy link
Author

IMO you can't call service: climate.set_temperature inside the climate template set_temperature:, because it's calling itself.

When temperature is set on the card, you have to directly invoke your specific device function (aircon), and in the service call or property set you can refer to the {{ temperature }} value

ex.:

          sequence:
            - service: number.set_value
              data:
                value: "{{ temperature | float(1) }}"
              target:
                 xxxxxxxxxxxxx

I did as you told me, but still not working.

The same behavior: I can change Bedroom Aircon target temperature from termostato_z1 but I can't change termostato_z1 target temperature from Bedroom Aircon.

This is my code now:

` - platform: climate_template
name: Bedroom Aircon
modes:
- "heat"
- "off"
- "cool"
min_temp: 5
max_temp: 30

# get current temp.
current_temperature_template: "{{ states('sensor.temperatura_termostato_baterias') }}"

# get current humidity.
current_humidity_template: "{{ states('sensor.sensorhumedadytemperatura_humidity') }}"
target_temperature_template: "{{ state_attr('climate.termostato_zona_z1', 'temperature') }}"
# set current temp.
set_temperature:
  - condition: template
    value_template: "{{ state_attr('climate.termostato_zona_z1', 'temperature') != state_attr('climate.Bedroom_Aircon', 'temperature') }}"
  - service: number.set_value
    data:
      value: "{{ temperature | float(1) }}"
      target: climate.termostato_zona_z1`

@andrus2049
Copy link

You need to directly address the aircon entity (input.number temperature ???) if you want to set the new temperature.
You can't use a climate entity as target, the climate entity is the software controller.

Let say that my_aircon temperature is controlled by a number entity.

set_temperature:
  - condition: template
    value_template: "{{ temperature != states('number.my_aircon_temperature') }}"
  - service: number.set_value
    data:
      value: "{{ temperature | float(1) }}"
      target: 
        entity_id: number.my_aircon_temperature

Condition template might be unnecessary as the temperature can be set anyway, also if it's just the current one.

@andrus2049
Copy link

andrus2049 commented May 20, 2024

The climate template entity is useful in these situations:

  • you have a heater with on-off switch entity
  • you have an air conditioner with a on-off switch entity and a temperature set entity (input.number entity ??), a fan speed entity, etc.
  • you have a separate temperature sensor entity

(All these entities are provided to HA by their specific integrations.)

Now you want to create a logic controller that regulates your house temperature: and just for this scope you can use the climate template entity to group all those entities together as a thermostat.

For example your logic could be:

  • if the sensor temperature is below 20°C, then turn the heater on
  • if the sensor temperature is above 22°C, then turn the heater off
  • if the sensor temperature is above 27°C, then turn the aircon on and set the aircon target temperature, and if needed set the fan speed.
  • if the sensor temperature is below 25°C, then turn the aircon off
  • otherwise keep both off.
  • define hours of use during days and nights

The HA climate card (thermostat) let you use the created climate template entity to show the current state, and override the logic if you need so.

@douglascrc-git
Copy link
Author

**andrus2049 ** commented May 20, 2024

I understand. Thanks so much for the explanation.

I will explain a little better what I am trying to achieve based on what you have told me.

I have a wireless zigbee thermostat that only works for heat (Bedroom_Aircon), and I want it to work for both cold and heat.

My idea is to use the temperature sensor entity that the thermostat gives me, as well as the set point variable. Take these two entities and create a "virtual" thermostat that works for hot and cold. In addition to that, I would like that when modifying the set point in the virtual thermostat, it would also be modified in the wireless zigbee thermostat (it has a screen).

I know how to create a sensor with the thermostat temperature (with a template) :)
I don't know how to get the thermostat set point and create an entity :(
I don't know how to ensure that when modifying the set point in the virtual thermostat, it is also modified in the real thermostat :(

@andrus2049
Copy link

I don't know how to get the thermostat set point and create an entity

So you don't get/set this value in HA?

The model of the zigbee thermostat can help to understand how it works.

Anyway, generally speaking, the entities available for managing a device (get and set) are provided by the integration that manages it, you can't add an entity to it.
For the zigbee devices there are very technical methods that could allow HA to send them commands (using clusters and attributes), but the necessary documentation specific for a device is generally poor if not existent at all.

Probably the best solution might be to use a different thermostat with all the settings already available in HA.

@mhjansen79
Copy link

This should work for what you are trying to do @douglascrc-git

`set_temperature:

  • service: climate_set_temperature
    target:
    entity_id: climate.termostato_zona_z1
    data:
    temperature: "{{ temperature }}"`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants