# Trying to set a variable from a script, help needed

**URL:** <https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582>\
**Category:** Questions & Help\
**Tags:** homeyscript\
**Created:** [February 9, 2024, 9:11am UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582 "2024-02-09T09:11:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matteo\_Sulis](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/matteo_sulis/32/110774_2.png) [@Matteo\_Sulis](https://community.homey.app/u/Matteo_Sulis)\
**Post date:** [February 9, 2024, 9:11am UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582/1 "2024-02-09T09:11:52Z")

</div>

Hi,  
I’m trying to set a boolean variable from a script, that should be then used in flows.

I understood that I am supposed to set a tag and not a global variable.

So looking at examples i put:

await tag(‘aria\_inquinata’, aria\_inquinata);  
return("aria inquinata: "+aria\_inquinata);

The script returns the value, but the variable is not appearing under “variables” in the app and I can’t use it to trigger a flow. It does appear under the tags that can be selected in the “and” part.  
If I create a variable with the same name in the app, it doesn’t change value running the script.

So global variables, tags, and app variables are 3 different things? How can I write an app variable from a script? I there any comprehesive guide I can read?

Thanks!

---

<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:** [February 9, 2024, 3:07pm UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582/2 "2024-02-09T15:07:27Z")

</div>

You can find HomeyScript variables, when you make a flow and add a tag, scroll down untill HomeySctipt variables, like you do for device variables.

---

<div class="post-metadata">

**Author:** ![Matteo\_Sulis](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/matteo_sulis/32/110774_2.png) [@Matteo\_Sulis](https://community.homey.app/u/Matteo_Sulis)\
**Post date:** [February 9, 2024, 3:57pm UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582/3 "2024-02-09T15:57:32Z")

</div>

Yes thanks, but it doesn’t show up in the “variables” section of the Homey app, right? Is it possible to modify those variables in a script?

---

<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:** [February 9, 2024, 6:26pm UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582/4 "2024-02-09T18:26:29Z")

</div>

> [@Matteo\_Sulis](#):
>
> await tag(‘aria\_inquinata’, aria\_inquinata);

If it is not a boolean or numeric value, the var should be quoted  
As shown in the example scripts:

 ![Screenshot from 2024-02-09 19-19-24](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/d/ad69e2f1e485d4b29baef9ed55d1ca07f478cc06.png)

Yours should be adjusted it to:

```auto
await tag('aria_inquinata', '"' + aria_inquinata + '"');

```

or

```auto
await tag('aria_inquinata', `'${aria_inquinata}'`);

```

---

<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:** [February 9, 2024, 6:30pm UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582/5 "2024-02-09T18:30:41Z")

</div>

That will add _literal_ quotes, which is not what you want. Instead, use this:

```auto
await tag('aria_inquinata', String(aria_inquinata));

```

---

<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:** [February 9, 2024, 6:32pm UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582/6 "2024-02-09T18:32:30Z")

</div>

Ah yes I saw that happening, but didn’t know your trick yet 🫣

---

<div class="post-metadata">

**Author:** ![Matteo\_Sulis](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/matteo_sulis/32/110774_2.png) [@Matteo\_Sulis](https://community.homey.app/u/Matteo_Sulis)\
**Post date:** [February 9, 2024, 8:59pm UTC](https://community.homey.app/t/trying-to-set-a-variable-from-a-script-help-needed/103582/7 "2024-02-09T20:59:57Z")

</div>

aria\_inquinata is a variable in the js script with value true/false (boolean)
