HomeyScript: Any sane ways to use args?

I agree, in HomeyScript it is much more readable, but i wouldn’t agree that writing a JSON in the HS argument textfield is really more readable.

But like i said, i personally want a fullproof method, so i just created an app:
[APP][Pro] JSON Handler and Manipulator - Apps - Homey Community Forum

@Articate let me know if you can use it and if you would need more in it.
(It is still in review so not available yet)

What’s the intended use case? It looks very daunting, since it has a lot of possibly redundant input fields. I understand that it’s probably impossible to write that dynamically. Looks easier to simply create a JSON-object from a JS-object or simply text string, but that might be down to my experience.

The intended use case is building a JSON to be parsed to for example HomeyScript, without having to place a Card for every single JSON Property, but in a way that is fullproof.

The redundant input fields are optional, no need to be set.
Just like in [APP][Pro] Advanced Triggers or in H.O.O.P. (Hope) - Homey Object Oriented Programming.

Here is a use case for your question as answered by @Adrian_Rockall (message 4).

No more need to watch the quotes :wink:

2 Likes

I don’t get a boolean thrugh like above made, only getting a “x” when I print it to the log.

If i do it like this, it returns the boolean just like it should:

Perhaps share your flow?

Uh, I feel like an idiot, but whenever I try to write a homeyscript either directly in a flow, or create a script… I dont have that top block you ahve where you define the args? Am I missing something?

With the Adv.flow Then card: Homeyscript - Run code with Argument and return X-tag

Trying to make a script to switch on a light directly with arguments dim and color, now in the advanced flows this costs me 2 ‘then’ cards, I was hoping to do this with 1 script call like underneath but sofar no luck getting anything to work (I am a machine programmer so these functions are really easy on a PLC, but for some reason it must be complicated in java :-))
image
Result:
image

Any idea how to solve this much appreciated

String-type values need to be quoted:

{"name":"Bijkeuken","dim":50,"color":75}

I actually already tried that, but then I get this error:
image
(simplified to only use 1 arg for test)

EDIT: script itself was incorrect, had to separate device from the list of devices, think it will work now, thanks

is there a way to see what went in the log? since I have to run the script from a flow, I do not really see the result now

Not sure what you mean, but you can always implement a simple tester:

let arg = args[0] || '{"name":"Bijkeuken"}';
let myArgs = JSON.parse(arg);
...

I meant as long as you can run the script directly you can log to the console to see if it gives the result you wanted. However when you have to run the script from a flow, the console isn’t visible afaik, so then I don’t see if it has the correct result.

What exactly should your last code do? I do not quite understand it sorry

Homey doesn’t have (accessible) logfiles for most things, Homeyscript included. So the only way to see if a script runs correctly is to hardcode some test data into it and run it manually.

If args[0] isn’t defined, it will use a fixed string as input. That’s how you can test your script manually.

thanks will try a bit more, still got a lot to learn :slight_smile:

@Arjan_Neet:
In a normal running flow, you can catch errors like this:
Screenshot from 2024-03-13 10-45-43

I use Simple Log, but you could use a timeline card, or push message, stuff like that.

thanks :slight_smile: