[APP][Pro] HomeyScript

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();
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());
1 Like