In HA, Scripts are a series of actions. What atlflyer posted above is an action that could be placed in a script. If you need help translating YAML configuration to use in the Script Editor, there is a slightly dated, but still informative video primer on Youtube.
The way you get the current setpoint is through templates that query the state object of the entity you are interested in. Many types of actions allow the use of templates as a means to produce dynamic values in scripts and automations.