Built My First Night Sky Pi Module
So I finally built my first Night Sky Pi module! I decided to keep it pretty simple since I mainly wanted to figure out the whole module-building process without getting lost in complexity.
This little thing (which I’m calling NSP Ntfy) basically just watches for messages on specific MQTT topics and shoots notifications to your phone using ntfy.sh. If you’re curious, the code’s up on GitHub.
The module needs two config files to work properly. One is specific to the module itself, and the other is the main Night Sky Pi config file. I set it up this way because the module needs to run on the same machine as the Night Sky Pi core system to talk to the MQTT broker (which only listens locally for security reasons).
Setting up the module config is pretty straightforward. You basically just tell it which MQTT topics to listen to and what ntfy topic to forward messages to. You can also add some bells and whistles like notification priority and emoji tags:
|
|
I also added a logging section at the bottom. Night Sky Pi handles most of the logging details (like where files go, when to rotate them, etc.), but each module gets to decide its own log file name and debug level.
How’s it working so far?
The module runs as a service alongside Night Sky Pi. When it starts up, it grabs its config, connects to the MQTT broker (or gives up if MQTT isn’t enabled), and subscribes to all the topics you’ve specified.
Whenever a message hits one of those topics, the module looks up the matching ntfy settings, pulls the notification text from the MQTT message (which needs to be valid JSON with a “notification” field), and sends it off to ntfy.sh.
Nothing fancy, but it does the job! I’ve been using it to get alerts when my sensors detect something interesting, and it’s way more convenient than checking logs or a dashboard all the time.