HomeyScript newby question(s)

Dear all,

I am trying to use a HomeyScript in an advanced flow, but I do not even get a first simple script running. The documentation is far from clear, so I looking for some help, hopefully some very simple things that I overlook.

When at https://my.homey.app I select the </> button on the left, and here I have several example script that are marked as classic (i.e. using the deprecated API version). I have created a new script, which is not marked as such, so that is great. However, when I try to call a simple Homey.flow.runFlowCardCondition or Homey.flow.runFlowCardAction I get errors all the time.

For instance, when using

let result = await this.Homey.flow.runFlowCardCondition({
  uri: 'homey:manager:cron',
  id: 'day_equals',
  args: {
    day: 6, // for Saturday
  },
});
log(result);

gives, when running the script, a script error, and no log. What am I doing wrong?
When I remove the await, I get a

Promise { <pending> }

in the log, which is also unwanted, and the result is undefined.

Hope someone can help.

Can you start by editing your post, and format the code as code?
Use the </> icon,
Or
Add ``` as first and last line.

Why?
To avoid errors like using fancy qoutes,

which make scripts error.
Only straight quotes ' " and back ticks `
are allowed

Done. Thanks for that tip. :slightly_smiling_face:

1 Like

Next tip:

As ‘new’ script, you’d use it this way (and leave out this from this.Homey.fl ...):

const { result: isSaturday } = await Homey.flow.runFlowCardCondition({
  // uri: 'homey:manager:cron', // classic script code only!
  id: 'homey:manager:cron:day_equals', // 'new' script code (uri and id are now combined)
  args: {
    day: 6,
  },
});

log('Is Saturday:', isSaturday);

Result:

Oh, and about:

It’s because a line with something like

try {
  let result = riskyOperation(); 
  return result;
} catch (error) {
  // Handle the error and include it in the result
  return { success: false, message: error.message };
}

isn’t there.
You’d add it yourself.


Classic to ‘new’ Homeyscript migration:

Thanks for the - indeed simple - solution!
I read the text you refer to, but did not understand that it required me to add the uri to the id; I simply removed the uri argument, but that did not work.

1 Like

YW.
I also didn’t get it at first, how should it ever work without uri…
it finally worked by trying different combinations of uri and id as id.

You’re absolutely right about documentation not being clear at certain points

The documentation isn’t just unclear, it’s just plain wrong. For this method, it shows that both id and uri are required parameters:

(I won’t be able to say that Athom doesn’t care about maintaining documentation, at the risk of this post being removed because it’s “too negative”, so I will refrain from saying so)

1 Like

Just rephrase it: “apparently somehow it slipped past Athom’s test team, which has to approve the documentation” :face_with_peeking_eye::grimacing:

But don’t tell me posts (can) get removed when you show and explain what’s wrong?

And imho it’s not helping there’s no
timestamps / versioning / author initials, and last but not least no ordinairy “comments” section, to have the improvement ideas right where the issue is.

I’ve had posts removed when I pointed out that it felt like Athom seemed perhaps somewhat less motivated to improve certain parts of Homey that are known, and have been known for a long time, to be um “problematic” :man_shrugging:t3:

The various Github repositories that are used to “track” issues with the SDK or Web API are filled with comments that point out incorrect and/or insufficient documentation.

1 Like