npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mmm-mqtt

v1.1.1

Published

Show payload from subscribed MQTT message

Downloads

5

Readme

MQTT

Module for MagicMirror showing the payload of a message from MQTT.

Screenshot

Screenshot

Installasjon

Go to MagicMirror/modules and write

git clone https://github.com/ottopaulsen/MMM-MQTT
cd MMM-MQTT
npm install

Configuration

Here is an example configuration with description. Put it in the MagicMirror/config/config.js file:

{
  module: 'MMM-MQTT',
  position: 'bottom_left',
  header: 'MQTT',
  config: {
    logging: false,
    useWildcards: false,
    mqttServers: [
      {
        address: 'localhost',  // Server address or IP address
        port: '1883',          // Port number if other than default
        // ca: '/path/to/ca/cert.crt', // Path to trusted CA certificate file (optional)
        // clientId: 'mirror',     // Custom MQTT client ID (optional)
        user: 'user',          // Leave out for no user
        password: 'password',      // Leave out for no password
        subscriptions: [
          {
            topic: 'smoky/1/inside/temperature', // Topic to look for
            label: 'Temperature', // Displayed in front of value
            suffix: '°C',         // Displayed after the value
            decimals: 1,          // Round numbers to this number of decimals
            sortOrder: 10,        // Can be used to sort entries in the same table
            maxAgeSeconds: 60,    // Reduce intensity if value is older
            broadcast: true,      // Broadcast messages to other modules
            colors: [             // Value dependent colors
              { upTo: -10, value: "blue", label: "blue", suffix: "blue" },
              { upTo: 0, value: "#00ccff", label: "#00ccff", suffix: "#00ccff" },
              { upTo: 10, value: "yellow"},
              { upTo: 25, label: "green", suffix: "green" },
              { upTo: 100, label: "red" }, // The last one is used for higher values too
            ],
          },
          {
            topic: 'smoky/1/inside/humidity',
            label: 'Luftfuktighet',
            suffix: '%',
            decimals: 0,
            sortOrder: 20,
            maxAgeSeconds: 60 
          },
          {
            topic: 'smoky/2/inside/temperature',
            label: 'Temp ute',
            decimals: 1,
            decimalSignInMessage: ",", // If the message decimal point is not "."
            sortOrder: 20,
            maxAgeSeconds: 60
          },
          {
            topic: 'smoky/1/inside/smoke',
            label: 'Røyk',
            sortOrder: 30,
            divide: 10, // Divide numeric values. Alternatively use `multiply`.
            maxAgeSeconds: 60
          },
          {
            topic: 'guests',
            label: 'First guest',
            jsonpointer: '/people/0/name'
          },
          {
            topic: 'powerprices',
            label: 'Power prices',
            broadcast: true,
            hidden: true    // Do not display in the table
          },
          {
            topic: "house/1/doors/1",
            label: "Door",
            conversions: [
              { from: "true", to: "Open" },
              { from: "false", to: "Closed" }
            ]
          }
        ]
      }
    ],
  }
}

mqttServers is an array, so you can add multiple servers to the same config. You can also use the module in multiple places on the mirror/screen.

JSON Data

If the payload contains JSON data, use the jsonpointer configuration to get the value. See JSON Ponter specification or google an easier description.

Wildcards

Wildcard "+" is supported in topics, but it only works on some platforms (Chrome, Electron). Set the useWildcards config to true for wildcards to work.

Conversions

Use the conversions config to convert values from one to another. If there is no match, the received value is used.

For numeric values, you can use multiply or divide to multiply or divide values before they are displayed. See example with divide above.

You can also use this to display icons. Example:

conversions: [
  {
    from: "on",
    to: "<i class='fas fa-toggle-on' style='color:green'></i>",
  },
  {
    from: "off",
    to: "<i class='fas fa-toggle-off' style='color:red'></i>",
  },
];

Broadcasting messages

By setting config variable broadcast: true for a given topic, every message with that topic is broadcasted to every other module using sendNotification with notification identifier MQTT_MESSAGE_RECEIVED. This can then be received by any other module using receiveNotification.

Hide table entry at specified value

You can hide the complete table entry if the value is like defined.

In this example we only show the green button if value is 'on'. If the value is 'off' the whole line is hidden.

conversions: [
  {
    from: "on",
    to: "<i class='fas fa-toggle-on' style='color:green'></i>",
  },
  {
    from: "off",
    to: "#DISABLED#",
  },
];

Colored values

For numeric values, color codes can be configured using the colors array in the subscription config. If you are using the same color scheme on multiple topics, you can configure it as a constant above the config variable like this:

const humidityColors = [
  {upTo: 95, value: ''},
  {upTo: 100, value: '#1a1aff'},
];

var config = {
    ...

and then refer to it like this:

colors: humidityColors;

Styling

General styling can be done in the MQTT.css file. The table header can be styled using locator #module_3_MMM-MQTT > header. The column text can be styled using the following classes:

.mqtt-label {
}
.mqtt-value {
}
.mqtt-suffix {
}

Collaborate

Pull requests are welcome.

Thanks to

Thanks to Jan Lehnardt for the jsonpointer.js file. I had to copy it from the repo and make a small change, in order to be able to use it from both the module helper and the module file.

The topic_match code is also copied

TO DO

Create a timeout, so values are deleted if they are not refreshed. May be faded out...

Create a threshold so a value is flashing if outside threshold.

Make a filter so a row is displayed only if a value satisfies certain criteria. To be used f.eks. when a battery level is too low.

Make a sound when a specific value changes.