GithubHelp home page GithubHelp logo

tom-hirschberger / mmm-commandtonotification Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 473 KB

A MagicMirror² module which peridocally calls configured scripts and sends the output as notification

License: MIT License

JavaScript 51.46% Python 43.89% Shell 4.65%
magicmirror-module magicmirror2 dht11 dht22 temperature bme280 ds18b20 flowercare htu21d miflora

mmm-commandtonotification's Introduction

MMM-CommandToNotification

MagicMirror² module which periodically calls configured scripts and sends the output as value of configurable notifications. The values can be displayed in modules like MMM-ValuesByNotification.

Example scripts to read the temperature values of DHT11, DHT22, DS18B20, HTU21 or BME280 connected to the raspbarry or Miflora sensors in reach of bluetooth are included in the scripts directory. There is a documentation in the scripts directory, too.

Basic installation

cd ~/MagicMirror/modules
git clone https://github.com/Tom-Hirschberger/MMM-CommandToNotification
cd MMM-CommandToNotification
npm install

Basic configuration

Add the following code to your ~/MagicMirror/config/config.js:

  {
   module: "MMM-CommandToNotification",
   disabled: false,
   config: {
    commands: [
    ]
   },
  },

General

Option Description Type Default
updateInterval How often should the scripts be iterated (in seconds) Integer 30
commands A array containing the command definition objects Array []
sync Should the commands called one by one (true) or should all be started as fast as possible (false). Can be overriden for each command in the command configuration Boolean true
debug This flag controls if debug messages should be output on the console Boolean false

Commands

Option Description Mandatory Type Default
script Either a absolute path or the realtive path of a script starting at the "scripts" directory. true String null
args Arguments which should be passed to the script false String ""
timeout Should the script be killed if it does not return within a specific amount of milliseconds? false Integer infinity
notifications A array containing names of the notifications to send if script returns output. If not present the script gets called but no notification will be send. If you want to override the payload instead of using the output please look at the notification section. false Array []
sync Should the command by run synchronous (next command will be called after this one, true) or asynchronous (directly proceed with the next one and process output when the command finishes, false) Boolean true
delayNext Wait some amount of time (milliseconds) before the next command will be processed after this one has called. Make sure to set to updateInterval of the module to a value that is enough time to call and process all commands with all delays summed up! Integer 0
conditions A map containing conditions that need to match to send the notifications false Map null

Notifications

The notifications array contains all notifications that should be send if a command is called (and the conditions matched). There may be situations where you want send a notification with a specific payload instead of the output of the script. You can do so if you specify a array instead of the string identifiying the notification. Lets see the following example:

notifications: [
  ["TEST1","MY_NEW_PAYLOAD"],
  "TEST2",
],

In this example the notification "TEST1" will have "MY_NEW_PAYLOAD" as output while "TEST2" contains the output of the command.

Conditions

All conditions specified need to match to send notifications!

Option Description Type Default
returnCode Specify either a single return code or a array of return codes that need to match. If a array is specified one of the values need to match (or condition). Integer or Array of Integer null
outputContains Specify either a single string or a array of possible strings which of one need to be present in the output (or condition). null

Example

Add the following example to produce the following result:

  • the scripts will be iterated every 10 seconds
  • the script "scripts/randomInteger.js" gets called every iteration
    • a random number between -10 and 10 is produced
    • the timeout of the script is 5 seconds. If the script does not produce any output within 5 seconds the call will be aborted and no notifications will be send
    • if the script produces output the output will be send as payload of the notifications TEST1 and TEST2
  • the script "scripts/randomNumberJson.js" will be called every fourth iteration because a three skips are configured
    • the script calculates a random number between -50 and 20 and produces a json object containing two values ("integer" and "float"). The float value is the random number the integer value the random number rounded as integer.
    • the timeout of the script is set to 10 seconds
    • the result of the script (JSON object as string) will be send as payload of notification TEST3 while TEST4 will be send with payload "true"
    • As the condition returnCode is set to [0,1,2] the notifications TEST3 and TEST4 only will be send if the script ./randomNumberJson.js only will be send if the script exits with code 0, 1 or 2
  {
   module: "MMM-CommandToNotification",
   disabled: false,
   config: {
    updateInterval: 10,
    commands: [
     {
      script: "./randomInteger.js",
      args: "-10 10",
      timeout: 5,
      notifications: [
       "TEST1",
       "TEST2",
      ],
     },
     {
      script: "./randomNumberJson.js",
      args: "-50 20",
      skips: 3,
      timeout: 10,
      conditions: {
        returnCode: [0,1,2]
      }
      notifications: [
       "TEST3",
       ["TEST4", true]
      ],
     }
    ]
   },
  },

My Prusa MK4 3D-Printer setup

Curl->MMM-CommandToNotification->MMM-ValuesByNotification

mmm-commandtonotification's People

Contributors

tom-hirschberger avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

mmm-commandtonotification's Issues

Uncaught exception?

0|MagicMirror  | [24.05.2023 13:42.53.777] [LOG]   MMM-CommandToNotification: Calling commands
0|MagicMirror  | [24.05.2023 13:42.53.779] [LOG]   Running /usr/bin/curl asynchronous
0|MagicMirror  | [24.05.2023 13:42.53.814] [LOG]   Running ~/MagicMirror/modules/MMM-CommandToNotification/scripts/temperature/bme280 asynchronous
0|MagicMirror  | [24.05.2023 13:42.53.849] [LOG]   Running ~/MagicMirror/modules/MMM-CommandToNotification/scripts/temperature/htu21 asynchronous
0|MagicMirror  | [24.05.2023 13:42.53.896] [ERROR] Whoops! There was an uncaught exception...
0|MagicMirror  | [24.05.2023 13:42.53.905] [ERROR] TypeError: Cannot read properties of null (reading 'trim')
0|MagicMirror  |     at ChildProcess.<anonymous> (/home/bkey1970/MagicMirror/modules/MMM-CommandToNotification/node_helper.js:56:86)
0|MagicMirror  |     at ChildProcess.emit (node:events:513:28)
0|MagicMirror  |     at maybeClose (node:internal/child_process:1093:16)
0|MagicMirror  |     at Socket.<anonymous> (node:internal/child_process:451:11)
0|MagicMirror  |     at Socket.emit (node:events:513:28)
0|MagicMirror  |     at Pipe.<anonymous> (node:net:757:14)
0|MagicMirror  | [24.05.2023 13:42.53.905] [ERROR] MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
0|MagicMirror  | [24.05.2023 13:42.53.905] [ERROR] If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
0|MagicMirror  | [24.05.2023 13:42.54.004] [LOG]   curCmdConfig: {"script":"~/MagicMirror/modules/MMM-CommandToNotification/scripts/temperature/bme280","args":"0x77","timeout":5000,"sync":false,"notifications":["TempRoom"]}
0|MagicMirror  | [24.05.2023 13:42.54.272] [INFO]  Calendar-Fetcher: Broadcasting 72 events.
0|MagicMirror  | [24.05.2023 13:42.54.658] [LOG]   curCmdConfig: {"script":"~/MagicMirror/modules/MMM-CommandToNotification/scripts/temperature/htu21","timeout":5000,"sync":false,"notifications":["TempCase"]}

keep getting this randomly. is there anything that can be done? When this happens, all notifications turn to NA.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.