# \[APP\]\[Pro\] HomeyScript

**URL:** <https://community.homey.app/t/app-pro-homeyscript/854>\
**Category:** Apps\
**Tags:** app, homey-pro\
**Created:** [August 30, 2018, 7:34am UTC](https://community.homey.app/t/app-pro-homeyscript/854 "2018-08-30T07:34:20Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![mats\_karlsson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mats_karlsson/32/7887_2.png) [@mats\_karlsson](https://community.homey.app/u/mats_karlsson)\
**Post date:** [March 24, 2019, 12:50pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/21 "2019-03-24T12:50:40Z")

</div>

thanks Volkov now I just need to understand it I got an error because of measure null and after put in a consol log I found that it was two unit that diden’t exist in reality it had a problem with.  
question how can one found out the capoability of a device?  
for examle as simple as temp on a xiaomi device.

---

<div class="post-metadata">

**Author:** ![Volkov](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/volkov/32/4664_2.png) [@Volkov](https://community.homey.app/u/Volkov)\
**Post date:** [March 24, 2019, 2:04pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/22 "2019-03-24T14:04:44Z")

</div>

You should have all the capabilities with their current values in device.capabilitiesObj. Try to log that to the console for your device and you will see the values.

---

<div class="post-metadata">

**Author:** ![DaneedeKruyff](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/daneedekruyff/32/964_2.png) [@DaneedeKruyff](https://community.homey.app/u/DaneedeKruyff)\
**Post date:** [March 24, 2019, 3:26pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/23 "2019-03-24T15:26:36Z")

</div>

A device that is not ready will not have a capabilitiesObj and can very well cause the error.

---

<div class="post-metadata">

**Author:** ![mats\_karlsson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mats_karlsson/32/7887_2.png) [@mats\_karlsson](https://community.homey.app/u/mats_karlsson)\
**Post date:** [March 24, 2019, 4:30pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/24 "2019-03-24T16:30:50Z")

</div>

> [@Volkov](#):
>
> device.capabilitiesObj

Now it feels a lot better a real jumpstart to get all capabilities. thanks for a fast response.  
add my smsall program that list all devices capabilities  
// list capabilityes  
let devices = await Homey.devices.getDevices();

Object.values(devices).forEach(device =\> {  
//write out name of device and all the capabilities  
console.log(device.name, device.capabilitiesObj);  
});

---

<div class="post-metadata">

**Author:** ![Ludwig\_Hallgren](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ludwig_hallgren/32/10694_2.png) [@Ludwig\_Hallgren](https://community.homey.app/u/Ludwig_Hallgren)\
**Post date:** [May 14, 2019, 12:39pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/25 "2019-05-14T12:39:27Z")

</div>

To use logic variabels you use code like this  
let Logic = await Homey.logic.getVariables()  
console.log(Logic);

#### updateVariable

await Homey.logic.updateVariable({id: yourid, variable: yourVar})

You have access to the API [https://developer.athom.com/docs/api](https://developer.athom.com/docs/api)  
so Homey.whatyouwannareach gives alot of options. send me a question if you need more help.

---

<div class="post-metadata">

**Author:** ![gagga](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gagga/32/14149_2.png) [@gagga](https://community.homey.app/u/gagga)\
**Post date:** [May 18, 2019, 9:10pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/26 "2019-05-18T21:10:08Z")

</div>

How do I get the id if I only know the name of the variable?

---

<div class="post-metadata">

**Author:** ![Ludwig\_Hallgren](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ludwig_hallgren/32/10694_2.png) [@Ludwig\_Hallgren](https://community.homey.app/u/Ludwig_Hallgren)\
**Post date:** [May 19, 2019, 5:15am UTC](https://community.homey.app/t/app-pro-homeyscript/854/27 "2019-05-19T05:15:16Z")

</div>

Use get function and console log it. That will give you the I’d

---

<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:** [May 19, 2019, 11:43am UTC](https://community.homey.app/t/app-pro-homeyscript/854/28 "2019-05-19T11:43:50Z")

</div>

> [@gagga](#):
>
> How do I get the id if I only know the name of the variable?

let devices = await Homey.devices.getDevices();  
\_.forEach(devices, device =\> {  
console.log(device.name, ’ ',device.id);  
});

---

<div class="post-metadata">

**Author:** ![gagga](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gagga/32/14149_2.png) [@gagga](https://community.homey.app/u/gagga)\
**Post date:** [May 19, 2019, 7:20pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/29 "2019-05-19T19:20:42Z")

</div>

This is for devices. Need this for logic variables.

---

<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:** [May 19, 2019, 7:54pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/30 "2019-05-19T19:54:30Z")

</div>

@gagga Sorry, I did not read well, but how about this:

> [@Ludwig\_Hallgren](#):
>
> let Logic = await Homey.logic.getVariables()  
> console.log(Logic);

Did you try this?

Or go to: [Homey Developer Tools](https://developer.athom.com/tools/api-playground)  
and add a new line: _Homey.logic.getVariables();_ and press Run 😊

---

<div class="post-metadata">

**Author:** ![mirius](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mirius/32/12478_2.png) [@mirius](https://community.homey.app/u/mirius)\
**Post date:** [May 26, 2019, 4:40pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/31 "2019-05-26T16:40:51Z")

</div>

Hi.

Does the HomeyScript “Run a script with an argument” (in Flow) support passing multiple arguments or only one?

Thank you.

---

<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:** [May 26, 2019, 5:22pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/32 "2019-05-26T17:22:27Z")

</div>

Have a look at the old forum, if I remember well, there was an example:

> **[HomeyScript - share your scripts - main discussion topic](https://forum.athom.com/discussion/3666/homeyscript-share-your-scripts-main-discussion-topic)**
>
> HomeyScript Write scripts for Homey, for when the Flow Editor might not be enough. App store link: HomeyScript App 

---

<div class="post-metadata">

**Author:** ![gagga](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gagga/32/14149_2.png) [@gagga](https://community.homey.app/u/gagga)\
**Post date:** [May 26, 2019, 8:07pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/33 "2019-05-26T20:07:38Z")

</div>

I can get the id this way.  
I also need to get a bunch of variables by their NAME. Any idea how to get the variable Id from a call to getVariables();?

---

<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:** [May 26, 2019, 11:17pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/34 "2019-05-26T23:17:51Z")

</div>

> [@JPe4619](#):
>
> Homey.logic.getVariables();

All I know is from reading and copy - past the examples on this forum and the old forum, search, combine, test and get wiser.

---

<div class="post-metadata">

**Author:** ![tampiss](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tampiss/32/11950_2.png) [@tampiss](https://community.homey.app/u/tampiss)\
**Post date:** [June 13, 2019, 10:30am UTC](https://community.homey.app/t/app-pro-homeyscript/854/35 "2019-06-13T10:30:14Z")

</div>

> [@Ludwig\_Hallgren](#):
>
> await Homey.logic.updateVariable({id: yourid, variable: yourVar})

Hi, any chance to explain or even better provide an example of how to use/modify this **await Homey.logic.updateVariable({id: yourid, variable: yourVar})**?

I have add the ID: something like dfb4ab9b-c711-4… but I do not know, how to modify the **variable** parametr…

If I add variable=“xy” I get **An unkown error has occured [invalid\_json]**  
If I try to add params inside the variable such name, value etc… I get **You have no access to do this.**

Thank you very much, M

---

<div class="post-metadata">

**Author:** ![Slof](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/slof/32/1318_2.png) [@Slof](https://community.homey.app/u/Slof)\
**Post date:** [June 25, 2019, 11:39am UTC](https://community.homey.app/t/app-pro-homeyscript/854/36 "2019-06-25T11:39:53Z")

</div>

Why will this script doens’t disable all my Apps as a test?

// Restart apps in case of crash  
console.log(“Start”);

let apps = await Homey.apps.getApps();  
crash = false;

\_.forEach(apps, app =\> {

```
//For test
console.log(app.name);
console.log(app.id);
console.log(app.state);
Homey.apps.disableApp({id: app.id});
//End test

if(app.crashed == false) return;
console.log("App crashed, restart...");
//Homey.apps.restartApp(app.name);
crash = true;

```

});

console.log(“Done”);

return crash;

---

<div class="post-metadata">

**Author:** ![Satoer](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/satoer/32/38113_2.png) [@Satoer](https://community.homey.app/u/Satoer)\
**Post date:** [July 1, 2019, 7:58pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/37 "2019-07-01T19:58:31Z")

</div>

Here’s is some code that might help other diggers for data. especially the retrieving of tokens (which also contain Better Logic variables) which syntax is changed in the past (Homey 2.0?). It’s only outputting the names (To quickly see the contents), but if you want to see the complete object with all the data, uncomment the console log code:

```
// Log everything

console.log('-------------APPS----------');
let apps = await Homey.apps.getApps();
_.forEach(apps, app => {
       console.log(app.name);
    });
//console.log(apps);

console.log('-------------TOKENS----------');
let tokens = await Homey.flowToken.getFlowTokens();
_.forEach(tokens, token => {
       console.log(token.title+': '+token.value);
    });
//console.log(tokens);

console.log('-------------DEVICES----------');
let devices = await Homey.devices.getDevices();
_.forEach(devices, device => {
       console.log(device.name);
    });
//console.log(devices);

console.log('-------------FLOWS----------');
let flows = await Homey.flow.getFlows();
_.forEach(flows, flow => {
       console.log(flow.name);
    });
//console.log(flows);

console.log('-------------ZONES----------');
let zones = await Homey.zones.getZones();
_.forEach(zones, zone => {
       console.log(zone.name);
    });
//console.log(zones);  

console.log('-------------LOGIC----------');
let logics = await Homey.logic.getVariables()
_.forEach(logics, logic => {
       console.log(logic.name);
});
//console.log(logics);
```

---

<div class="post-metadata">

**Author:** ![josjg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/josjg/32/12397_2.png) [@josjg](https://community.homey.app/u/josjg)\
**Post date:** [July 26, 2019, 4:22pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/38 "2019-07-26T16:22:46Z")

</div>

Hello,

I cannot get the [https://homeyscript.homey.app/](https://homeyscript.homey.app/) page to work. I says “Homey offline” while my Homey is definitely online! The page gives the following error in the console:  
Failed to load resource: the server responded with a status of 401 ()

The sample scripts do not appear on the screen, but they can be selected in flows. However, the ones that are supposed to log to the console, don’t log to the console.

Am I missing something?

---

<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:** [July 26, 2019, 6:01pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/39 "2019-07-26T18:01:14Z")

</div>

Log out and log back in again?

---

<div class="post-metadata">

**Author:** ![josjg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/josjg/32/12397_2.png) [@josjg](https://community.homey.app/u/josjg)\
**Post date:** [July 27, 2019, 10:16am UTC](https://community.homey.app/t/app-pro-homeyscript/854/40 "2019-07-27T10:16:28Z")

</div>

Thanks, worked! I feel a little stupid…

[Previous page](https://community.homey.app/t/app-pro-homeyscript/854.md?page=1)

[Next page](https://community.homey.app/t/app-pro-homeyscript/854.md?page=3)
