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.

    MMM-NotificationTrigger transform payload

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    24 Posts 4 Posters 6.8k Views 4 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.
    • S Offline
      sdetweil @corius
      last edited by

      @corius what is ‘title’? the incoming message is an array of calendar events…

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • C Offline
        corius
        last edited by

        by the title i mean the title of the individual calendar events. but ok then it doesn’t work that way. So again asked differently: is there a way to display upcoming calendar events via the alert module?

        S lavolp3L 2 Replies Last reply Reply Quote 0
        • S Offline
          sdetweil @corius
          last edited by sdetweil

          @corius said in MMM-NotificationTrigger transform payload:

          upcoming calendar events

          what does that mean? if I have 20 entries, u want 1 alert with 20 entries, or 20 alerts with 1 entry each?
          or just today, or?

          alert module is expecting a single line of text

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • lavolp3L Offline
            lavolp3 Module Developer @corius
            last edited by lavolp3

            @corius you need to have a look at how the payload looks. If it’s an array, you should be able to catch the title of specific elements by using something like payload.entries[n].title

            How to troubleshoot modules
            MMM-soccer v2, MMM-AVStock

            S 1 Reply Last reply Reply Quote 0
            • lavolp3L Offline
              lavolp3 Module Developer
              last edited by

              @corius Considering you want to alert the next event happening in say 15 minutes, you could first check what event is in a range of the next 15 minutes, then take it’s title and alert that one. Can all be done inside the callback function you’ve shown above.

              Is that what you want?

              How to troubleshoot modules
              MMM-soccer v2, MMM-AVStock

              1 Reply Last reply Reply Quote 0
              • S Offline
                sdetweil @lavolp3
                last edited by sdetweil

                @lavolp3 actually payload IS an array
                (from my system default cal)

                0: {title: "M L King Day", startDate: "1579500000000", endDate: "1579586400000", fullDayEvent: true, location: "United States", …}
                1: {title: "Valentine's Day", startDate: "1581660000000", endDate: "1581746400000", fullDayEvent: true, location: "United States", …}
                2: {title: "Presidents' Day", startDate: "1581919200000", endDate: "1582005600000", fullDayEvent: true, location: "United States", …}
                3: {title: "Good Friday", startDate: "1586494800000", endDate: "1586581200000", fullDayEvent: true, location: "United States", …}
                4: {title: "Easter Sunday", startDate: "1586667600000", endDate: "1586754000000", fullDayEvent: true, location: "United States", …}
                5: {title: "Mother's Day", startDate: "1589086800000", endDate: "1589173200000", fullDayEvent: true, location: "United States", …}
                6: {title: "Memorial Day", startDate: "1590382800000", endDate: "1590469200000", fullDayEvent: true, location: "United States", …}
                7: {title: "Father's Day", startDate: "1592715600000", endDate: "1592802000000", fullDayEvent: true, location: "United States", …}
                8: {title: "Independence Day Holiday", startDate: "1593752400000", endDate: "1593838800000", fullDayEvent: true, location: "United States", …}
                9: {title: "Independence Day", startDate: "1593838800000", endDate: "1593925200000", fullDayEvent: true, location: "United States", …}
                
                

                so the js would be

                payload[0].title 
                

                for the title (cal subject) of the 1st cal entry

                I found this by using the developers window (ctrl-shift-i), selecting the ‘Sources’ tab,
                expanding the modules entry, and then the calendar entry to get to calendar.js

                then knowing it is a notification,(notificationreceived) i searched (ctrl-f) for ‘sendnotification’
                I put a stop on that line, hit refesh(f5), and the web page starts over, and stops on that line, then use the mouse to hover over the eventlist variable name, and it expands to the data layout

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • C Offline
                  corius
                  last edited by

                  @lavolp3 yes that is exacly wat i want. can you please post the code? Thank you

                  lavolp3L 1 Reply Last reply Reply Quote 0
                  • lavolp3L Offline
                    lavolp3 Module Developer
                    last edited by lavolp3

                    {
                      module: "MMM-NotificationTrigger",
                      config: {
                        triggers:[
                          {
                            trigger: "CALENDAR_EVENTS",
                            fires: [
                              {
                                fire:"SHOW_ALERT",
                                payload: (payload) => {
                                  var testMessage = "";
                                  payload.forEach(event => {
                                    if (moment(event.startDate) > moment() && moment(event.startDate) < moment().add("15", minutes)) {
                                     testMessage += event.title + ", "
                                    }
                                  });
                                  return {
                                          type: "notification",
                                           title: "test",
                                           message: testMessage
                                  } 
                                },
                              },
                            ],
                          },
                        ]
                      }
                    },
                    

                    This will most probably not work and needs to be de-bugged, but might be worth as a starting point. And I hope you get what I’m hinting at.

                    How to troubleshoot modules
                    MMM-soccer v2, MMM-AVStock

                    1 Reply Last reply Reply Quote 0
                    • lavolp3L Offline
                      lavolp3 Module Developer @corius
                      last edited by lavolp3

                      @corius

                      can you please post the code?

                      Took me 10 seconds :smiling_face_with_sunglasses:
                      No, of course I was already working on it.

                      Seriously, I like the idea, that’s why I did a contribution.But you need to be more specific if you want to have the complete solution

                      How to troubleshoot modules
                      MMM-soccer v2, MMM-AVStock

                      C 1 Reply Last reply Reply Quote 0
                      • C Offline
                        corius
                        last edited by

                        @lavolp3 Thank you for the fast answer. I tried this code. the result is that I get a notification but so far it only contains the title (test) but not the massage (title of the calendar event)

                        S lavolp3L 2 Replies Last reply Reply Quote 0
                        • C Offline
                          corius @lavolp3
                          last edited by

                          @lavolp3 what do you mean by “more specific”?

                          S 1 Reply Last reply Reply Quote 0
                          • S Offline
                            sdetweil @corius
                            last edited by

                            @corius did u have an event within the next 15 minutes?

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            C 1 Reply Last reply Reply Quote 0
                            • S Offline
                              sdetweil @corius
                              last edited by sdetweil

                              @corius >what do you mean by “more specific”?

                              all the questions we have been asking… title, time filter, number to show, …

                              Sam

                              How to add modules

                              learning how to use browser developers window for css changes

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                corius @sdetweil
                                last edited by

                                @sdetweil yes i have

                                1 Reply Last reply Reply Quote 0
                                • lavolp3L Offline
                                  lavolp3 Module Developer @corius
                                  last edited by

                                  @corius Well to be honest I did not expect it to work from scratch. But I am considering taking this into my own mirror to remind me of taking out the trash. :smiling_face:
                                  I won’t get it done today.
                                  If you don’t know how to work on from here I need to ask for your patience, and I’ll have a closer look at it myself in the next days.

                                  How to troubleshoot modules
                                  MMM-soccer v2, MMM-AVStock

                                  S 1 Reply Last reply Reply Quote 0
                                  • S Offline
                                    sdetweil @lavolp3
                                    last edited by sdetweil

                                    @lavolp3 i am debugging it now

                                    not making any progress… can’t get the time compare to work

                                    let now = moment()
                                    let end = now.add(15, "minutes")
                                    let event_time=moment(event.startDate)
                                    if(event_time.isAfter(now) && event_time.isBefore(end))
                                    

                                    its 11:53, event starts at 12:00 and ends as 12:15

                                    so 12:00.isAfter(11:53) should be true, but is false
                                    and 12:00.isBefore(12:08), should be true,m but is false
                                    

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    1 Reply Last reply Reply Quote 0
                                    • ? Offline
                                      A Former User
                                      last edited by

                                      I think it’s better to build a new module about alerting events by the condition.

                                      1 Reply Last reply Reply Quote 0
                                      • C Offline
                                        corius
                                        last edited by

                                        @lavolp3 @sdetweil thank you for the time you have spent so far. I would be happy if someone else has an idea how to implement it. Thanks:smiling_face:

                                        lavolp3L 1 Reply Last reply Reply Quote 0
                                        • lavolp3L Offline
                                          lavolp3 Module Developer @corius
                                          last edited by lavolp3

                                          @corius So I tamed the beast but I’m getting the feeling that @Sean is right.

                                          The following would alert you of the next event every time the calendar sends a calendar_event notification:

                                          	{
                                          	  module: "MMM-NotificationTrigger",
                                          	  config: {
                                          		triggers:[
                                          		  {
                                          			trigger: "CALENDAR_EVENTS",
                                          			fires: [
                                          				{
                                          					fire:"SHOW_ALERT",
                                          					payload: (payload) => {
                                          						var testMessage = "";
                                          						var nextEvent = payload.find(event => event.startDate > moment().format("x"));
                                          						testMessage = nextEvent.title + " " + moment(nextEvent.startDate, "x").format("HH:mm");
                                          						return {
                                          							type: "notification",
                                          							title: "Next event:",
                                          							message: testMessage
                                          						} 
                                          					},
                                          				}
                                          			],
                                          		  },
                                          		]
                                          	  }	
                                          	}, 
                                          

                                          For some yet unknown reason, I am getting this alert 8 times! The alert then vanishes quite shortly after.

                                          It is a good idea, but what I would do, no, WILL do, is implement a “Notification Alert Function” directly into the calendar module (or into MMM-CalendarExt, if you’re interested, @Sean).
                                          I think that would be a better way of ontrolling the alert created from a calendar event appearing.

                                          How to troubleshoot modules
                                          MMM-soccer v2, MMM-AVStock

                                          S 1 Reply Last reply Reply Quote 0
                                          • S Offline
                                            sdetweil @lavolp3
                                            last edited by

                                            @lavolp3 said in MMM-NotificationTrigger transform payload:

                                            For some yet unknown reason, I am getting this alert 8 times! The alert then vanishes quite shortly after.

                                            because it still sends an alert notification, with an empty payload

                                            fire:“SHOW_ALERT”, (always)

                                            Sam

                                            How to add modules

                                            learning how to use browser developers window for css changes

                                            lavolp3L 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • 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