Read the statement by Michael Teeuw here.
Simple(?) module to send a notification every x minutes?
-
Is there a module out there where you can say “every 60000ms, send a “PAGE_CHANGED” notification with a value of 1” and it will do that?
I tried having ChatGPT write a “MMM-NotificationTimer” module that I could start from but I can’t seem to get it to actually send the notification. JavaScript is just too foreign to me to be able to do this at this time.
I’m using MMM-pages to be able to switch between a traditional MM setup and just a picture. I use MMM-Keypress to switch between the two. I’d like it to automatically switch back to the picture after, say, 10 minutes, hence the need for timed notifications.
Is there such a module already out there somewhere?
-
Module.register("test", { defaults: { interval: 60_000 }, start: function () { this.timer = null const job = () => { this.sendNotification("PAGE_CHANGED", 1) clearTimeout(this.timer) this.timer = setTimeout(job, this.config.interval) } job() }, })
Just from my brain, not tested.
-
@MMRIZE should wait til modules are ready. use interval timer
@UncleRoger try this
-
@sdetweil
Yup. You are right.
Just little things;- Generally, you are right. After
ALL_MODULES_STARTED
notification, it would be better to start communication. But sending notifications is harmless, so I put it intostart
, just for example. - Personally, I prefer loop of
timeout
than normalinterval
. Butinterval
would be more obvious.
- Generally, you are right. After
-
@sdetweil said in Simple(?) module to send a notification every x minutes?:
Thank you so much! That got a lot farther than I ever did. When it gets to the point of actually sending the notification, however, I see an error in the browser console:
sendNotification: Notification should be a string.
As far as I can tell, the notification (this.config.notification) is a string. Is there something else that I can do to force it to be considered a string?
Note: the only change I made was to add a bunch of console.log messages so I could try to understand what was going on and then, when I saw that error, commented out the sendnotification line (which made the error disappear). When I uncommented it, the error came back.
-
@UncleRoger do a git pull in the module folder… just posted a fix
-
@sdetweil
Got the new version (typo in “notification”?) and it seems to work except that it ignores the interval and just constantly sends the notification.Also, there’s an error showing in the console log:
Parameter mismatch in module.show: callback is not an optional parameter! 3 module.js:394:8
with different numbers. I’m not sure that’s a problem (MMM-BackgroundSlideshow has the same error and it works fine) but I thought I’d mention it.
-
@UncleRoger can u post the module config
-
@sdetweil
This is what I have:{ module: 'MMM-SendNotification', position: 'top_right', classes: "fixed", config: { interval: 60000, // 1 minute interval notification: 'PAGE_CHANGED', payload: 1, }, },
Thank you for your patience and assistance! You are amazing!
-
@UncleRoger no position, as there is no UI…