Advanced Flow and HomeyScript

I have created a Homey Script which returns the number of TV Programs found.

I want to use that script in an advanced flow, but there’s no card for “Execute Script with an Argument and Return a Number”.

There’s only “Execute Code with an Argument and Return a Number”, but I don’t want to use that, because my script can be called by a lot of flows (and if I need to change something, I only need to change one script, not all the “execute code” in all my flows).

So…what to do?

image

Here you can call a script by his name.

Yes, but I need a return type (number, string or boolean). I want to have a tag which I can use for the next part in my flow.

Now I need to save the outcome of my script to a variable (a Homey Script variable, a Logic variable or a BLL variable).

What is wrong with the additional tag you can use in the flow? Just connect the HomeyScript card to the card you want to use value in, and select the local tag “result” in there.

Maybe I am missing something?

Which “result”? There’s no local tag “result”, because there’s now flow card which calls a SCRIPT which returns a local tag.

Only the cards which uses CODE have a return tag. As I have written before, my SCRIPT can be called from a lot of places, I don’t want to copy-paste my SCRIPT into a CODE section of HomeyScript.

Aaah, then I read it wrong my bad.
Indeed, HomeyScript’s Script, is a separate part of the app, the flow can only run the script, that is how it was designed as Advanced Flows didn’t exist back then, changing that would most likely break all those existing codes of people already running scripts.

The code part of the app was added when Advanced flows was introduced for this very reason, so the only option you have is to run it in the Code card, or indeed save it to a logic variable.

1 Like

You can create a (global?) tag inside HomeyScript:

await tag("tagName", variable);

This tag you can use in the following AdvancedFlow card.

2 Likes

Hi all,

I’m trying to achieve the same. Is it a really crazy idea to always create a JSON error?

Example:

throw new Error(‘{“status”:“ok”}’);

For example, does this require a lot more resources? Otherwise, I think this is a great solution until it is implemented? Agree? :slight_smile:

Adv. flow cards have error ‘nipples’ for that.
Or do you mean something else?

Screenshot from 2023-04-07 22-26-26

@Peter_Kawa Exactly! Any objections to why this is not a good idea?
afex

The error card only gets triggered when the HS card errors. I don’t see that is gonna use much resources.
I still don’t get what you want to achieve yet. The “resultaat = OK” will never be true now.

1 Like

Bit late on this (as always) as was looking for potential solution to combine my (exiting) multi-argument input approach (separated by “;” ) and (now needed) returning text-tag(s) out from HomeyScript (not code-card) - comments welcomed

I created test flow (most flex case, normally would not check “false”, but only continue when “true” and error-handling):

where HomeyScript is (to allow easy adjustments depending on #or agrs and tags):

//Testing tags
const allArguments = args[0];
const sepArguments = ( allArguments.split(‘;’) ).map(value => value.trim());
if (!sepArguments || sepArguments.length === 0) {
return false}
for (let j = 0; j < sepArguments.length; j++) {
if (sepArguments[j] === undefined) {
throw new Error('Undefined argument ’ + j)}
}
//--------------------------------------
const arg1 = sepArguments[0];
const arg2 = sepArguments[1];
const tag1 = sepArguments[2];
//--------------------------------------
await tag(tag1, arg1 + " / " + arg2); // global Tag
//> await tag(tag2, arg2 + " / " + arg1); // global Tag
return true

Otherwise I am happy, but cannot figure out how I could used “Res1” also to read a-Res1 tag (as now need to run script 1st to create a-Res1 and only then can select it from tag-list…)

Any advice appreciated (trying to avoid Global- and BLL-variables, so not looking for those)