MQTT is the backbone of many home automation setups. With that, it’s often beneficial to know when certain events occur. macOS notifications are a perfect way to solve that problem. Plug in your broker’s host name or IP, credentials, and the topics you’d like to be notified about and you’re off to the races.

Fetaures of MQTTNotify include:

  • Receive notifications for multiple MQTT topics.
  • Supports the use of MQTT topic wildcards.
  • Designate specific MQTT topics as “ignored topics” in case a wildcard topic includes a noisy topic you want to ignore.
  • Full customization of the macOS notifications you receive.
  • Format your notification text using JavaScript.

Documentation

MQTTNotify is fairly straightforward in its design. Where things can be complicated, however, is with formatting notifications. This formatting depends on the type of payload you expect for messages on the topic you’ve subscribed to. You define these topics and the notifications text using the Rules section of the MQTTNotify preferences window.

Payload Types

MQTTNotify supports two different types of message payload types: Text and JSON. This gives you fine grain control of what shows up in your notification’s title and message body. Furthermore, all MQTTNotify messages are parsed as JavaScript! Keep reading to see how you can leverage this new found power.

Text

A text payload type means that the message payload is interpreted as plain text. You can simply insert the following curly-braced statement anywhere into your notification title or message body and the payload will be injected:

{{payload}}

The statement above will be replaced with whatever string is in the message payload. Here’s how to use it in the application:

MQTTNotify Rules Editor

Notice in the message field JavaScript is being used to lower-case the string from the message payload. Extending this further, consider a situation where we receive a message with a payload containing the string “Front Door.” Using the settings above, the notification would look as follows:

MQTTNotify

JSON

A JSON payload type works similarly to the Text payload type, except you have access to all of the members of the JSON object that the message provides. You could have notification text that is as complicated as the following:

The {{payload.Name}} was {{payload.Status ? “opened” : “closed”}}

The statements above would be evaluated and given the following payload:

{ “Name”: “Garage Door”, “Status”: true }

The resulting notification would be: