Can’t Adjust Thermostat

I need some assistance from the forum, please. I have a Nest thermostat, and I am trying to write a couple scripts that are activated by a button. Neither are working, and I am sure it’s my code.

The first script is supposed to look to see if I am heating or cooling the house, and then adjust the target temperature by 2 degrees (higher if heating, lower if cooling). I am trying to do this by comparing my house temperature to the outside temperature. I could use the hvac_mode, but if that is set to ‘heat-cool’, I may not know what’s really happening.

My second script is supposed to poll the current temperature and set that value to the target temperature. The idea being that i have become to cold (or hot), and just stop where it is.

Neither of my scripts are working and I can’t figure out why. I am hoping someone has done this before and has some suggestions. I am rather new to this, so any and all help is greatly appreciated!

Button Code:

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: script.turn_on
  target:
    entity_id: script.climate_adjust
  data:
    climate_id: climate.upstairs
entity: script.climate_adjust
name: Nudge Temp
hold_action:
  action: call-service
  service: script.turn_on
  target:
    entity_id: script.climate_hold
  data:
    climate_id: climate.upstairs

The two scripts:

climate_adjust:
  alias: Climate Adjust
  sequence:
    - variables:
        target_temp: "{{ state_attr('{{ climate_id }}','target_temperature') | float(0) }}"
        current_mode: "{{ state_attr('{{ climate_id }}','hvac_mode')}}"
        adjustment: 2
    - if:
        - condition:  weather.home.attribute.temperature > '{{ target_temp }}'
      then:
        - variables:
            adjustment: -2
    - service: climate.set_temperature
      data:
        temperature: '{{ target_temp }} + {{ adjustment }}'
        hvac_mode: '{{ current_mode }}'
      target:
        entity_id: '{{ climate_id }}'
    - service: climate.turn_on
      data: {}
      target:
        entity_id: '{{ climate_id }}'

climate_hold:
  alias: Climate Hold
  sequence:
    - variables:
        current_temp: "{{ state_attr('{{ climate_id }}','current_temperature') | float(0) }}"
        current_mode: "{{ state_attr('{{ climate_id }}','hvac_mode')}}"
    - service: climate.set_temperature
      data:
        temperature: '{{ current_temp }}'
        hvac_mode: '{{ current_mode }}'
      target:
        entity_id: '{{ climate_id }}'
    - service: climate.turn_on
      data: {}
      target:
        entity_id: '{{ climate_id }}' 

Took me a while, but I got it. It was all about the syntax. I still haven’t figured out how to do a proper if…then statement to adjust a variable, but I used a little logic to get me there. Anyhow, here is my solution. I hope it helps others:

Button:

            name: Upstairs
            tap_action:
              action: call-service
              service: script.climate_adjust
              service_data:
                entity_id: "climate.upstairs"
            double_tap_action:
              action: call-service
              service: script.climate_hold
              service_data:
                entity_id: "climate.upstairs"

and the two scripts:

climate_adjust:
  alias: Climate Adjust
  sequence:
  - variables:
      climate_id: "{{entity_id}}"
      target_temp: "{{ state_attr(climate_id,'temperature') | float()}}"
      outside_temp: "{{ state_attr('weather.home','temperature') | float ()}}"
      adjustment: "{{ 2 - ((outside_temp>=target_temp)| int() * 4) }}"
  - service: climate.set_temperature
    data:
      temperature: "{{(float(target_temp)+ float(adjustment)) | float}}"
    target:
      entity_id: "{{climate_id}}"

climate_hold:
  alias: Climate Hold
  sequence:
  - variables:
      climate_id: "{{entity_id}}"
      current_temp: "{{ state_attr(climate_id,'current_temperature') | float()}}"
  - service: climate.set_temperature
    data:
      temperature: "{{current_temp}}"
    target:
      entity_id: "{{climate_id}}"

I am sure there is a way to do code this more efficiently, but this worked.