[APP][Pro] HomeyScript

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?

Which browser?

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.

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

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…

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.

1 Like

Did you try Firefox?

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.

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!

1 Like

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. :wink:

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

var date = new Date();
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();
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();
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();
1 Like

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

I would like to use this card :

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.

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 } });

Not HomeyScript, but this is an alternative way
Screenshot from 2023-06-14 19-54-57

1 Like

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


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.

1 Like

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

1 Like

Dutch Latin :wink: per se - Wiktionary


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?

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

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.

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

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:

You already did, with the logic card you used

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

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