mqttactions
mqttactions is a simple CLI to build simple interactive behavior with MQTT. It's particularly useful for build simple rules for home automation without going to full in on a complex solution like Home Assistant or similar.
For example, mqttactions makes it super simple to listen to an MQTT topic from a switch (e.g., from Zigbee2MQTT) and then publish a message to a different topic to, for example, turn on a light.
Since the automation scripts are just Python, you can do arbitrarily complex things. Want to have a button (via Zigbee2MQTT) that checks if you have a new email and if so, flashes a light 3 times? No problem, just requires some more Python code.
Note that this project is my experimentation with AI-assisted coding. I do look over every change, but I let AI do as much of the work as possible as long as the result is still useful for my own usage.
Installation
mqttactions is available on PyPI and can be installed with pip:
$ pip install mqttactions
Especially if you plan to use complex scripts that require additional packages, it's advisable to install mqttactions in a virtualenv.
Usage
MQTT Actions provides two main commands:
Discover MQTT Devices
Discover devices exposed via the Home Assistant MQTT discovery protocol:
$ mqttactions --host mqtt.example.com discover
This can be used to help figure out what the command and/or state topics of your devices are if they support Home Assistant's MQTT discovery protocol.
Use the --filter option to do a substring match on any of the fields
in case you have many devices.
Run Automation Scripts
Run automation scripts that respond to MQTT messages:
$ mqttactions --host mqtt.example.com run script1.py script2.py
The scripts you pass are imported by the CLI which then runs until you terminate it. Scripts can subscribe to topics and publish messages but also anything else an ordinary Python module could do.
Writing Automation Scripts
Scripts use a simple decorator-based API for reacting to MQTT messages:
from mqttactions import on, publish
@on("some-switch/action", payload="press_1")
def turn_on_light():
publish("some-light/set", {"state": "ON"})
@on("some-switch/action", payload="press_2")
def turn_off_light():
publish("some-light/set", {"state": "OFF"})
Check the examples/ directory for more example scripts that demonstrate
common automation patterns.
The API is currently a very rough first attempt, expect it to evolve in breaking ways for some time.
Metadata
Release files for mqttactions 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mqttactions-0.4.1.tar.gz | 86.7 kB | Without provenance | Details for mqttactions-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mqttactions-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for mqttactions-0.4.1-py3-none-any.whl |
Total release size: 126.2 kB
Release files / mqttactions-0.4.1.tar.gz
| Download URL | mqttactions-0.4.1.tar.gz |
|---|---|
| Size | 86.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ac1da5bc0cd62afc78d0fbccba4676ac24ef405e1e89159e6c275a6575f1820
|
|
BLAKE2b-256 checksum How to use checksums |
1bf3ca79d3d78a686bdd2b13ae367c16fa94e9b0d8fcc8d6c164e00dac01e848
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Release files / mqttactions-0.4.1-py3-none-any.whl
| Download URL | mqttactions-0.4.1-py3-none-any.whl |
|---|---|
| Size | 39.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fee3b41065e2c09bf835c7a60e5df93c5fb82b4ba1eb5e161c9f8ca010bbc3b4
|
|
BLAKE2b-256 checksum How to use checksums |
a864bbef8e4e005e80e0053775df8c9c8ed1e9a4638a55b30c864801e50c8197
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Security for mqttactions 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.