# HomeyScript: Any sane ways to use args?

**URL:** <https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178>\
**Category:** Questions & Help\
**Tags:** homeyscript\
**Created:** [July 17, 2022, 10:09pm UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178 "2022-07-17T22:09:03Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [July 21, 2022, 9:14am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/21 "2022-07-21T09:14:21Z")

</div>

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](https://community.homey.app/t/app-pro-json-handler-and-manipulator/66317)

@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)

---

<div class="post-metadata">

**Author:** ![Articate](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/articate/32/57311_2.png) [@Articate](https://community.homey.app/u/Articate)\
**Post date:** [July 21, 2022, 9:42am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/22 "2022-07-21T09:42:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [July 21, 2022, 10:11am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/23 "2022-07-21T10:11:07Z")

</div>

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](https://community.homey.app/t/app-pro-advanced-triggers-trigger-and-action-cards-with-eventname-for-advanced-flows/65651) or in [H.O.O.P. (Hope) - Homey Object Oriented Programming](https://community.homey.app/t/h-o-o-p-hope-homey-object-oriented-programming/43709).

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [July 21, 2022, 4:23pm UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/24 "2022-07-21T16:23:06Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/8/d8f8e660154f65c739e42ccad7481a8b8c281a75.png)

No more need to watch the quotes 😉

---

<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:** [May 30, 2023, 4:38pm UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/25 "2023-05-30T16:38:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [May 30, 2023, 6:06pm UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/26 "2023-05-30T18:06:59Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/a/aa23ca900e48ca207d1795f68ca2c6ee480b63d9.png)

Perhaps share your flow?

---

<div class="post-metadata">

**Author:** ![Aleksander\_Stalsberg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/aleksander_stalsberg/32/71121_2.png) [@Aleksander\_Stalsberg](https://community.homey.app/u/Aleksander_Stalsberg)\
**Post date:** [July 12, 2023, 10:20pm UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/27 "2023-07-12T22:20:02Z")

</div>

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?

---

<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 12, 2023, 11:16pm UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/28 "2023-07-12T23:16:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arjan\_Neet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arjan_neet/32/17808_2.png) [@Arjan\_Neet](https://community.homey.app/u/Arjan_Neet)\
**Post date:** [March 12, 2024, 10:40am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/29 "2024-03-12T10:40:06Z")

</div>

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](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/f/cfb160dcc2d8854aff9321ddf13e5cd61dc40d94.png)  
Result:  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/d/cdc5c31f1dfdff62950708efb00ea5ceff494c05.png)

Any idea how to solve this much appreciated

---

<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:** [March 12, 2024, 10:50am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/30 "2024-03-12T10:50:05Z")

</div>

String-type values need to be quoted:

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

```

---

<div class="post-metadata">

**Author:** ![Arjan\_Neet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arjan_neet/32/17808_2.png) [@Arjan\_Neet](https://community.homey.app/u/Arjan_Neet)\
**Post date:** [March 12, 2024, 10:52am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/31 "2024-03-12T10:52:35Z")

</div>

I actually already tried that, but then I get this error:  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/8/c8c9764e5279667c2f79d83017d614b9d3ec2ba3.png)  
(simplified to only use 1 arg for test)

---

<div class="post-metadata">

**Author:** ![Arjan\_Neet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arjan_neet/32/17808_2.png) [@Arjan\_Neet](https://community.homey.app/u/Arjan_Neet)\
**Post date:** [March 12, 2024, 10:56am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/32 "2024-03-12T10:56:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arjan\_Neet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arjan_neet/32/17808_2.png) [@Arjan\_Neet](https://community.homey.app/u/Arjan_Neet)\
**Post date:** [March 12, 2024, 10:58am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/33 "2024-03-12T10:58:34Z")

</div>

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

---

<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:** [March 12, 2024, 11:19am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/34 "2024-03-12T11:19:21Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Arjan\_Neet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arjan_neet/32/17808_2.png) [@Arjan\_Neet](https://community.homey.app/u/Arjan_Neet)\
**Post date:** [March 12, 2024, 11:47am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/35 "2024-03-12T11:47:24Z")

</div>

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

---

<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:** [March 12, 2024, 11:52am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/36 "2024-03-12T11:52:14Z")

</div>

> [@Arjan\_Neet](#):
>
> 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.

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.

> [@](#):
>
> What exactly should your last code do? I do not quite understand it sorry

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

---

<div class="post-metadata">

**Author:** ![Arjan\_Neet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arjan_neet/32/17808_2.png) [@Arjan\_Neet](https://community.homey.app/u/Arjan_Neet)\
**Post date:** [March 12, 2024, 12:06pm UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/37 "2024-03-12T12:06:20Z")

</div>

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

---

<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:** [March 13, 2024, 9:48am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/38 "2024-03-13T09:48:09Z")

</div>

> [@Arjan\_Neet](#):
>
> so then I don’t see if it has the correct result.

@Arjan_Neet:  
In a normal running flow, you can catch errors like this:  
 ![Screenshot from 2024-03-13 10-45-43](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/1/e1bc9052eb51d3e775b072223b56ecfb0ea63334.png)

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

---

<div class="post-metadata">

**Author:** ![Arjan\_Neet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arjan_neet/32/17808_2.png) [@Arjan\_Neet](https://community.homey.app/u/Arjan_Neet)\
**Post date:** [March 13, 2024, 10:26am UTC](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178/39 "2024-03-13T10:26:34Z")

</div>

thanks 🙂

[Previous page](https://community.homey.app/t/homeyscript-any-sane-ways-to-use-args/66178.md?page=1)
