Skip to content

New Share your ideas with the AWTRIX community. Keep your creations together in your account.

Sign in

Which AWTRIX do you have? Choose it once and the Hub shows what runs on it.

ScriptAWTRIX NG

MQTT_Collector

On an AWTRIX display
MQTT_Collector shown on an AWTRIX display
MQTT_Collector · by donaldo_duck

On your display

subscripe to a mqtt channel and provide its values for other scripts

Which AWTRIX do you have? See below where it runs, or choose your device.
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.

Send to AWTRIX

Choose your AWTRIX

MQTT_CollectorAWTRIX NG script

Install this script on your AWTRIX NG. Its icons and sounds are installed with it.

Your AWTRIX’s local address, for example 192.168.178.39 or awtrix.local.

The name shown in your AWTRIX script list. Use letters, digits, hyphens or underscores.

Connection & device login

Connect your phone or computer to the same network as your AWTRIX. Allow local network access if your browser asks.

Use the device’s IP address, without a page path such as /#/apps.

If your AWTRIX requires a login, the username and password fields will appear when you connect.

Sign in to the Hub to install scripts. Attached files are installed separately.

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

  1. It listens to a dynamic topic path like AwtrixNG/DataCollector/+.
  2. When a message arrives, it automatically extracts the last part of the topic as the key name (e.g., PVpower or BatterySOC).
  3. 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.
  4. If approved, it updates the timestamp and publishes the payload globally as mqtt_collector.<key_name>.

Setup Instructions

  1. 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).
  2. Configure via Web UI:

    • Go to the Apps tab.
    • Click the Gear icon on the MQTT Collector row.
    • 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: 5 seconds). Set to 0 to disable throttling.
    • Log messages: Toggle true if you want to inspect incoming data streams in your AWTRIX console.
  3. 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")
      

More scripts in Smarthome

Something wrong with this script? Report it.