• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

MagicMirror compliments for specific days at specific times

Scheduled Pinned Locked Moved Unsolved Troubleshooting
4 Posts 2 Posters 350 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    Horyzon
    last edited by sdetweil Jul 15, 2024, 6:31 PM Apr 19, 2024, 8:42 AM

    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 !

    S 2 Replies Last reply Apr 19, 2024, 11:59 AM Reply Quote 0
    • S Offline
      sdetweil @Horyzon
      last edited by sdetweil Apr 22, 2024, 1:33 AM Apr 19, 2024, 11:59 AM

      @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 week

      so 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#57639657

      and adding those 2 or 3 lines of code to the module function

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @Horyzon
        last edited by Apr 21, 2024, 2:23 AM

        @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-57

        so 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 0

        there are crontab generators… click some boxes and it will spit out the string

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        S 1 Reply Last reply Jul 15, 2024, 6:25 PM Reply Quote 0
        • S Offline
          sdetweil @sdetweil
          last edited by Jul 15, 2024, 6:25 PM

          @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-code

          my 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

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Sam, technical setup by Karsten.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy