Skip to content

MMM GPIO Notifications & MMM NotificationTrigger collaboration

Seongnoh Sean Yi edited this page Sep 25, 2024 · 1 revision

When trying to control CX3 with a button connected to GPIO using MMM-GPIO-Notifications, a simple payload is fine, but using a callback function doesn't work properly.

The reason is that MMM-GPIO-Notifications sends the payload to node_helper and then receives it back. In this process, the payload is JSONified, so values ​​such as function or undefined disappear.

So, if you want to control CX3 with MMM-GPIO-Notifications, it doesn't work right away, and you need to use an intermediary module such as MMM-NotificationTrigger in the middle. MMM-GPIO-Notifications sends a simple notification, and MMM-NotificationTrigger that receives it sends a complex notification.

{
  module: 'MMM-GPIO-Notifications',
  config: {
    '17': {
      notifications_low: [
        {
          notification: 'NEXT_MONTH',
        },
      ]
    },
  }
},

{
  module: "MMM-NotificationTrigger",
  config: {
    useWebhook: false,
    triggers: [
      {
        trigger: "NEXT_MONTH",
        fires: [
          {
            fire: "CX3_GET_CONFIG",
            payload: {
              callback: (currentMonthConfig) => {
                const self = MM.getModules().find(m => m.name === "MMM-NotificationTrigger")
                self.sendNotification("CX3_SET_CONFIG", {
                  monthIndex: currentMonthConfig.monthIndex + 1
                })
              }
            }
          }
        ]
      },
    ]
  }
},