How to call climate.set_temperature service?

Hi, I am creating some dashboard for my house heating system with touch display on esp32 and I have small problem with calling climate.set_temperature service.

Here is part of my code:

- platform: touchscreen
    internal: true
    # ...
    on_click:
      min_length: 100ms
      max_length: 500ms
      then:
        - homeassistant.service:
            service: climate.set_temperature
            data:
              entity_id: climate.better_aqara_e1
              temperature: '{{ my_variable | float }}'
            variables:
              my_variable: |-
                return id(target_temperature).state + 0.5;
        - component.update: my_display
# ...
- platform: touchscreen
    internal: true
    # ...
    on_click:
      min_length: 100ms
      max_length: 500ms
      then:
        - homeassistant.service:
            service: climate.set_temperature
            data:
              entity_id: climate.better_aqara_e1
              temperature: '{{ my_variable | float }}'
            variables:
              my_variable: |-
                return id(target_temperature).state - 0.5;
        - component.update: my_display
# ...
- platform: homeassistant
    id: target_temperature
    entity_id: climate.better_aqara_e1
    attribute: temperature

Touch screen is registering clicks, but target temperature is not changing in HA. I can’t figure out the correct syntax from ESPHome documentation.

1 Like

Ok I am an idiot. Documentation clearly says that data is for static values data_template is for non static.

So I needed to use this

data:
  entity_id: climate.better_aqara_e1
data_template:
  temperature: '{{ my_variable }}'

instead of:

data:
  entity_id: climate.better_aqara_e1
  temperature: '{{ my_variable }}'

And now it works

2 Likes

Thank you <3 Saved me a ton of time.

Here is the documentation being referred to from above: