How do use a template temperature value in

I am trying to pass a temperature value from a template (basically deduct one degree from the current set temperature). However, HA will only accept a numeric value in “temperature” and not my template value

alias: Make Upstairs Cooler
sequence:
  - wait_template: >-
      {% set upstairs_target_temp =  state_attr('climate.upstairs_temperature',
      temperature' ) - 1 %}
    continue_on_timeout: true
  - service: climate.set_temperature
    target:
      entity_id: climate.upstairs_temperature
    data:
      temperature: {{ set upstairs_target_temp }}
mode: single

Your template doesn’t actually output anything… Do you need a Wait action or are you just trying to define a variable?

alias: Make Upstairs Cooler
sequence:
  - variables:
      upstairs_target_temp: >
        {{ state_attr('climate.upstairs_temperature', 'temperature' ) - 1 }}
  - service: climate.set_temperature
    target:
      entity_id: climate.upstairs_temperature
    data:
      temperature: '{{ upstairs_target_temp }}'
mode: single

I am trying to get a new set value to set and update my thermostat. If I put it in Developer Tools it does display the value was dropped by 1 which is what I want to set as the new value.

Can you show me how to achieve this? My first real attempt at templating.

The script I posted above, based on your original post, will change the set point of the thermostat to 1 degree less than the current room temperature… can you describe more broadly what you are trying to do and why you would use this approach?

Ultimately, if I wake up in the middle of the night because I over heated, I would like to be able to drop the temperature at night in bed using Alexa without having to open my phone and navigate to ecobee to see the set temperature in order to drop it by one degree. And since I am half-asleep I can’t remember what the current multi-stage cooliing setting is.

Thanks for the code. However I am getting an error msg.

missed comma between flow collection entries at line 595, column 69:
... irs_temperature', 'temperature' ) - 1 }}
^

Maybe as follows:
{{ state_attr('climate.upstairs_temperature', 'temperature' ) | float(0) - 1 }}

Dang, same error msg.

Thanks

Both versions of the template work in D’ tools but when the script I get the error msg. I assume it must be formatting but I can’t find it. However, if I delete the comma between the two temperatures the error goes away.

There was a missing multi-line quote symbol >, I have fixed it above.

Thanks that took care of the comma problem, now when I check config I get this warning

"Error loading /config/configuration.yaml: invalid key: "OrderedDict([('upstairs_target_temp', None)])"
in "/config/scripts.yaml", line 611, column 0"

Double check that you have quotes around the template for temperature: '{{ upstairs_target_temp }}'

With your last tweak I was able to finally figure out that it had to be the indentations.
Once I playted around with it I finally got it to work.
I learned a lot and hopefully will be able to pay it forward.
I also changed “>” to “>-”

Many Thanks Sir!

Hi dhtguru,

hope you can help me with a similar issue, PLEASE, I have a temp / humidity sensor loggin into a google sheet, but if it goes offline, ha keeps posting the last value. so I am trying to set the value to temp -40 before reading the state. that way the value will be 31deg - 40 = -9 deg if the sensor is offline but because i read the sensor value after this if the sensor is online it will report the real value.
I am using this
variables: {{ state_attr('sensor.sonoff_1001dbe456_temperature, ‘temperature’ ) | float (0) -40 }}

Please follow the Community Guidelines by posting the full configuration in question, formatted correctly so we don’t have to base answer on conjecture.

Based on the small piece you posted, there are at least 3 errors that need to be addressed:

  1. A key/id for your variable.
  2. Double quotes around the entire template
  3. A single quote at the end of the entity ID.
variables: 
  temp: "{{ state_attr('sensor.sonoff_1001dbe456_temperature', 'temperature' ) | float (0) - 40 }}"