[APP][Pro] HomeyScript

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.

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 now I want to get that number from this string so need to remove a part of the string (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.

I think only 1 argument is possible :frowning:

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

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

Afaik everything is documented here:
https://developer.athom.com/docs/api

Do you have examples what is not working?

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

Have you fe seen the Examples in:

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

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.

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?

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.

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.

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… :nerd_face:

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?

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

Thanks a million Jero!

In case filter ever gets removed or something :wink:

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);
1 Like

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.

// 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?

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:

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

In this case you don’t need JSON.stringify

2 Likes

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

Script:

// 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:

Timeline:

1 Like

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

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