# Advanced Flow and HomeyScript

**URL:** <https://community.homey.app/t/advanced-flow-and-homeyscript/74196>\
**Category:** Questions & Help\
**Tags:** advancedflow\
**Created:** [December 27, 2022, 4:00pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196 "2022-12-27T16:00:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamster](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hamster/32/16580_2.png) [@Hamster](https://community.homey.app/u/Hamster)\
**Post date:** [December 27, 2022, 4:00pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/1 "2022-12-27T16:00:07Z")

</div>

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** ”.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/e/1ed0ad24269af13046a1c53994909aba2c0dddea.png)

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?

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [December 27, 2022, 4:46pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/2 "2022-12-27T16:46:26Z")

</div>

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/3/d32cda5e2c415eecb867a3f66b901f8694e1063b.png)

Here you can call a script by his name.

---

<div class="post-metadata">

**Author:** ![Hamster](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hamster/32/16580_2.png) [@Hamster](https://community.homey.app/u/Hamster)\
**Post date:** [December 27, 2022, 5:05pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/3 "2022-12-27T17:05:19Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [December 27, 2022, 5:22pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/4 "2022-12-27T17:22:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hamster](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hamster/32/16580_2.png) [@Hamster](https://community.homey.app/u/Hamster)\
**Post date:** [December 27, 2022, 5:37pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/5 "2022-12-27T17:37:27Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/1/c1f5a9ea553e8273f71d5c71cf745a7f87927cd6.png)

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [December 27, 2022, 5:42pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/6 "2022-12-27T17:42:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [December 27, 2022, 6:12pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/7 "2022-12-27T18:12:28Z")

</div>

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

`await tag("tagName", variable);`

This tag you can use in the following AdvancedFlow card.

---

<div class="post-metadata">

**Author:** ![homeypro](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/homeypro/32/51936_2.png) [@homeypro](https://community.homey.app/u/homeypro)\
**Post date:** [April 7, 2023, 12:58pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/8 "2023-04-07T12:58:26Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [April 7, 2023, 8:28pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/9 "2023-04-07T20:28:42Z")

</div>

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

![Screenshot from 2023-04-07 22-26-26](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/4/94f07d74fcf24f03e4d06db1df37adbaf44c42b2.png)

---

<div class="post-metadata">

**Author:** ![homeypro](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/homeypro/32/51936_2.png) [@homeypro](https://community.homey.app/u/homeypro)\
**Post date:** [April 7, 2023, 8:44pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/10 "2023-04-07T20:44:05Z")

</div>

@Peter_Kawa Exactly! Any objections to why this is not a good idea?  
 ![afex](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/3/531460e4e64edb768438bc283f339889db06196b.png)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [April 7, 2023, 9:12pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/11 "2023-04-07T21:12:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Eko\_taas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/eko_taas/32/74256_2.png) [@Eko\_taas](https://community.homey.app/u/Eko_taas)\
**Post date:** [February 5, 2025, 7:16pm UTC](https://community.homey.app/t/advanced-flow-and-homeyscript/74196/12 "2025-02-05T19:16:11Z")

</div>

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):

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/d/adaa19ab6d7e8e654ade4c295672168ae08d1f87.png)

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)
