Skip to main content

MQtfy - A ntfy <-> mqtt gateway. Subscribes to ntfy and mqtt topics and sends these to the other side ;)

Project description

MQtfy - Ntfy Mqtt Gateway

Send MQTT Messages to send ntfy Notifications and subscribe to ntfy to send them to mqtt

Installation

Local

$ pip install mqtfy 
$ mqtfy # first run will end up in a error message, that you do not have a config. The script tries to download one for your version
# Update your config file (config.yaml)
$ mqtfy

Docker

Todo

Configuration

See example file (config.yaml.example). Just do a:

cp config.yaml.example config.yaml

and edit the file to your needs.

mqtt_host: "mqtt.local"             # MQTT Host
mqtt_port: 1883                     # MQTT Port
mqtt_user: "mqttuser"               # MQTT User (remove if not needed)
mqtt_pass: "mqttpass"               # MQTT Password (remove if not needed)
mqtt_topic: "mqtfy/"                # MQTT Topic
mqtt_client_id: "mqtfy"             # MQTT client id
ntfy_url: "https://ntfy.sh"         # ntfy url
log_level: "INFO"                   # Log lebvel
receive_only_message: True          # do you want the ntfy message (true) or the entire body (false)
ignore_events: keepalive, open      # some events are not really helpful

# subtopics to subscribe to (mqtt and ntfy)
subtopics:
  - topic: "foo"                    # ntfy topic
    ntfy_user: "user1"              # ntfy user for that topic
    ntfy_pass: "pass1"              # ntfy password for that user
  - topic: "bar"
    ntfy_url: "https://ntfy.example.com"  # optional - if not pressent, it uses the global configured ntfy_url
    ntfy_user: "user2"
    ntfy_pass: "pass2"

It might be a good idea to set log_level while you are configuring to DEBUG

Usage

Create your configuration File and just run mqtfy

MQTT -> ntfy

By default, MQtfy will listen to mqtfy/. MQtfy will send messages to the ntfy server by sending the message to mqtfy/send/myTopic. The Message content is a Json with all the attributes you want, just follow the documentation.

The only exception is that the topic of the Message will be set/replaced by the part after /mqtfy/send/. In our example here the ntfy topic in the json will be set to myTopic.

To stay close to the documentation, here is an example:

mosquitto_pub -h mqtt.local -t "mqtfy/send/myTest" -m '{
    "topic": "WILL_BE_OVERWRITTEN_BY -> myTest    ⬆️",
    "message": "Disk space is low at 5.1 GB",
    "title": "Low disk space alert",
    "tags": ["warning","cd"],
    "priority": 4,
    "attach": "https://filesrv.lan/space.jpg",
    "filename": "diskspace.jpg",
    "click": "https://homecamera.lan/xasds1h2xsSsa/",
    "actions": [{ "action": "view", "label": "Admin panel", "url": "https://filesrv.lan/admin" }]
  }'

Or a simple version:

mosquitto_pub -h mqtt.local -t "mqtfy/send/myTest" -m '{
    "message": "Disk space is low at 5.1 GB"
  }'

Or even a more simplified version:

mosquitto_pub -h mqtt.local -t "mqtfy/send/myTest" -m 'Disk space is low at 5.1 GB'

ntfy -> MQTT

All messages will be published into the topic mqtfy/receive/ntfy-TOPIC

Todo

  • Allow Strings as ntfy messages (Simple version)
  • Implement a switch to not publish mqtt messages which are sent by mqtfy (mqtt -> ntfy -> mqtt)
  • Add default values which can be added for a topic into the configuration file (Eg. the topic doorbell could always get a tag 'bell' for a 🔔)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mqtfy-0.3.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mqtfy-0.3.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file mqtfy-0.3.1.tar.gz.

File metadata

  • Download URL: mqtfy-0.3.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for mqtfy-0.3.1.tar.gz
Algorithm Hash digest
SHA256 9f2f503976fec611936043b70b34d6e526c6a2d3737f4d1a19a8583aadf54962
MD5 70d35908096adaf176d50f778389dfc0
BLAKE2b-256 062bdf533db43c91a6e6210470f97c0c61c455f639b94cca2b121d2361060ad4

See more details on using hashes here.

File details

Details for the file mqtfy-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: mqtfy-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for mqtfy-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e765fc76519f2410b8103ca12c8b035a5242911d916ffc708a3bf77058c875a8
MD5 489b86e5ab54e40b94da3d83b23721f5
BLAKE2b-256 db6874bdb66fc246bae8f34ec2220dc2eaab223b2793e9c24db63124fb3eec78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page