├── .gitignore
├── LICENSE
├── README.md
├── mmm-systemtemperature.css
├── mmm-systemtemperature.js
├── node_helper.js
├── package-lock.json
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Michael Teeuw
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Module: MMM-SystemTemperature
2 | This MagicMirror modules allows you to show your processor temperature on you mirror.
3 | It also allows to safely shutdown the Raspberry Pi using [MMM-Remote-Control](https://github.com/Jopyth/MMM-Remote-Control) if you configure it.
4 |
5 | ## Installation
6 |
7 | In your terminal, go to your MagicMirror's Module folder:
8 | ````
9 | cd ~/MagicMirror/modules
10 | ````
11 |
12 | Clone this repository:
13 | ````
14 | git clone https://github.com/MichMich/mmm-systemtemperature.git
15 | ````
16 |
17 | Install dependencies:
18 | ````
19 | npm install
20 | ````
21 |
22 | Configure the module in your `config.js` file.
23 |
24 | ## Using the module
25 |
26 | To use this module, add it to the modules array in the `config/config.js` file:
27 | ````javascript
28 | modules: [
29 | {
30 | module: 'mmm-systemtemperature',
31 | position: 'top_center', // This can be any of the regions.
32 | classes: 'small dimmed', // Add your own styling. Optional.
33 | config: {
34 | // See 'Configuration options' for more information.
35 | }
36 | }
37 | ]
38 | ````
39 |
40 | ## Configuration options
41 |
42 | The following properties can be configured:
43 |
44 |
45 |
46 |
47 |
48 | Option |
49 | Description |
50 |
51 |
52 |
53 |
54 | prependString |
55 | The text that will be shown before the temperature.
56 | Default value: 'System temperature: '
57 | |
58 |
59 |
60 | updateInterval |
61 | How often does the content needs to be fetched? (Milliseconds)
62 | Possible values: 1000 - 86400000
63 | Default value: 5000 (5 seconds)
64 | |
65 |
66 |
67 | animationSpeed |
68 | Speed of the update animation. (Milliseconds)
69 | Possible values: 0 - 5000
70 | Default value: 0 (animation off)
71 | |
72 |
73 |
74 | unit |
75 | Temperature unit of measurement
76 | Possible values: c (Celsius), f (fahrenheit), k (Kelvin)
77 | Default value: c (Celsius)
78 | |
79 |
80 |
81 | warning |
82 | Specific config for warning state
83 | Possible values: { temp: 0-999, color: '#HEX', command: Object }
84 | Default value: { temp: 60, color: 'orange', command: undefined }
85 | |
86 |
87 |
88 | critical |
89 | Specific config for critical state
90 | Possible values: { temp: 0-999, color: '#HEX', command: Object }
91 | Default value: { temp: 75, color: 'red', command: { notification: 'REMOTE_ACTION', payload: { action: 'SHUTDOWN' } } }
92 | NOTE: The REMOTE_ACTION notification (SHUTDOWN and MONITOROFF ) actions require the MMM-Remote-Control module to be installed.
93 | |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/mmm-systemtemperature.css:
--------------------------------------------------------------------------------
1 | .mmm-systemtemperature .temperatureUnit::before {
2 | content: '°';
3 | display: inline;
4 | }
--------------------------------------------------------------------------------
/mmm-systemtemperature.js:
--------------------------------------------------------------------------------
1 | Module.register("mmm-systemtemperature",{
2 |
3 | defaults: {
4 | prependString: 'System temperature: ',
5 | updateInterval: 5000,
6 | animationSpeed: 0,
7 | unit: 'c',
8 | warning: { temp: 60, color: 'orange', command: undefined },
9 | critical: { temp: 75, color: 'red', command: { notification: 'REMOTE_ACTION', payload: { action: 'SHUTDOWN' } } }
10 | },
11 |
12 | getStyles: function () {
13 | return ["mmm-systemtemperature.css", "font-awesome.css"];
14 | },
15 |
16 | getScripts: function () {
17 | return [`modules/${this.name}/node_modules/lodash/lodash.js`];
18 | },
19 |
20 | start: function() {
21 | this.sendSocketNotification('CONFIG', this.config);
22 | this.config.unit = this.config.unit && this.config.unit.toLowerCase();
23 | this.commandExecutor = this.getCommandExecutor();
24 | },
25 |
26 | socketNotificationReceived: function(notification, payload) {
27 | if (notification === 'TEMPERATURE') {
28 | this.temperature = parseFloat(payload);
29 | this.stateConfig = this.getStateConfigByTemperature() || {};
30 | this.updateDom(this.config.animationSpeed);
31 | this.commandExecutor();
32 | }
33 | },
34 |
35 | getDom: function() {
36 | var wrapper = document.createElement("div");
37 | if (this.temperature) {
38 | wrapper.innerHTML = this.config.prependString + this.getTemperatureLabel();
39 | wrapper.style.color = this.stateConfig.color || "";
40 | } else {
41 | wrapper.innerHTML = ` ${this.translate("LOADING")}`;
42 | }
43 | return wrapper;
44 | },
45 |
46 | getTemperatureLabel: function() {
47 | return `
48 | ${this.getConvertedTemperature()}
49 | ${this.config.unit.toUpperCase()}
50 | `;
51 | },
52 |
53 | getStateConfigByTemperature: function() {
54 | if (this.config.critical && this.temperature >= this.config.critical.temp) {
55 | return this.config.critical;
56 | } else if (this.config.warning && this.temperature >= this.config.warning.temp) {
57 | return this.config.warning;
58 | }
59 | },
60 |
61 | getConvertedTemperature: function() {
62 | if (this.temperature && this.config.unit !== 'c') {
63 | var convertedTemperature;
64 | if (this.config.unit === 'f') {
65 | convertedTemperature = this.temperature * 9 / 5 + 32;
66 | } else if (this.config.unit === 'k') {
67 | convertedTemperature = this.temperature - 273.15;
68 | }
69 | // Round off the temperature to 2 decimal places
70 | return Math.round(convertedTemperature * 100) / 100;
71 | }
72 | return this.temperature;
73 | },
74 |
75 | getCommandExecutor: function() {
76 | return _.throttle(() => {
77 | if (this.stateConfig && this.stateConfig.command) {
78 | const command = this.stateConfig.command;
79 | this.sendNotification(command.notification, command.payload);
80 | }
81 | }, this.config.updateInterval * 5, { leading: false, trailing: true });
82 | }
83 |
84 | });
85 |
--------------------------------------------------------------------------------
/node_helper.js:
--------------------------------------------------------------------------------
1 | var NodeHelper = require("node_helper");
2 | var exec = require('child_process').exec;
3 |
4 | module.exports = NodeHelper.create({
5 | start: function() {
6 | console.log("Starting node helper: " + this.name);
7 | },
8 |
9 | // Subclass socketNotificationReceived received.
10 | socketNotificationReceived: function(notification, payload) {
11 | if (notification === 'CONFIG') {
12 | this.config = payload;
13 | setInterval(() => {
14 | this.sendTemperature();
15 | }, this.config.updateInterval);
16 | }
17 | },
18 |
19 | sendTemperature: function() {
20 | var command = "cat /sys/class/thermal/thermal_zone*/temp"
21 |
22 | exec(command, (error, stdout, stderr) => {
23 | if (error) {
24 | console.log(error);
25 | return;
26 | }
27 | var temperatures = stdout.trim().split('\n').map((t) => parseInt(t));
28 | var average = temperatures.reduce((a, b) => a + b, 0) / temperatures.length || 0;
29 | this.sendSocketNotification('TEMPERATURE', (average / 1000).toFixed(2));
30 | });
31 | }
32 | });
33 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mmm-systemtemperature",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "lodash": {
8 | "version": "4.17.20",
9 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
10 | "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mmm-systemtemperature",
3 | "version": "1.0.0",
4 | "description": "A MagicMirror module that displays your processor temperature on you mirror.",
5 | "repository": {
6 | "type": "git",
7 | "url": "git+https://github.com/MichMich/mmm-systemtemperature"
8 | },
9 | "main": "mmm-systemtemperature.js",
10 | "scripts": {
11 | "test": "echo \"Error: no test specified\" && exit 1"
12 | },
13 | "author": "Michael Teeuw",
14 | "contributors": [
15 | {
16 | "name": "Alvaro Naveda",
17 | "email": "alvaro@naveda.me",
18 | "url": "https://github.com/naveda89/"
19 | }
20 | ],
21 | "license": "MIT",
22 | "dependencies": {
23 | "lodash": ">=4.17.19"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------