Night Sky Pi Ntfy

It’s exciting to have created the first Night Sky Pi (NSP) module! This module is intentionally simple, as I wanted to explore what it takes to define and build a module for the Night Sky Pi system.

The NSP Ntfy module, hosted on GitHub, monitors configured MQTT topics for the Night Sky Pi and sends notifications using ntfy.sh. The module uses two configuration files: the first is specific to the module itself, while the second is the configuration file for the Night Sky Pi. This second file must be present, as the module is designed to run on the same device as the Night Sky Pi to communicate with the MQTT broker, which is set to local-only.

The configuration file for the module is quite straightforward. It consists of a list of settings, with each configuration defining a fully qualified MQTT topic name. Along with the MQTT topic, it also specifies an ntfy topic to publish to, as well as metadata like tags and priority.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
{
    "configurations": [
        {
            "mqtt_topic": "mqtt-topic",
            "ntfy": {
                "topic": "ntfy-topic",
                "options": {
                    "title": "notification-title",
                    "priority": 3,
                    "tags": [
                        "blue_square"
                    ]
                }
            }
        }
    ],
    "logging": {
        "file": "nsp-ntfy.log",
        "level": "DEBUG"
    }
}

An additional requirement for the module configuration is to include specific logging information for the module. This follows the same process as the Night Sky Pi, where the NSP handles the overall logging details such as file locations, rollover settings, and formatting. Meanwhile, the module itself specifies the log file name and the logging level.

How is it working?

Once the configurations are provided, the module starts as a service on the same device as the Night Sky Pi. When nsp-ntfy starts up, it processes the configurations, connects to the broker provided by the Night Sky Pi, or terminates if MQTT is disabled. Once connected, it goes through the module configurations and subscribes to each of the specified MQTT topics.

When a message is published on a subscribed topic, the module searches the configuration for that topic to retrieve the corresponding ntfy settings. It then parses the JSON of the MQTT message, which is a requirement for all Night Sky Pi and NSP modules using MQTT. The message must include a field called "notification", which is used as the payload for the ntfy notification.

Finally, a request is sent to ntfy.sh, with the "notification" field as the message payload. The title, emojis (from the tags list), and priority are set based on the configuration.


↤ Night Sky Pi Released
Smigle Lite Release ↦