# Homeyscript functionality

**URL:** <https://community.homey.app/t/homeyscript-functionality/30066>\
**Category:** Questions & Help\
**Tags:** flow\
**Created:** [May 18, 2020, 9:52am UTC](https://community.homey.app/t/homeyscript-functionality/30066 "2020-05-18T09:52:41Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_van\_de\_Schuur](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/frank_van_de_schuur/32/35882_2.png) [@Frank\_van\_de\_Schuur](https://community.homey.app/u/Frank_van_de_Schuur)\
**Post date:** [May 18, 2020, 9:52am UTC](https://community.homey.app/t/homeyscript-functionality/30066/1 "2020-05-18T09:52:41Z")

</div>

I’m struggling regularly with the shortcomings of the homey flows. For instance the lack of **nested if** or **elsif** functionality has driven me to several workarounds.  
Also not being to control **float** and **integer** has driven me nuts.  
Now I understood that Homeyscript should solve that and I am trying to understand how it works. Is for instance the below assumption true?  
I can have a flow triggered by an event(eg variable changing or a time) then execute a script in which I have access to **all** variables and device parameters which are also available in Homey Flow. Use these in **if then else** statements and write values to it like in Homey flow

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [May 18, 2020, 10:19am UTC](https://community.homey.app/t/homeyscript-functionality/30066/2 "2020-05-18T10:19:22Z")

</div>

AFAIK you don’t have access to variables, unless you pass them as argument to the Homeyscript. Getting device capability values is possible, not sure if you can _set_ them though.

---

<div class="post-metadata">

**Author:** ![johan\_bendz](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/johan_bendz/32/10344_2.png) [@johan\_bendz](https://community.homey.app/u/johan_bendz)\
**Post date:** [May 18, 2020, 11:45am UTC](https://community.homey.app/t/homeyscript-functionality/30066/3 "2020-05-18T11:45:45Z")

</div>

Sure you can 🙂

let flowTokens = await Homey.flowToken.getFlowTokens();  
console.log(flowTokens);

let variables = await Homey.logic.getVariables();  
console.log(variables);

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [May 18, 2020, 12:06pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/4 "2020-05-18T12:06:15Z")

</div>

Nice, thanks for the correction 😃

---

<div class="post-metadata">

**Author:** ![Frank\_van\_de\_Schuur](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/frank_van_de_schuur/32/35882_2.png) [@Frank\_van\_de\_Schuur](https://community.homey.app/u/Frank_van_de_Schuur)\
**Post date:** [May 18, 2020, 12:18pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/5 "2020-05-18T12:18:27Z")

</div>

Nice indeed. I’m going to play around with it.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![BartOverdevest](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bartoverdevest/32/38783_2.png) [@BartOverdevest](https://community.homey.app/u/BartOverdevest)\
**Post date:** [April 1, 2021, 11:06pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/6 "2021-04-01T23:06:13Z")

</div>

> Sure you can 🙂
> 
> let flowTokens = await Homey.flowToken.getFlowTokens();  
> console.log(flowTokens);

@johan_bendz  
How can i read the value of a specific token within flowTokens, if i know the id?

I would like to write a tag / flow token using **await tag(“TageName”,value)**  
and use your method to read them back.

Bart

---

<div class="post-metadata">

**Author:** ![johan\_bendz](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/johan_bendz/32/10344_2.png) [@johan\_bendz](https://community.homey.app/u/johan_bendz)\
**Post date:** [April 2, 2021, 11:55am UTC](https://community.homey.app/t/homeyscript-functionality/30066/7 "2021-04-02T11:55:03Z")

</div>

You will have to select the token uri and id like this:

```
  await Homey.flowToken.getFlowTokens().then(function(tokens) {
    for (let token in tokens) {
      if ( tokens[token].uri == "homey:manager:weather" && tokens[token].id == "state" ) {
        var mytoken = tokens[token].value;
        console.log(mytoken);
      }
    }
  }).catch(console.error);
```

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [April 2, 2021, 1:27pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/8 "2021-04-02T13:27:07Z")

</div>

Is it also possible to change the value and save it. It is possible with better logic, would be nice if it is also possible with logic

---

<div class="post-metadata">

**Author:** ![johan\_bendz](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/johan_bendz/32/10344_2.png) [@johan\_bendz](https://community.homey.app/u/johan_bendz)\
**Post date:** [April 2, 2021, 2:06pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/9 "2021-04-02T14:06:35Z")

</div>

If you want to work with Homey Logic’s variables they are found here: Homey.logic.getVariables()

To work with tokens in other apps this is a short guide:

// Define the token you want to add to the app  
let tokenName = “mytoken”;  
let tokenValue = 12345;  
// Define the app you want to add the token to  
let tokenApp = “net.i-dev.betterlogic”;  
// get the current tokens from the app  
let token = await Homey.apps.getApp({id:tokenApp});  
// save the new token to the app  
token.apiPut("/" + tokenName + “/” + tokenValue );  
// write the output info  
console.log(“The token: “+tokenName+” saved to app “+tokenApp+” with the value:”+tokenValue);

---

<div class="post-metadata">

**Author:** ![Torch1969](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/torch1969/32/33305_2.png) [@Torch1969](https://community.homey.app/u/Torch1969)\
**Post date:** [April 2, 2021, 2:14pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/10 "2021-04-02T14:14:44Z")

</div>

Or use the getFlowToken of getVariable function?

```
const FlowToken = await Homey.flowToken.getFlowToken({uri: '<uri here>', id: '<id here>'});
console.log(FlowToken.value);

const Variable = await Homey.logic.getVariable({id: '<id-here>'});
console.log(Variable.value);
```

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [April 2, 2021, 2:16pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/11 "2021-04-02T14:16:57Z")

</div>

thx Johan, i already use better logic “net-i-dev.betterlogic” but what should i use when i want to save them in homey logic. com.athom.logic?

---

<div class="post-metadata">

**Author:** ![johan\_bendz](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/johan_bendz/32/10344_2.png) [@johan\_bendz](https://community.homey.app/u/johan_bendz)\
**Post date:** [April 2, 2021, 3:04pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/12 "2021-04-02T15:04:47Z")

</div>

> [@Torch1969](#):
>
> Or use the getFlowToken of getVariable function?

Yes, that works too. Many ways to do this. : )

---

<div class="post-metadata">

**Author:** ![BartOverdevest](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bartoverdevest/32/38783_2.png) [@BartOverdevest](https://community.homey.app/u/BartOverdevest)\
**Post date:** [April 3, 2021, 9:15am UTC](https://community.homey.app/t/homeyscript-functionality/30066/13 "2021-04-03T09:15:04Z")

</div>

I posted the question on GitHub as well and this is Jeroen Wienk’s answer. I thought good to share here because “there are many ways to do this’ 😀 and because as Jeroen mentioned values are cached and he gives the solution to circumvent this.

> It’s possible with the API but it’s not a very clear solution since the values are cached. But you can do this;
> 
> ```
> await tag('my-tag', false);
> 
> // value is false
> console.log(await Homey.flowToken.getFlowToken({
> uri: 'homey:app:com.athom.homeyscript',
> id: 'my-tag'
> }));
> 
> await tag('my-tag', true);
> 
> // value is false (cached)
> console.log(await Homey.flowToken.getFlowToken({
> uri: 'homey:app:com.athom.homeyscript',
> id: 'my-tag'
> }));
> 
> // value is true (skipped cache)
> console.log(await Homey.flowToken.getFlowToken({
> $skipCache: true,
> uri: 'homey:app:com.athom.homeyscript',
> id: 'my-tag'
> }));
> 
> ```
> 
> Notice the last call with `$skipCache`.

So apparently it depends on the use case if you want to call the value between multiple executions or call the value you just updated within the script.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [April 3, 2021, 9:43am UTC](https://community.homey.app/t/homeyscript-functionality/30066/14 "2021-04-03T09:43:05Z")

</div>

Too bad this isn’t documented anywhere ☹ But thanks for letting us know!

---

<div class="post-metadata">

**Author:** ![thomasschadron](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/thomasschadron/32/33929_2.png) [@thomasschadron](https://community.homey.app/u/thomasschadron)\
**Post date:** [August 8, 2021, 6:03pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/15 "2021-08-08T18:03:48Z")

</div>

Hello, could you elaborate on passing a variable (string, integer) to Homeyscript? Could you show an example?

---

<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:** [August 8, 2021, 8:42pm UTC](https://community.homey.app/t/homeyscript-functionality/30066/16 "2021-08-08T20:42:30Z")

</div>

Use the card " start a script with an argument "

> [@How to get the Arguments from the flow into your script?](https://community.homey.app/t/how-to-get-the-arguments-from-the-flow-into-your-script/23888):
>
> Busy on a script and found out one can run a script from a flow and give the card arguments. I cannot find out how these arguments can be fetched in the script? Can someone help me out?
