Homey Community Forum

Getting Started - Logic variables

How did you calculate which day it is in order to put the name of the day in that text variable?

While I was curious, and like to find out things, I came up with this.
It should run until Homey dies.
Maybe I missed something, or things can be done in other ways, pls let me know!

How to display (or to use with speech) name of today and this month

A. Create 2 variables, type Text

  1. NaamVanDag (name of day), no text need to be entered.
  2. NaamVanMaand (name of month) & enter the name of the current Month

B. Create 7 flows, one for each weekday
Mon:

Tue:

Wed:


And so forth

C. Create 12 flows, one for each month
Jan:

Feb:

Mar:


And so forth

some/most can be done in HomeyScript:

//MyCreateDay-Tag.js

let SysInfo = await Homey.system.getInfo();
var weekDay   = SysInfo.dateHuman.slice(0,(SysInfo.dateHuman.indexOf(' ')));
await tag("WeekDay", weekDay );       //creating new HomeyScriptTag 'WeekDay'
console.log("Weekdag", weekDay);
return(true);
1 Like

Thanks! I don’t have enough knowledge to write a script like that.
Most of the time I can read what a script should do.
So if I’m correct this script creates tag named Weekday and then this script updates the value of it with the name of the weekday.
Does it create the same tag each day? Or is this skipped if it already exists?

But, well, this saves a lot of flows :wink: :wink:

This script runs ones when called, so it has to be run every day.(can be run in the AND column)
HomeyScript is fun to experiment with, just try, I’m also a beginner but many guys here can assist you, when you get stucked. There are many examples provided with HomeyScript, play with them and be amazed.

Thanks, yes I understood, and alr created a flow for that :wink: Playing with the script examples right now.
So ofcourse I want the month tag also, but, no way it returns something else but weekday

Inside the Playground

Homey.system.getInfo();

returns

"dateHuman": string "donderdag 29ste april 2021 17:31:41"

I can’t even let the homeyscript return that, and I want to pick the 3rd word of the string in some way I was thinking.

Indeed the 3rd word, but it has not a fixed place in the string, so I used the index of the spaces:

console.log (SysInfo.dateHuman); // just to show dateHuman

   var temp = SysInfo.dateHuman.slice(SysInfo.dateHuman.indexOf(' ')+1);
    temp = temp.slice(temp.indexOf(' ')+1);
    var Maand = temp.slice(0,temp.indexOf(' '));
1 Like

Clever. I wondered why it was empty, and had more than one space between the ’ ’

Many thanks again.
Cheers

1 Like

So, here’s the flow (instead of 19 flows :crazy_face: )

The var’s (missing in shared flow views)
naamdagmaandhscript

1 Like

Thanks for input regarding this issue. Do you know how I can figure out the dateHuman for tomorrow?

Sorry, no.

-----------------------------------
Just for fun, I got a q how to display the weekday on a dash, and found out this works also:

// Create a date object
    var date = new Date();
    var week = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag']; // Create an array of weekday names
    await tag("NaamVanDag", week[date.getDay()] );       //creating new HomeyScriptTag 'NaamVanDag'
    console.log( "NaamVanDag", week[date.getDay()] ); // Displays the name of today
return(true);

--------------------------------

And I just read the Q from @Simon_Skotheimsvik again,

this should be quite simple when using the array of weekdays. Just start the array with a different day :wink:

// Create a date object
var date = new Date();
var week = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag']; // Create an array of weekday names
var weekTomorrow = ['Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag','Zondag']; // Create an array of weekday names, but one day ahead
   
   await tag("NaamVanDag", week[date.getDay()] );  //creating new HomeyScriptTag 'NaamVanDag'
   await tag("NaamVanMorgen", weekTomorrow[date.getDay()] );  //creating new HomeyScriptTag 'NaamVanMorgen'

   console.log( "NaamVanDag", week[date.getDay()] );  // Displays the name of today
   console.log( "NaamVanMorgen", weekTomorrow[date.getDay()] );  // Displays the name of tomorrow

return(true);

Always fun to hassle with HomeyScript, btw, did you test this also between 00:00h and 02:00h? I had the problem that Homey is using UTC time in HomeyScript, so the day change is at 02:00h in the summer. That’s the reason for me to use dateHuman.

Yup, 2 hrs difference according to developer.athom.com:

date|2021-05-14T08:41:54.727Z
dateHuman|vrijdag 14de mei 2021 10:41:54|

Yea, I’m aware of the UTC vs. local time sh*t.
Why did Athom change the system time to UTC. Very impractical for ‘normal’ @ home use imho.

Well, it’s a big discussion about what time to use, this is Geurt’s view on it:

So if Hscript Date() returns zulu time, the new day / next day flows which triggers scripts using that, should be running at 02:01AM during Day Saving time,
and at 01:01AM during ‘normal local time’.
My holy, who invented this mess🙈

But, to keep it practical, for me this does the job:
I won’t need written / spoken weekdays or months before 6:00AM UTC+2
So the flows can run at 02:01AM UTC on my system.

Hi Simon en Jan @JPe4619 @Simon_Skotheimsvik

With one idea, you get another one :wink:
This script returns the name of the next day (a bit quick ‘n’ dirty, but it works), and it can be run right after midnight (no hassle with UTC times and what not)

//MyCreateTomorrowName-Tag.js
// This script creates tag named NaamVanMorgen and then this script
// updates the value of it with the name of the *the next* weekday.

let SysInfo = await Homey.system.getInfo();
var weekDay   = SysInfo.dateHuman.slice(0,(SysInfo.dateHuman.indexOf(' ')));
if ( weekDay == "maandag" ) { weekDay = "dinsdag" }  // if contents of 'weekDay' equals [maandag], then overwrite it with [dinsdag]
 else if ( weekDay == "dinsdag" ) { weekDay = "woensdag" }
  else if ( weekDay == "woensdag" ) { weekDay = "donderdag" }
   else if ( weekDay == "donderdag" ) { weekDay = "vrijdag" }
    else if ( weekDay == "vrijdag" ) { weekDay = "zaterdag" }
     else if ( weekDay == "zaterdag" ) { weekDay = "zondag" }
      else if ( weekDay == "zondag" ) { weekDay = "maandag" }
       else weekDay = "Unknown until tomorrow..."

await tag("NaamVanMorgen", weekDay );       //creating new HomeyScriptTag 'NaamVanMorgen'
console.log("NaamVanMorgen", weekDay);
return(true);
2 Likes

Would it be too much trouble to switch to English when making screen dumps?

1 Like

If you mean the weekdays (the rest is in English?):

Actually I ment the screenshots from your phone.

BR

Thomas

Thanks Thomas, I’ll try to remember switching to EN first when taking screenshots. Oh crap, I just discover Homey has to restart to change the language :flushed: :nerd_face:
Which post do you like to be Englified @Kindbo?

I just don’t read more than English and Swedish, so every other language makes it harder for me.

I am Swedish, but use English for Windows, Android and Homey. That way it is easier to search for help and apply what I find.

2 Likes