# \[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:** 3

<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 27, 2019, 10:19am UTC](https://community.homey.app/t/app-pro-homeyscript/854/41 "2019-07-27T10:19:15Z")

</div>

Don’t, because it also took me a while to find this out. Instead of showing “Expired session, please log back in again” (or something), Athom have chosen to show a confusing error that doesn’t necessarily reflect the actual cause of the problem.

---

<div class="post-metadata">

**Author:** ![Sander\_Vlotman](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_vlotman/32/7855_2.png) [@Sander\_Vlotman](https://community.homey.app/u/Sander_Vlotman)\
**Post date:** [August 31, 2019, 9:34am UTC](https://community.homey.app/t/app-pro-homeyscript/854/42 "2019-08-31T09:34:03Z")

</div>

Hi, I would like to modify a string that i retrieve via IFTT and RSS that i store in a variabele This string containing a unique number for the mp4 of the 20.00 NOS news. [https://nos.nl/b/43885](https://nos.nl/b/43885) now I want to get that number from this string so need to remove a part of the string ([https://nos.nl/b/](https://nos.nl/b/)). I’m trying to do this with homey script where i’m able to update variables but not able to retrieve the value of an exsiting variable. Maybe doing it via using an argument with the homey scriptcard where I can enter an argument but do’nt know how to get that to work. Als removing a part of a string might be a challange so if you know how to write that part that is welcome as well.  
Some help or examples are welcome. I will then share my project with the NOS chromecast feed app that no longer works.

---

<div class="post-metadata">

**Author:** ![ropske](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ropske/32/16716_2.png) [@ropske](https://community.homey.app/u/ropske)\
**Post date:** [January 1, 2020, 3:13pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/43 "2020-01-01T15:13:13Z")

</div>

I think only 1 argument is possible ☹

---

<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:** [January 2, 2020, 4:15pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/44 "2020-01-02T16:15:15Z")

</div>

In the old forum, there is something that maybe you can use:

> **[HomeyScript - share your scripts - main discussion topic - Page 2](https://forum.athom.com/discussion/comment/61291/#Comment_61291)**
>
> HomeyScript can possibly change the need to have Apps installed for all kinds of functionality. Getting the scripts to work is not the hardest part.

---

<div class="post-metadata">

**Author:** ![Jonas\_Hagh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonas_hagh/32/17079_2.png) [@Jonas\_Hagh](https://community.homey.app/u/Jonas_Hagh)\
**Post date:** [February 7, 2020, 7:25pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/45 "2020-02-07T19:25:59Z")

</div>

Those who have developed HomeyScript will have to share which Apies are available from HomeysWEBApi and what difference there is in their syntax.  
Right now the App is totally useless for writing anything other than logical requests to Homey, if you want to access several “deeper” functions then you are completely alone  
From version 2.0 of Homey a lot has happened with how to change values of “boolean values” type off / on

If you go to GitHub and look at the project they seem to have died out …

Really need a powerful scripting language with well-documented APIs for Homey because it’s basically a very good product

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [February 7, 2020, 7:36pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/46 "2020-02-07T19:36:28Z")

</div>

> [@Jonas\_Hagh](#):
>
> Those who have developed HomeyScript will have to share which Apies are available from HomeysWEBApi and what difference there is in their syntax.

Afaik everything is documented here:  
[https://developer.athom.com/docs/api](https://developer.athom.com/docs/api)

Do you have examples what is not working?

---

<div class="post-metadata">

**Author:** ![Jonas\_Hagh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonas_hagh/32/17079_2.png) [@Jonas\_Hagh](https://community.homey.app/u/Jonas_Hagh)\
**Post date:** [February 7, 2020, 9:37pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/48 "2020-02-07T21:37:15Z")

</div>

How should I translate this into javascript that works in the javacript ?

 ![bild](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/b/2b31a3d9b4288e00110440523f2bc92ede6df4e2.png)

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [February 7, 2020, 9:43pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/49 "2020-02-07T21:43:50Z")

</div>

> [@Jonas\_Hagh](#):
>
> How should I translate this

Have you fe seen the Examples in:

> **[GitHub - athombv/com.athom.homeyscript: HomeyScript is a JavaScript-based...](https://github.com/athombv/com.athom.homeyscript)**
>
> HomeyScript is a JavaScript-based scripting language for Homey that empowers users to unleash their creativity. - GitHub - athombv/com.athom.homeyscript: HomeyScript is a JavaScript-based scripting...

---

<div class="post-metadata">

**Author:** ![Jonas\_Hagh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonas_hagh/32/17079_2.png) [@Jonas\_Hagh](https://community.homey.app/u/Jonas_Hagh)\
**Post date:** [February 7, 2020, 9:51pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/50 "2020-02-07T21:51:51Z")

</div>

have been there but have not found any advanced examples but only simple things, want a little more “deeper” clues “on how to access Homey” core "of knowledge  
Want to write more advanced scripts that come when an app but without having to become an app

---

<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:** [February 8, 2020, 7:34am UTC](https://community.homey.app/t/app-pro-homeyscript/854/51 "2020-02-08T07:34:09Z")

</div>

Homey script is pretty limited in what it is allowed to do in Homey.  
Example: it can only get devices, but not update any devices.  
So unless you can give an example what you are trying to do that is “advanced”, it is very hard for people to help you.

---

<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:** [February 8, 2020, 11:39am UTC](https://community.homey.app/t/app-pro-homeyscript/854/52 "2020-02-08T11:39:33Z")

</div>

> [@Caseda](#):
>
> Example: it can only get devices, but not update any devices.

It can’t update devices? But I am able to do things like turn the lights on/off change colours etc. with HomeyScript. Or isn’t that your definition of updating devices?

---

<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:** [February 8, 2020, 12:14pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/53 "2020-02-08T12:14:35Z")

</div>

you can? thought only by activating corresponding flows you could do that, not by updating other app’s devices, as it didn’t have the permission to do that.

---

<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:** [July 26, 2021, 4:27pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/54 "2021-07-26T16:27:42Z")

</div>

Hi everyone,

I used lots of examples, and tried all kinds of stuff.  
But how do I create a HomeyScript script from the web API playground “Find broken flows” script.

```auto
Homey.flow.getFlows().then(f => Object.values(f).reduce((r,b)=> Object.assign(r, b.broken ? {[b.name]:b.broken} : ''), {}) );

```

I can’t get my head around this cryptogram. So far I have this, but then… 🤓

```auto
await Homey.flow.getFlows(); 
var badflows = Homey.flow.getFlows();

await tag("BrokenFlows", badflows); //creating new HomeyScriptTag 'BrokenFlows'

console.log ("Broken flows: ", badflows);
return(true);

```

Returns: `❌ Script Error ⚠️ Error: invalid_type at Remote Process`

Anyone a hint or pointer?

---

<div class="post-metadata">

**Author:** ![Jero](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jero/32/17556_2.png) [@Jero](https://community.homey.app/u/Jero)\
**Post date:** [July 26, 2021, 4:30pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/55 "2021-07-26T16:30:52Z")

</div>

```auto
const flows = await Homey.flow.getFlows({ filter: { broken: true }});
console.log(flows)

```

---

<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:** [July 26, 2021, 4:32pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/56 "2021-07-26T16:32:04Z")

</div>

Thanks a million Jero!

---

<div class="post-metadata">

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

</div>

In case filter ever gets removed or something 😉

```auto
const flows = await Homey.flow.getFlows();
const brokenAsArray = Object.values(flows).filter(flow => flow.broken);

const brokenAsObj = {};
for (const flow of Object.values(flows)) {
  if (flow.broken) {
    brokenAsObj[flow.id] = flow;
  }
}

console.log(brokenAsArray);
console.log(brokenAsObj);

```

---

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

</div>

Thanks Jero, the output makes sense on the console.  
But…  
I want to send the output to f.i. my timeline and/or as push message.  
But then it only sais [object, Object],[object, Object],[object, Object],[object, Object], and so on. (I have 30+ broken flows, I am aware of that)  
This, because creating & filling a variable results in an error `invalid_type at Remote Process`

Only filling the variable is also fine with me, as long as I can display the names of the flows found somewhere.

```auto
// Script FindBrokenFlows2.js

const flows = await Homey.flow.getFlows();
const brokenAsArray = Object.values(flows).filter(flow => flow.broken);

const brokenAsObj = {};
for (const flow of Object.values(flows)) {
  if (flow.broken) {
    brokenAsObj[flow.id] = flow;
  }
}

// filling a variable does result in an console error: [Script Error: invalid_type at Remote Process]
// await tag("BrokenFlows", brokenAsArray ); // (create&)write tag "BrokenFlows" with results

console.log("Broken Flows:", brokenAsArray);
//console.log("Broken Flows:", brokenAsObj);

      // Timeline notification
      await Homey.flow.runFlowCardAction({
        uri: 'homey:manager:notifications',
        id: 'create_notification',
        args: {
          text: 'Broken Flows today: ' + brokenAsArray + ' [script: FindBrokenFlows2.js]'
          //text: '' + brokenAsArray + ''
        },
      });
      // Push msg to mobile phone
      await Homey.flow.runFlowCardAction({
        uri: 'homey:manager:mobile',
        id: 'push_text',
        args: {
			    user: {
			    name: 'Peter Kawa',
			    id: '6b333a3e-288a-4099-a0fb-f3903a605c74',
			    image: 'https://api.athom.com/user/xxxxxxxxxxxxxxxxxxxxxx/avatar',
			    athomId: 'xxxxxxxxxxxxxxxxxxxxxxxx',
		    	},
		    text: 'Broken Flows today: ' + brokenAsArray + ' [script: FindBrokenFlows2.js]'
        },
      });

```

Any hints?

 ![Screenshot_20210726-202452_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/a/aa8982146c23eb76830228d03b26b8e6b5965be7.jpeg)

---

<div class="post-metadata">

**Author:** ![tb1962](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tb1962/32/7888_2.png) [@tb1962](https://community.homey.app/u/tb1962)\
**Post date:** [July 26, 2021, 7:20pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/59 "2021-07-26T19:20:18Z")

</div>

You could do JSON.stringify(brokenAsArray) but that would result in an very long string. In case you are only interested in a list of flow names you can use to following:

```auto
const flows = Object.values(await Homey.flow.getFlows({filter: { broken: true }})).map(f => f.name)

```

In this case you don’t need JSON.stringify

---

<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:** [July 26, 2021, 7:23pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/60 "2021-07-26T19:23:47Z")

</div>

Thanks @tb1962 & @Jero  
Works like a charm now.

Script:

```auto
// Get broken flows and write result to a variable/tag

const flows = Object.values(await Homey.flow.getFlows({filter: { broken: true }})).map(f => f.name)

const flowsString = JSON.stringify(flows) // Create string [FlowString] from array [flows], so it can be written into variable "BrokenFlows"
await tag("BrokenFlows", flowsString ); // (create&)write variable/tag [BrokenFlows] with results of [FlowString]

// Just to check the results in HomeyScript console
// console.log("Broken Flows (Array):", flows);
// console.log("Broken Flows (String):", flowsString);

return (true);

```

Flow:

 ![findbrokenflows_flow](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/0/f013306dcf835728cceb542d444eb10ccbc3535c.png)

Timeline:

 ![Screenshot_20210727-011806_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/6/263fc8a8b18618b83804f412536343f6a67c5266.jpeg)

---

<div class="post-metadata">

**Author:** ![Peter\_Hendrix](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_hendrix/32/8090_2.png) [@Peter\_Hendrix](https://community.homey.app/u/Peter_Hendrix)\
**Post date:** [October 13, 2022, 10:43am UTC](https://community.homey.app/t/app-pro-homeyscript/854/61 "2022-10-13T10:43:52Z")

</div>

Only the names:  
const flows = await Homey.flow.getFlows({ filter: { broken: true }});

for (const flow of Object.values(flows)) {  
console.log(flow.name)  
}

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

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