Read the statement by Michael Teeuw here.
MagicMirror compliments for specific days at specific times
-
Hi everyone,
I want to change the code of my MMM-compliments .js so that some compliments are displayed only on specific days (friday, saturday, sunday) at specific times (around beer o’clock so 6pm to 8pm).
Issue is that the documentation of the module isn’t mentioning how to go about it, even though I’m 100% sure it’s possible.So if someone knows how to do it, or has done it and doesn’t mind sharing the code, it would be very much appreciated !
Thanks a lot and have a good one !
-
@Horyzon currently the code only supports a date mask
yyyy-mm-dd
that is done by this section of code
complimentArray () { const hour = moment().hour(); const date = moment().format("YYYY-MM-DD"); let compliments = []; . . . // Add compliments for special days for (let entry in this.config.compliments) { if (new RegExp(entry).test(date)) { Array.prototype.push.apply(compliments, this.config.compliments[entry]); } } return compliments; },
it gets the date/time NOW
and prints it YYYY-MM-DD
2024-04-19
and in the later code checks the selector field of the compliment entry to match that
. means any character.to do what you want the selector would need a different format, crontab like
* 18-20 * * 4-6
which is (* means any)
any minute
hours 18-20
any day
any month
4-6 days of the weekso one could envision printing that layout
and building a regular expression to test it
see https://stackoverflow.com/questions/14203122/create-a-regular-expression-for-cron-statement/57639657#57639657and adding those 2 or 3 lines of code to the module function
-
@Horyzon SO… I think I have this working if you’d like to try it.
uses the cron nomenclature
“56-57 16-18 * * 4-6”
“minute hour day month day_of_week”any of those can be ranges like above for minute, hour and day of week
- means any
so, the mask above says
valid for last 3 days of week, thur-sat
between 16:00 and 18:00
during the two minutes at hh:56-57so 16:56-57. 17:56-57 , on thur, fri, sat nights all year
the values can also be treated with some divisor
mm/2 means the even minutes
mm/30 means every 30 minutes
hh/2 even other hour
etc
commas are allowed too 3,5,7,8 on the 3rd, 5th, 7th,8th (minute,hour, month day of month,
7/8 are invalid for day of week 0-6, sunday is day 0there are crontab generators… click some boxes and it will spit out the string
-
@Horyzon my update to compliments to support cron type entries was accepted and will be published in the next release (Oct 1)
you can try it today by using the the develop branch of the MagicMirror repo
see the troubleshooting section topic on how to get the develop branch
https://forum.magicmirror.builders/topic/14327/testing-new-fixes-or-solving-current-problems-with-next-release-codemy MMM-Config module has support for this approach today
you can use this page to generate the cron expression
https://crontab-generator.org/
use some dummy command to complete their config operation,
and only take the first 5 space separated fields of the result…
minute hour day month day_of_week