Can running a script from a card create a tag?

Hi, I am trying to find a way to have a two way interaction from a flow card to a script and back.
I have tried the following card, but I am not able to get a tag created, based on the “No tags have been generated” comment, I am assuming that this card allows to get data back to the flow.
HomeyScript, Run with argument
Please let me know if you know what I might be doing wrong or perhaps other suggestions, I will also add the sample code for the script.
Thanks in advance.


See example-tag.js and use single quotes.

When you want to use the tag in a flow (with a logic card) it can be found under Homeyscript.tag.

Thank you, I’ll give that a try

It’s also possible to use the script as code in a HS flowcard like
Run your_code with argument and return [type]-tag

You can use your HS tag as argument, and have your script update that tag’s value

Thank you. Would you be able to show how in your code you return the tag and how you use it on another card?
In your code do you create a tag or do you use return ?
Cheers

Thank you, from a functionality point of view that worked, I have realised that this might have been working, but I am not sure why the “No tags have been generated” message appears.

I am lost. What did you try and what is your current problem. Did you noticed that Peter uses another card?
Maybe it is not an error message but an informational message, as there are two similar cards, one creating a tag and the other not.

Sure. Forgive me if I show things you already know, I just start at the starting point.

First create the desired tag with a one time script:

Screenshot from 2024-05-11 01-04-27


This way it shows the script output, and the tag value of ‘My_String’:


How to find and insert the HS tag ‘My_String’:
Screenshot from 2024-05-11 01-21-43


Now I can change the ‘My_String’ value with this “Then” action flowcard:

Screenshot from 2024-05-11 01-13-41


As example: when the input argument changes, the tag value changes:


The code I used in that flowcard:

// update homeyscript tag, dependent on input argument's value

// save the input argument to a script var
const myArgument = (args[0]);
// for testing only: comment line above, uncomment line below
//const myArgument = 'hello Picante';

// When the argument value was as expected
if (myArgument == 'just_a_new_value') { 

  // write new value to tag My_String
  await tag('My_String', 'hello Picante');
  return 'myArgument used: (' + myArgument + '), tag My_String is updated to: hello Picante';

}

// When an other argument value was as expected
if (myArgument == 'hello Picante') { 

  // write new value to tag My_String
  await tag('My_String', 'just_a_new_value');
  return 'myArgument used: (' + myArgument + '), tag My_String is updated to: just_a_new_value';

}

// end
1 Like

That’s awesome, thank you.

1 Like

Thank you both for taking the time to reply.

1 Like

My learnings summary:
if this helps anyone (Thanks @Peter_Kawa & @Rmb, please let me know if you think any of this is not accurate ):

  • How do you create a script and return a value to be used on another card?
    • I will be using the following method, there are pros & cons for different approaches, because I believe is creates less of a management overhead in some areas and it means that I do not need to create and maintain a Tag, this one only needs to be used locally. The following also appears to show me the returned value for the script on the card when I run it from the flows screen, I was not able to get this working another way.

Method:

  1. Add a card of under HomeyScript of type “Run with and return <Number_Yes/No_Text-tag>” The type depend on the data type value that you expect your script to return.

  2. Add your script to the card, and include a return value, my example is simply returning the value that I send in as an Argument, in my example is “Gracias Amigos!!!”

  3. To fully show showcase the capability. I created a Push notification card (purely for testing).

  4. Create a connector from the Script card to another card where you want to use the output of the script. (It is CRITICAL, that you add a connector or you will not be able to see the Result tag.)

  5. In the card that you linked the script to (where you want to use the script’s output, select the Tag from the “This Flow” section. )

  6. If you’d like to see the result, run the flow (using the play button), then mouse over the blue line on the bottom of the script card to see the result.

Screenshots:

  1. (no need to show this, easy)

  2. (no need to show how to create this, but showing the difference if a connector is present or not, showing that one will allow the selection of the Tag and without the link the Tag will not be available)


  1. (no need to show again, shown above )

  2. Show the result value on the card.