Python script: how to call a function

I am a very new person for Python.
There is a script containing a function.
Let it be this example:

def my_function(fname):
  print(fname + " Refsnes")

How to call this function by using a HA service?

I want to use the result as a value for some sensor.

I found this:

PS: im even more green, just looked at the new “Python script” doc the other day :wink:

Thank you very much for a reply.
Unfortunately, it does not help me.
I need to pass a parameter to a function my_function.

Have you had a go at this example?
Simple python script that reads a parameter from a service call and writes parameter value to the HA log. Good hunting!

Yes i thought this was too simple example for you, below is a more “complicated”, and way above my understanding example, and then you can hope “123” will catch your post, he seems to be familiar with python also.

Did you ever get this figured out? I’ve got the same problem