MQTT_Collector
On your display
subscripe to a mqtt channel and provide its values for other scripts
- Topic
- Smarthome
- Includes
- Script
Runs on
- Runs on 32×8 (TC001 & DIY)
- Runs on 52×16 (TC002)
- Does not run on 32×8 with AWTRIX 3 (TC001 & DIY) Made for AWTRIX NG.
Choose your display in the next step.
Script description
Overview
The MQTT Collector is a headless background script (# @headless true) designed to aggregate multiple data points dynamically under a single base topic. Instead of spawning heavy individual MQTT subscriptions for every single sensor, this script listens to a wildcard path and seamlessly hands the values over to your display apps via global shared memory.
How it Works
- It listens to a dynamic topic path like
AwtrixNG/DataCollector/+. - When a message arrives, it automatically extracts the last part of the topic as the key name (e.g.,
PVpowerorBatterySOC). - It checks the timestamp map. If the value arrived faster than your configured threshold, it drops the payload immediately to save CPU cycles and RAM.
- If approved, it updates the timestamp and publishes the payload globally as
mqtt_collector.<key_name>.
Setup Instructions
-
Install the Script:
- Open your AWTRIX web interface.
- Go to the Scripts tab, create a new script, and name it exactly
mqtt_collector. - Paste the Berry code into the editor and press Save (
Ctrl+S).
-
Configure via Web UI:
- Go to the Apps tab.
- Click the Gear icon on the
MQTT Collectorrow. - MQTT Basis-Topic: Set this to your preferred path ending with a wildcard
+(Default:AwtrixNG/DataCollector/+). - min. Interval (seconds): Choose how many seconds a specific data point must "cool down" before a new value is accepted (Default:
5seconds). Set to0to disable throttling. - Log messages: Toggle
trueif you want to inspect incoming data streams in your AWTRIX console.
-
Read Data in your Display Apps:
- Your custom display apps can easily fetch any collected value directly from any method using:
var my_value = shared.get("mqtt_collector.YOUR_DATA_POINT_NAME")
- Your custom display apps can easily fetch any collected value directly from any method using:
Sign in to view and copy the code of this script.
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
Have an idea?
Sign in to ask questions and join the conversation.