Return values

It would be great if scripts could return values. Using global helpers for this feels far from ideal; Jinja templates are sketchy at best (though perhaps you differ from me in that view, and I haven’t even figured out how I might use Jinja templates in HA scripts–though perhaps that’s where I go wrong); and the alternative feels like building a top-down script architecture where every possible piece of information is passed down from the top to a series of scripts that call one another in only one direction.

Am I missing something here? I’d love to be able to extract a return value from a script.

Thank you for reviewing. I have just two gripes with HA (which I have started using over teh last year) and have posted them both. I don’t want to abuse the opportunity :slight_smile:

Do you have an example?

In most other programming languages global variables are considered bad practice while in home assistant its more the golden standard.

There are multiple benefits to something like this for example

  • more generic and reusable scripts where different action can be taken on the return value depending on situation
  • return data from a web request or similar instead of storing this as a global separate variable
  • returning resulting state to take further action upon

Developers have been discussing the idea of allowing service calls to return a value:


Yea so I mean this is what you were missing:

Nothing wrong with the idea but its impossible at an architectural level right now. Service calls have no capability to return values, scripts are no exception. Could change though.

But yea, I’ll vote for it. Probably bigger then a WTH but I would definitely use this capability.