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-CustomText
No dependencies need to be installed, but you likely want MMM-Remote-Control installed to allow posting of messages via API.
cd ~/MagicMirror/modules/MMM-CustomText
git pull
To 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: string Default: "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: int Default: 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 viainitialMessage
or 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
uniqueID
in your config, you do not need to pass auniqueID
in your notification. The module will update no matter what you pass asuniqueID
, or if you pass nothing at all.
- 2024-3-30: Initial release