MMM-CustomText is a module for MagicMirror². It posts any message you want to your MagicMirror. Multiple instances are supported. Message can be updated via notification. And messages can include HTML elements including CSS formatting.
The main differences between this and MMM-CustomMessage are that (1) this module allows separately updating multiple instances, (2) this module primarily employs the MagicMirror notification system for updating messages, and (3) this module completely collapses to 0 pixels in height by default when no message is displayed.
Suggestions are welcome.
cd ~/MagicMirror/modules
git clone https://github.com/dathbe/MMM-CustomTextDependencies:
- None!
- But you likely want MMM-Remote-Control installed to allow posting of messages via API
cd ~/MagicMirror/modules/MMM-CustomText
git pullTo use this module, add it to the modules array in your ~/MagicMirror/config/config.js file:
{
module: 'MMM-CustomText',
position: 'top_bar',
config: {
initialMessage: "I posted my first message!",
uniqueID: "myUniqueID",
animationSpeed: 1000 * 2,
},
},The following properties can be configured:
| Option | Description |
|---|---|
initialMessage |
Optional A message you would like to display when MagicMirror loads Type: stringDefault: "No notification received yet" |
uniqueID |
Optional, but necessary if you plan to have multiple instances of this module in your config file. Give each instance a unique uniqueID that you can pass in notifications (see below)Type: anything Default: null |
animationSpeed |
Optional The speed of animated transitions from one message to another in milliseconds Type: intDefault: 2000 (2 seconds) |
You can update the message displayed by this module using a CUSTOMTEXT_UPDATE notification. Pass the message and, if you have more than one instance of the module, the uniqueID of the instance in a json object:
{
"uniqueID": "myUniqueID",
"message": "I posted a notification message!"
}For example, if you wanted to create such a notification in python, install the MMM-Remote-Control module, and then you can execute the following script:
import requests
accesstoken = 'mYsUpErSeCrEtToKeN'
header = {'Authorization': f"Bearer {accesstoken}", 'Content-type': 'application/json'}
message =
json = {
"uniqueID": "myUniqueID",
"message": "<div style='background-color:#f19b52'>I posted a notification message!</div>"
}
x = requests.post('http://localhost:8080/api/notification/CUSTOMTEXT_UPDATE', json=json, headers=header)- Both the initial message and any subsequent message posted by notification will accept standard HTML elements within the string. That means you could, for example, style the message using inline CSS or by giving the message a class name and using
~/MagicMirror/css/custom/css. You could also insert more complex elements like a table. - You can clear the message from the display by posting
""via notification. If the message is""--either viainitialMessageor a notification posting--it should collapse the module so that no unnecessary space is taken up on your display. If you want the module to take up a fixed height on your display regardless of the length of the message, you should be able to set this in~/MagicMirror/css/custom.css. - If you only have one instance of this module in your config (or you want to update all instances at the same time) and you have not set an explicit
uniqueIDin your config, you do not need to pass auniqueIDin your notification. The module will update no matter what you pass asuniqueID, or if you pass nothing at all.
If you find any problems, bugs or have questions, please open a GitHub issue in this repository.
Pull requests are of course also very welcome 🙂
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
You will need to first install the dev dependencies:
cd ~/MagicMirror/modules/MMM-CustomText
npm installnode --run lint- Run linting checks.node --run lint:fix- Fix automatically fixable linting errors.
This project is licensed under the MIT License - see the LICENSE file for details.
Special thank you to jpcaldwell30, who created the MMM-CustomMessage, which this is based on. He did most of the work.
