How to get float formatted and published into template text_sensor?

I’m curious the best way to get a global or sensor’s float value into a template text_sensor with lambda. I tried to do it like this:

                        - text_sensor.template.publish:
                            id: ${node_name}_change_reason
                            state: !lambda |-
                              return "Turning fan on because it's hotter in the attic " + value_accuracy_to_string(x, 1) + " threshold " + value_accuracy_to_string(id(outdoor_min_temp) + id(offset_temp), 1);

but I don’t know if it’ll work and it feels like a mess. Is there a better way? I found that value_accuracy_to_string() function here: ESPHome: esphome Namespace Reference

this is part of an on_value so the x should be the sensor’s value. The outdoor_min_temp and offset_temp values are globals.