# \[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:** 1\
**Showing post:** 83

<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 11, 2023, 12:31pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/83 "2023-07-11T12:31:31Z")

</div>

YW!

> [@clindh](#):
>
> can I also set/get them in code?

You can write & read logics variables like this

> [@DIY circadian rhythm based lighting](https://community.homey.app/t/diy-circadian-rhythm-based-lighting/33348/36):
>
> This returns the ID (and the value) when you input your var name upside_down_face // Replace MyVar with your var name let varName = "MyVar" const logicVars = await Homey.logic.getVariables(); for (var iLogicVar in logicVars){ if (logicVars[iLogicVar].name == varName) log("Variable: " + logicVars[iLogicVar].name + "\nValue:\t " + logicVars[iLogicVar].value + "\nID:\t " + logicVars[iLogicVar].id) } . This is possible on 7.3.0 also @DirkG just l…

.

> [@clindh](#):
>
> Also, when I call console.log() in a flow - where does that log end up? I’ve seen that I can test-run a single Hscript block and get the output, but not possible for a whole flow?

Yeah you can see the log when test run a Hscript block.  
I don’t know exactly how, but you can log errors, which should be returned by the ‘red’ wire of flowcards / hscript blocks.  
You should catch errors like this

> [@Homeyscript functionality](https://community.homey.app/t/homeyscript-functionality/30066/7):
>
> You will have to select the token uri and id like this: await Homey.flowToken.getFlowTokens().then(function(tokens) { for (let token in tokens) { if ( tokens[token].uri == "homey:manager:weather" && tokens[token].id == "state" ) { var mytoken = tokens[token].value; console.log(mytoken); } } }).catch(console.error);

‘Normal’ console.log output you can redirect to a Homeyscript tag, or a logics var.  
Or, use the ‘return’, which writes to the ‘result’ tag of Hscript blocks

.  
You can use (almost?) any ‘And’ or ‘Then’ flowcard as well. Take a look at the example scrips in Hscript  
Write log to timeline:

```auto
Homey.flow.runFlowCardAction({
        uri: 'homey:manager:notifications',
        id: 'create_notification',
        args: {
          text: 'This is a test Timeline notification sent by Homeyscript'
        }
});

```

- Write log to push message:  
First run this little script

```auto
// To send a push message for example, you'll need the id and athomId of the user
resId = await Homey.users.getUsers().then(f => Object.values(f).reduce((r,b,c)=>Object.assign(r, {[b.name]:b.id}), {}));
log("The \'id\' of the users:\n", resId);

resAthomid = await Homey.users.getUsers().then(f => Object.values(f).reduce((r,b,c)=>Object.assign(r, {[b.name]:b.athomId}), {}));
log("\n\nThe \'athomId\' of the users:\n", resAthomid);

```

- Send the actual pushmessage using the `id` and `athomId`:

```auto
Homey.flow.runFlowCardAction({
        uri: 'homey:manager:mobile',
        id: 'push_text',
        args: {
			    user: {
			    id: 'xxxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx',
			     athomId: 'xxxxxxxxxxxxxxxxxxxxxx',
		    	},
		    text: 'This is a test push notification from HomeyScript'
        },
      });
  return(true);

```

---

_[View the full topic](https://community.homey.app/t/app-pro-homeyscript/854)._
