# \[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:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![olowi146](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/olowi146/32/63044_2.png) [@olowi146](https://community.homey.app/u/olowi146)\
**Post date:** [October 17, 2022, 8:13pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/62 "2022-10-17T20:13:27Z")

</div>

Hey!  
I can’t get the HomeyScript console to work.  
I’ve tried running several of the examples. But the console is just blank.  
Scripts seem to work, I can make Homey say something, but nothing is being written to the console.

Is this a known issue? Any way to get it working?  
Thanks!  
/Olof

---

<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:** [October 18, 2022, 4:33am UTC](https://community.homey.app/t/app-pro-homeyscript/854/63 "2022-10-18T04:33:37Z")

</div>

Which browser?

---

<div class="post-metadata">

**Author:** ![olowi146](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/olowi146/32/63044_2.png) [@olowi146](https://community.homey.app/u/olowi146)\
**Post date:** [October 18, 2022, 6:55am UTC](https://community.homey.app/t/app-pro-homeyscript/854/64 "2022-10-18T06:55:09Z")

</div>

Chrome, but I’ve tried Edge as well. Same result.

I’ve also tried uninstalling HomeyScript and reinstalling. Logging out and logging back on again.  
So far I haven’t tried a re-start of Homey, I guess that might be next.

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [October 18, 2022, 10:16am UTC](https://community.homey.app/t/app-pro-homeyscript/854/65 "2022-10-18T10:16:22Z")

</div>

Maybe you have to scroll-up or enlarge the monitor-window (drag upwards)

---

<div class="post-metadata">

**Author:** ![olowi146](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/olowi146/32/63044_2.png) [@olowi146](https://community.homey.app/u/olowi146)\
**Post date:** [October 18, 2022, 7:37pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/66 "2022-10-18T19:37:31Z")

</div>

This is what it looks like when I’m running a script, no output. I tried on my iPad using safari. There I can get the output, so most likely something is wrong with my laptop browser… much annoying…

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

---

<div class="post-metadata">

**Author:** ![HansieNL](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hansienl/32/10634_2.png) [@HansieNL](https://community.homey.app/u/HansieNL)\
**Post date:** [October 18, 2022, 9:04pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/67 "2022-10-18T21:04:24Z")

</div>

Maybe you can try a portable browser. You can find different browsers at Portableapps website.  
Then you don’t have the problem of installed plug-ins, custom settings, which can cause strange effects.

---

<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:** [October 18, 2022, 9:39pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/68 "2022-10-18T21:39:39Z")

</div>

Did you try Firefox?

---

<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:** [October 19, 2022, 4:45am UTC](https://community.homey.app/t/app-pro-homeyscript/854/69 "2022-10-19T04:45:40Z")

</div>

Are you using any browser extensions that might be causing this issue? Check your browser’s developer console to see if there are any errors popping up.

---

<div class="post-metadata">

**Author:** ![olowi146](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/olowi146/32/63044_2.png) [@olowi146](https://community.homey.app/u/olowi146)\
**Post date:** [October 27, 2022, 10:45am UTC](https://community.homey.app/t/app-pro-homeyscript/854/70 "2022-10-27T10:45:49Z")

</div>

Hej!  
Thanks for the suggestions!  
It seems like the issue might be that I was using my company-laptop. There must be something blocking the Homey Script.  
I’ve finally found my old private MacBook and using that one I got the Homey Script to work.  
Now I just need to learn scripting!

---

<div class="post-metadata">

**Author:** ![Richard\_Vermeulen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/richard_vermeulen/32/10636_2.png) [@Richard\_Vermeulen](https://community.homey.app/u/Richard_Vermeulen)\
**Post date:** [January 17, 2023, 12:34pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/71 "2023-01-17T12:34:19Z")

</div>

Hoi ik wil een export maken naar google sheets en ik kan dan als variabel de datum meenemen b.v. 17-01-2023.  
Wat ik graag zou willen is ook alleen de maand ( 01 ) van die datum (huidige datum van de export) meenemen in mijn export.  
Dat moet volgens mij niet moeilijk zijn alleen heb ik geen kaas gegeten van Homeyscript c.a. programeren.  
Of eigenlijk nog beter zou ik de datum los als jaar, maand en dag willen zien, nu ik toch bezig ben. 😉

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [January 17, 2023, 7:08pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/72 "2023-01-17T19:08:03Z")

</div>

Here is some code. All data will be given as a tag. De tags you don’t need, just add // in front of ‘await tag’. This will give e.g //await tag(‘CurrentDay’, currentDay); and this tag will not be available

```auto
var date = new Date();
date.setDate(date.getDate());
const currentDay = date.getDate();
await tag('CurrentDay', currentDay);
console.log('1 CurrentDay is: ' +currentDay);
const currentMonth = date.getMonth() +1; // getMonth() returns month from 1 to 12
await tag('CurrentMonth', currentMonth);
console.log('2 CurrentMonth is: '+currentMonth);
const currentYear = date.getFullYear();
await tag('CurrentYear', currentYear);
console.log('3 CurrentYear is: '+currentYear);

var date = new Date(); // current date
date.setDate(1); // going to 1st of the month
date.setHours(-1);// going to the last day of the previous Month
const yearPreviousMonth = date.getFullYear();
await tag('YearPreviousMonth', yearPreviousMonth);
console.log('4 YearPreviousMonth is: '+yearPreviousMonth);
const lastDayPreviousMonth = date.getDate();
await tag('LastDayPreviousMonth', lastDayPreviousMonth);
console.log('5 LastDayPreviousMonth is: '+lastDayPreviousMonth);
const previousMonth = date.getMonth() +1;
await tag('PreviousMonth', previousMonth);
console.log('6 PreviousMonth is: '+previousMonth);

var date = new Date(); // current date
date.setDate(1); // going to 1st of the month
date.setMonth(-2)// going back two months
date.setHours(-1);// going to the last day of the previous Month
const yearPreviousTwoMonth = date.getFullYear();
await tag('YearPreviousTwoMonth', yearPreviousTwoMonth);
console.log('7 YearPreviousTwoMonth is: '+yearPreviousTwoMonth);
const previousTwoMonth = date.getMonth() +1;
await tag('PreviousTwoMonth', previousTwoMonth);
console.log('8 PreviousTwoMonth is: '+previousTwoMonth);

var date = new Date();
date.setDate(date.getDate());
function getDaysInMonth(year, month) {
  return new Date(year, month, 0).getDate();
}
const daysInCurrentMonth = getDaysInMonth(currentYear, currentMonth);
await tag('DaysInCurrentMonth', daysInCurrentMonth);
console.log('9 DaysInCurrentMonth is: '+daysInCurrentMonth);
const daysInPreviousMonth = getDaysInMonth(currentYear, previousMonth);
await tag('DaysInPreviousMonth', daysInPreviousMonth);
console.log('10 DaysInPreviousMonth '+previousMonth +' is: '+daysInPreviousMonth);

var date = new Date();
date.setDate(date.getDate()-1);
const yesterDay = date.getDate();
await tag('YesterDay', yesterDay);
console.log('11 YesterDay is: ' +yesterDay);
const yesterDayMonth = date.getMonth() +1; // getMonth() returns month from 0 to 11
console.log('12 YesterDayMonth is: ' +yesterDayMonth);
await tag('YesterDayMonth', yesterDayMonth);
const yesterDayYear = date.getFullYear();
await tag('YesterDayYear', yesterDayYear);
console.log('13 YesterDayYear is: '+yesterDayYear);

var date = new Date();
date.setDate(date.getDate());

```

---

<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:** [June 13, 2023, 11:00pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/73 "2023-06-13T23:00:42Z")

</div>

The Better Logic Library has a special flowcard to format datetime just how you want it.

---

<div class="post-metadata">

**Author:** ![Jeroen\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_w/32/9803_2.png) [@Jeroen\_W](https://community.homey.app/u/Jeroen_W)\
**Post date:** [June 14, 2023, 5:52pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/74 "2023-06-14T17:52:23Z")

</div>

I would like to use this card :  
 ![2023-06-14_193709](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/5/459f1ce9087c78fba2d7f67fcb0210dd4a7b4347.png)

and use the output from this script. (found a big part on the forum) to check who/what or flow turned a device on or off.

It works as a script, but i have no idea how to use it in the card. Hopefully someone can help me.

```auto
let allDevices = await Homey.insights.getLogs();
let targetDeviceUri = 'homey:device:ID'; // Replace <DEVICE_URI> with the URI of the device you want to filter

let onoffDevices = allDevices.filter(function (capability) {
  return capability.id === 'onoff' && capability.uri === targetDeviceUri;
});

onoffDevices.forEach(async (device) => {
  let deviceData = await Homey.insights.getLogEntries({ uri: device.uri, id: device.id });
  let lastLogEntry = deviceData.values[deviceData.values.length - 1]; // Get the last log entry
  
  console.log(device.uriObj.name, lastLogEntry.t, lastLogEntry.v, '(', lastLogEntry.originName, ')');
  
const varName = 'test1'; // The name of your variable
const newValue = (device.uriObj.name) + (' ') + (lastLogEntry.t ) + (' ') + (lastLogEntry.v ) + (' ') + (lastLogEntry.originName); // The new value for the variable

const Logic = await Homey.logic.getVariables();
const filtered = Object.values(Logic).find((value) => value.name === varName);

if (filtered) {
  const { id: varID } = filtered;
  await Homey.logic.updateVariable({ id: varID, variable: { value: newValue } });
}
});

```

---

<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:** [June 14, 2023, 5:55pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/75 "2023-06-14T17:55:34Z")

</div>

Not HomeyScript, but this is an alternative way  
 ![Screenshot from 2023-06-14 19-54-57](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/2/32bceae2799caa3ff7a26f507b2ef29c47aa76a3.png)

---

<div class="post-metadata">

**Author:** ![Jeroen\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_w/32/9803_2.png) [@Jeroen\_W](https://community.homey.app/u/Jeroen_W)\
**Post date:** [June 14, 2023, 5:59pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/76 "2023-06-14T17:59:00Z")

</div>

U are fast haha, but that seems to be a better solution. Gonna try this.

---

<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:** [June 14, 2023, 6:12pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/77 "2023-06-14T18:12:32Z")

</div>

@Jeroen_W  
There is also a Get Insights card, which you can set to 0 minutes. It contains the same tokens.  
That one can be used on any trigger, so you don’t need the Watch/listener card perse.

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [June 15, 2023, 9:35am UTC](https://community.homey.app/t/app-pro-homeyscript/854/78 "2023-06-15T09:35:00Z")

</div>

> [@Arie\_J\_Godschalk](#):
>
> perse

A little bit of Dutch, brings a smile 😊 on my face

---

<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:** [June 15, 2023, 11:47am UTC](https://community.homey.app/t/app-pro-homeyscript/854/79 "2023-06-15T11:47:14Z")

</div>

Dutch Latin 😉 [per se - Wiktionary](https://en.wiktionary.org/wiki/per_se)

---

<div class="post-metadata">

**Author:** ![clindh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/clindh/32/60091_2.png) [@clindh](https://community.homey.app/u/clindh)\
**Post date:** [July 10, 2023, 6:31pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/80 "2023-07-10T18:31:51Z")

</div>

Dipping my toes into HomeyScript, sorry for newbie question but I tried to but could not find answer in the linked documentation. I found how to set a tag, but not how to read it.

In a “Run and return …” Advanced When-action, how do I get the value that is passed in a tag, for example in this little test flow?

Use case: I want to extract the “0” from the text here, so I need to read the “Result” text-tag (this is for testing, in real life the tag would be a topic from the MQTT cient).

And a second question while I’m at it, how do I set and read an Advanced Flow variable?

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/6/96a06f39fa478632aaf68b32c02a6e8fbc155162.png)

---

<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 10, 2023, 7:51pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/81 "2023-07-10T19:51:26Z")

</div>

I think this is a good start to get into Homey logics

> **[Using Homey Logic in Flows](https://support.homey.app/hc/en-us/articles/4410240765586-Using-Homey-Logic-in-Flows)**
>
> You’ve probably seen Homey Logic. Once you get the hang of it, it's a great tool for any smart home. By creating your own Variables and using these in your Flows as Tags, you can often accomplish c...

Use the Hscript card Run code with Argument and return text-tag.  
You also see the local tag of both cards is called [Result]. (Local tag = this flow only); the info popup is shown while hovering the tag symbol in the flowcard.

> ![Screenshot from 2023-07-10 21-33-40](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/8/f848ea85aa8a66cbc3bbb854326b3187c648be2e.png)

The local tag from the Logic card is used as argument to the Hscript card; In the tag picker, the tags under “This flow” are tags provided by the used flowcards

> ![Screenshot from 2023-07-10 21-32-26](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/7/a7b7c7cef591880a20f349ea29d6a8d0f3cb40ea.png)

When we have equally named tags, hover the tag in the picker list, to discover to which flowcard it belongs. The flowcard will glow blue and the tag symbol becomes blue:

> ![Screenshot from 2023-07-10 21-32-54](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/9/19e8b2f734869d6186f5391ab71ea4871d6f21e6.png)

> [@clindh](#):
>
> how do I set and read an Advanced Flow variable?

You already did, with the logic card you used

The logics variables, which you have to create up front, are global variables

> ![Screenshot from 2023-07-10 21-48-44](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/0/70295ea1cf6bba8b53c45444c5570c911d5f4b60.png)

.  
With the MQTT Client, you can use it like this, to edit the value of the topic message and pass it on

> ![Screenshot from 2023-07-10 21-54-56](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/f/ff81d4204cc52211c9bd269cec337fb6a3e9e580.png)

[Previous page](https://community.homey.app/t/app-pro-homeyscript/854.md?page=3)

[Next page](https://community.homey.app/t/app-pro-homeyscript/854.md?page=5)
