{"id":13583326,"url":"https://github.com/hobbyquaker/mqtt-scripts","last_synced_at":"2025-07-29T00:33:33.962Z","repository":{"id":53783961,"uuid":"42357103","full_name":"hobbyquaker/mqtt-scripts","owner":"hobbyquaker","description":"Node.js based script runner for use in MQTT based Smart Home environments","archived":false,"fork":false,"pushed_at":"2021-03-14T08:58:53.000Z","size":168,"stargazers_count":61,"open_issues_count":10,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-07-21T02:49:23.155Z","etag":null,"topics":["automation","iot","mqtt","nodejs","rules-engine","script-engine","script-runner","scripting","smarthome"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hobbyquaker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-12T12:59:53.000Z","updated_at":"2024-06-26T07:56:29.000Z","dependencies_parsed_at":"2022-08-24T17:11:41.360Z","dependency_job_id":null,"html_url":"https://github.com/hobbyquaker/mqtt-scripts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hobbyquaker/mqtt-scripts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobbyquaker%2Fmqtt-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobbyquaker%2Fmqtt-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobbyquaker%2Fmqtt-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobbyquaker%2Fmqtt-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hobbyquaker","download_url":"https://codeload.github.com/hobbyquaker/mqtt-scripts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hobbyquaker%2Fmqtt-scripts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267610409,"owners_count":24115434,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","iot","mqtt","nodejs","rules-engine","script-engine","script-runner","scripting","smarthome"],"created_at":"2024-08-01T15:03:24.257Z","updated_at":"2025-07-29T00:33:33.933Z","avatar_url":"https://github.com/hobbyquaker.png","language":"JavaScript","readme":"# mqtt-scripts\n\n[![mqtt-smarthome](https://img.shields.io/badge/mqtt-smarthome-blue.svg)](https://github.com/mqtt-smarthome/mqtt-smarthome)\n[![NPM version](https://badge.fury.io/js/mqtt-scripts.svg)](http://badge.fury.io/js/mqtt-scripts)\n[![dependencies Status](https://david-dm.org/hobbyquaker/mqtt-scripts/status.svg)](https://david-dm.org/hobbyquaker/mqtt-scripts)\n[![Build Status](https://travis-ci.org/hobbyquaker/mqtt-scripts.svg?branch=master)](https://travis-ci.org/hobbyquaker/mqtt-scripts)\n[![Coverage Status](https://coveralls.io/repos/github/hobbyquaker/mqtt-scripts/badge.svg?branch=master)](https://coveralls.io/github/hobbyquaker/mqtt-scripts?branch=master)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n[![License][mit-badge]][mit-url]\n\n\u003e mqtt-scripts is a Node.js based script runner for use in mqtt based smart home environments. \n\nIt's intentended to be used as the \"logic layer\" in your smart home, and offers a zero-boilerplate, straight forward \nscripting environment.\n\nIt follows the [mqtt-smarthome](https://github.com/mqtt-smarthome/mqtt-smarthome) architecture. Mqtt-scripts could be \nseen as something like \"Node-RED without GUI\"\n\n\n# Getting started\n\nPrerequisites: mqtt-scripts needs Node.js \u003e= 6.0.\n\n* Install mqtt-scripts globally:\n\n```sudo npm install -g mqtt-scripts```\n\n* Create a folder from where mqtt-scripts will load the scripts:\n\n```mkdir -p /opt/mqtt-smarthome/scripts```\n\n* Create a folder to install node modules that can be used in the scripts:\n\n```mkdir /opt/mqtt-smarthome/scripts/node_modules```    \n(You can then just use npm install in the directory /opt/mqtt-smarthome/scripts)\n\n* Put some files in you script dir:\n\n```\necho \"log.info('my first script!')\" \u003e /opt/mqtt-smarthome/scripts/test1.js\necho \"log.info 'get ma a coffee' \u003e /opt/mqtt-smarthome/scripts/test1.coffee\n```   \n\n* Start mqtt-scripts\n\n```mqtt-scripts -d /opt/mqtt-smarthome/scripts```  \n\n\n### Run with Docker\n\nTo run with Docker, use either a [pre-build image](https://hub.docker.com/r/dersimn/mqtt-scripts) or build one your own. Either way, just substitude the node-command you would have used by the Docker command, for e.g.:\n\n```mqtt-scripts --help```  \n\nbecomes\n\n```docker run dersimn/mqtt-scripts:1 --help```\n\nAn example for a productive configuration would be:\n\n```\ndocker run -d --restart=always --name=logic \\\n    -e \"TZ=Europe/Berlin\" \\\n    -v /opt/hma/etc/scripts:/scripts:ro \\\n    dersimn/mqtt-scripts:1 \\\n    --url mqtt://10.1.1.50 \\\n    --dir /scripts\n```\n\nConfigure via `MQTTSCRIPTS_` env variables when using Docker Compose.\n\n\n#### Build\n\nDocker development build:\n\n    docker build -t mqtt-scripts .\n    docker run --rm mqtt-scripts --help\n\nDocker Hub deploy:\n\n    docker buildx create --name mybuilder\n    docker buildx use mybuilder\n    docker buildx build --platform linux/amd64,linux/arm/v7 -t dersimn/mqtt-scripts:1 -t dersimn/mqtt-scripts:1.x.x --push .\n\n\n# Command Line Options\n\n\u003cpre\u003e\nUsage: mqtt-scripts [options]\n\nOptions:\n  --version                Show version number                         [boolean]\n  -c, --config             Path to JSON config file\n  -d, --dir                directory to scan for .js and .coffee files. can be\n                           used multiple times.\n  -h, --help               Show help                                   [boolean]\n  -s, --variable-prefix    topic prefix for $ substitution (shorthand for\n                           variables, see docs)                 [default: \"var\"]\n  -t, --disable-variables  disable variable feedback (see docs) [default: false]\n  -n, --name               instance name. used as mqtt client id and as prefix\n                           for connected topic                [default: \"logic\"]\n  -u, --url                mqtt broker url. See\n                           https://github.com/mqttjs/MQTT.js#connect-using-a-url\n                                                   [default: \"mqtt://127.0.0.1\"]\n  -v, --verbosity          possible values: \"error\", \"warn\", \"info\", \"debug\"\n                                                               [default: \"info\"]\n  -w, --disable-watch      disable file watching (don't exit process on file\n                           changes)                             [default: false]\n  -l, --latitude                                              [default: 48.7408]\n  -m, --longitude                                              [default: 9.1778]                                            \n\u003c/pre\u003e\n\nIf you're running multiple instances of mqtt-scripts you have to decide which one should handle variables and disable \nthe variables on all other instances with the --disable-variable option.\n\n\n# Script Examples\n\n#### Use hm2mqtt and hue2mqtt to control a hue lamp with a homematic remote control\n\n```javascript\nlink('hm//RC4:1/PRESS_CONT', 'hue//lights/Hobbyraum/bri_inc', -16);\n\nsubscribe('hm//RC4:2/PRESS_CONT', function () {\n    if (!getValue('hue//lights/Hobbyraum')) {\n        setValue('hue//lights/Hobbyraum', 1);\n    } else {\n        setValue('hue//lights/Hobbyraum/bri_inc', 16);\n    }\n});\n\nlink('hm//RC4:1/PRESS_SHORT', 'hue//lights/Hobbyraum', 0);\nlink('hm//RC4:2/PRESS_SHORT', 'hue//lights/Hobbyraum', 254);\nlink('hm//RC4:3/PRESS_CONT', 'hue//lights/Hobbyraum/ct_inc', -16);\nlink('hm//RC4:4/PRESS_CONT', 'hue//lights/Hobbyraum/ct_inc', 16);\nlink('hm//RC4:3/PRESS_SHORT', 'hue//lights/Hobbyraum/ct', 153);\nlink('hm//RC4:4/PRESS_SHORT', 'hue//lights/Hobbyraum/ct', 500);\n```\n\n#### retrieve fuel prices from tankerkoenig\n\n```javascript\nvar request =   require('request');\nvar cred =      require('./lib/credentials.js');\n\nvar url = 'https://creativecommons.tankerkoenig.de/json/detail.php';\n\nvar tankstellen = {\n    'OMV': 'cb1f0588-d517-40f0-8ce3-3edadebea40d',\n    'Shell': '4267c196-eea1-47be-96b7-d790b2fbd17a'\n};\n\nschedule('0/12 * * * *', function () {\n    for (var topic in tankstellen) {\n        getData(topic, tankstellen[topic]);\n    }\n});\n\nfunction getData(topic, id) {\n    request.get(url + '?id=' + id + '\u0026apikey=' + cred.tankerkoenig.apikey, function (err, res) {\n        if (err) {\n            log.error(err);\n            return;\n        }\n        var data = JSON.parse(res.body).station;\n        setValue('$Tankstelle/' + topic + '/Diesel',    data.diesel);\n        setValue('$Tankstelle/' + topic + '/E5',        data.e5);\n        setValue('$Tankstelle/' + topic + '/Offen',     data.isOpen);\n    });\n}\n```\n\n#### Send a variables state changes to Pushover\n\n```Javascript\nvar cred = require('./lib/credentials.js');\n\nvar pushoverNotifications = require('pushover-notifications');\n\nvar push = new pushoverNotifications( {\n    user: cred.pushover.user,\n    token: cred.pushover.token,\n    onerror: function (error) {\n        log.error(error);\n    }\n});\n\nfunction pushover(msg) {\n    if (typeof msg !== 'object' || typeof msg.message !== 'string') msg = {message: '' + msg};\n    msg.title = msg.title || \"Smart Home\";\n    msg.priority = msg.priority || 0;\n    msg.device = msg.device || 'iphone5';\n    push.send(msg, function(err, result) {\n        if (err) {\n            log.error(err);\n        }\n    });\n}\n\nsubscribe('$Anwesenheit', {change: true}, function () {\n    pushover({\n        title:'Anwesenheit',\n        message: getProp($Anwesenheit, 'logic_textual'),\n        priority: -1\n    });\n});\n```\n\n# API\n\n## Classes\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#log\"\u003elog\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eLog to stdout/stderr. Messages are prefixed with a timestamp and the calling scripts path.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#subscribe\"\u003esubscribe(topic, [options], callback)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eSubscribe to MQTT topic(s)\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#schedule\"\u003eschedule(pattern, [options], callback)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eSchedule recurring and one-shot events\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#sunSchedule\"\u003esunSchedule(pattern, [options], callback)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eSchedule a recurring event based on sun position\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#publish\"\u003epublish(topic, payload, [options])\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003ePublish a MQTT message\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#setValue\"\u003esetValue(topic, val)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eSet a value on one or more topics\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#getValue\"\u003egetValue(topic)\u003c/a\u003e ⇒ \u003ccode\u003emixed\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#getProp\"\u003egetProp(topic, [...property])\u003c/a\u003e ⇒ \u003ccode\u003emixed\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eGet a specific property of a topic\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#now\"\u003enow()\u003c/a\u003e ⇒ \u003ccode\u003enumber\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#age\"\u003eage(topic)\u003c/a\u003e ⇒ \u003ccode\u003enumber\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#link\"\u003elink(source, target, [value])\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eLink topic(s) to other topic(s)\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#combineBool\"\u003ecombineBool(srcs, targets)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eCombine topics through boolean or\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#combineMax\"\u003ecombineMax(srcs, targets)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003ePublish maximum of combined topics\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#timer\"\u003etimer(src, target, time)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003ePublishes 1 on target for specific time after src changed to true\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Typedefs\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#subscribeCallback\"\u003esubscribeCallback\u003c/a\u003e : \u003ccode\u003efunction\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"log\"\u003e\u003c/a\u003e\n\n## log\nLog to stdout/stderr. Messages are prefixed with a timestamp and the calling scripts path.\n\n**Kind**: global class  \n\n* [log](#log)\n    * [.debug()](#log.debug)\n    * [.info()](#log.info)\n    * [.warn()](#log.warn)\n    * [.error()](#log.error)\n\n\u003ca name=\"log.debug\"\u003e\u003c/a\u003e\n\n### log.debug()\nLog a debug message\n\n**Kind**: static method of [\u003ccode\u003elog\u003c/code\u003e](#log)  \n\n| Type |\n| --- |\n| \u003ccode\u003e\\*\u003c/code\u003e | \n\n\u003ca name=\"log.info\"\u003e\u003c/a\u003e\n\n### log.info()\nLog an info message\n\n**Kind**: static method of [\u003ccode\u003elog\u003c/code\u003e](#log)  \n\n| Type |\n| --- |\n| \u003ccode\u003e\\*\u003c/code\u003e | \n\n\u003ca name=\"log.warn\"\u003e\u003c/a\u003e\n\n### log.warn()\nLog a warning message\n\n**Kind**: static method of [\u003ccode\u003elog\u003c/code\u003e](#log)  \n\n| Type |\n| --- |\n| \u003ccode\u003e\\*\u003c/code\u003e | \n\n\u003ca name=\"log.error\"\u003e\u003c/a\u003e\n\n### log.error()\nLog an error message\n\n**Kind**: static method of [\u003ccode\u003elog\u003c/code\u003e](#log)  \n\n| Type |\n| --- |\n| \u003ccode\u003e\\*\u003c/code\u003e | \n\n\u003ca name=\"subscribe\"\u003e\u003c/a\u003e\n\n## subscribe(topic, [options], callback)\nSubscribe to MQTT topic(s)\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| topic | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | topic or array of topics to subscribe |\n| [options] | \u003ccode\u003eObject\u003c/code\u003e \\| \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003efunction\u003c/code\u003e | Options object or as shorthand to options.condition a function or string |\n| [options.shift] | \u003ccode\u003enumber\u003c/code\u003e | delay execution in seconds. Has to be positive |\n| [options.random] | \u003ccode\u003enumber\u003c/code\u003e | random delay execution in seconds. Has to be positive |\n| [options.change] | \u003ccode\u003eboolean\u003c/code\u003e | if set to true callback is only called if val changed |\n| [options.retain] | \u003ccode\u003eboolean\u003c/code\u003e | if set to true callback is also called on retained messages |\n| [options.condition] | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003efunction\u003c/code\u003e | conditional function or condition string |\n| callback | [\u003ccode\u003esubscribeCallback\u003c/code\u003e](#subscribeCallback) |  |\n\n\u003ca name=\"schedule\"\u003e\u003c/a\u003e\n\n## schedule(pattern, [options], callback)\nSchedule recurring and one-shot events\n\n**Kind**: global function  \n**See**: [sunSchedule](#sunSchedule) for scheduling based on sun position.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| pattern | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eDate\u003c/code\u003e \\| \u003ccode\u003eObject\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;mixed\u0026gt;\u003c/code\u003e | pattern or array of patterns. May be cron style string, Date object or node-schedule object literal. See [https://github.com/tejasmanohar/node-schedule/wiki](https://github.com/tejasmanohar/node-schedule/wiki) |\n| [options] | \u003ccode\u003eObject\u003c/code\u003e |  |\n| [options.random] | \u003ccode\u003enumber\u003c/code\u003e | random delay execution in seconds. Has to be positive |\n| callback | \u003ccode\u003efunction\u003c/code\u003e | is called with no arguments |\n\n**Example**  \n```js\n// every full Hour.\nschedule('0 * * * *', callback);\n\n// Monday till friday, random between 7:30am an 8:00am\nschedule('30 7 * * 1-5', {random: 30 * 60}, callback);\n\n// once on 21. December 2018 at 5:30am\nschedule(new Date(2018, 12, 21, 5, 30, 0), callback);\n\n// every Sunday at 2:30pm\nschedule({hour: 14, minute: 30, dayOfWeek: 0}, callback);\n```\n\u003ca name=\"sunSchedule\"\u003e\u003c/a\u003e\n\n## sunSchedule(pattern, [options], callback)\nSchedule a recurring event based on sun position\n\n**Kind**: global function  \n**See**: [schedule](#schedule) for time based scheduling.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| pattern | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | a suncalc event or an array of suncalc events. See [https://github.com/mourner/suncalc](https://github.com/mourner/suncalc) |\n| [options] | \u003ccode\u003eObject\u003c/code\u003e |  |\n| [options.shift] | \u003ccode\u003enumber\u003c/code\u003e | delay execution in seconds. Allowed Range: -86400...86400 (+/- 24h) |\n| [options.random] | \u003ccode\u003enumber\u003c/code\u003e | random delay execution in seconds. |\n| callback | \u003ccode\u003efunction\u003c/code\u003e | is called with no arguments |\n\n**Example**  \n```js\n// Call callback 15 minutes before sunrise\nsunSchedule('sunrise', {shift: -900}, callback);\n\n// Call callback random 0-15 minutes after sunset\nsunSchedule('sunset', {random: 900}, callback);\n```\n\u003ca name=\"publish\"\u003e\u003c/a\u003e\n\n## publish(topic, payload, [options])\nPublish a MQTT message\n\n**Kind**: global function  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| topic | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e |  | topic or array of topics to publish to |\n| payload | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eObject\u003c/code\u003e |  | the payload string. If an object is given it will be JSON.stringified |\n| [options] | \u003ccode\u003eObject\u003c/code\u003e |  | the options to publish with |\n| [options.qos] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e0\u003c/code\u003e | QoS Level |\n| [options.retain] | \u003ccode\u003eboolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | retain flag |\n\n\u003ca name=\"setValue\"\u003e\u003c/a\u003e\n\n## setValue(topic, val)\nSet a value on one or more topics\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| topic | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | topic or array of topics to set value on |\n| val | \u003ccode\u003emixed\u003c/code\u003e |  |\n\n\u003ca name=\"getValue\"\u003e\u003c/a\u003e\n\n## getValue(topic) ⇒ \u003ccode\u003emixed\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003emixed\u003c/code\u003e - the topics value  \n\n| Param | Type |\n| --- | --- |\n| topic | \u003ccode\u003estring\u003c/code\u003e | \n\n\u003ca name=\"getProp\"\u003e\u003c/a\u003e\n\n## getProp(topic, [...property]) ⇒ \u003ccode\u003emixed\u003c/code\u003e\nGet a specific property of a topic\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003emixed\u003c/code\u003e - the topics properties value  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| topic | \u003ccode\u003estring\u003c/code\u003e |  |\n| [...property] | \u003ccode\u003estring\u003c/code\u003e | the property to retrieve. May be repeated for nested properties. If omitted the whole topic object is returned. |\n\n**Example**  \n```js\n// returns the timestamp of a given topic\ngetProp('hm//Bewegungsmelder Keller/MOTION', 'ts');\n```\n\u003ca name=\"now\"\u003e\u003c/a\u003e\n\n## now() ⇒ \u003ccode\u003enumber\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003enumber\u003c/code\u003e - ms since epoch  \n\u003ca name=\"age\"\u003e\u003c/a\u003e\n\n## age(topic) ⇒ \u003ccode\u003enumber\u003c/code\u003e\n**Kind**: global function  \n**Returns**: \u003ccode\u003enumber\u003c/code\u003e - seconds since last change  \n\n| Param | Type |\n| --- | --- |\n| topic | \u003ccode\u003estring\u003c/code\u003e | \n\n\u003ca name=\"link\"\u003e\u003c/a\u003e\n\n## link(source, target, [value])\nLink topic(s) to other topic(s)\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| source | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | topic or array of topics to subscribe |\n| target | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | topic or array of topics to publish |\n| [value] | \u003ccode\u003emixed\u003c/code\u003e | value to publish. If omitted the sources value is published. A function can be used to transform the value. |\n\n\u003ca name=\"combineBool\"\u003e\u003c/a\u003e\n\n## combineBool(srcs, targets)\nCombine topics through boolean or\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| srcs | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | array of topics to subscribe |\n| targets | \u003ccode\u003estring\u003c/code\u003e | topic to publish |\n\n\u003ca name=\"combineMax\"\u003e\u003c/a\u003e\n\n## combineMax(srcs, targets)\nPublish maximum of combined topics\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| srcs | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | array of topics to subscribe |\n| targets | \u003ccode\u003estring\u003c/code\u003e | topic to publish |\n\n\u003ca name=\"timer\"\u003e\u003c/a\u003e\n\n## timer(src, target, time)\nPublishes 1 on target for specific time after src changed to true\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| src | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | topic or array of topics to subscribe |\n| target | \u003ccode\u003estring\u003c/code\u003e | topic to publish |\n| time | \u003ccode\u003enumber\u003c/code\u003e | timeout in milliseconds |\n\n\u003ca name=\"subscribeCallback\"\u003e\u003c/a\u003e\n\n## subscribeCallback : \u003ccode\u003efunction\u003c/code\u003e\n**Kind**: global typedef  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| topic | \u003ccode\u003estring\u003c/code\u003e | the topic that triggered this callback. +/status/# will be replaced by +//# |\n| val | \u003ccode\u003emixed\u003c/code\u003e | the val property of the new state |\n| obj | \u003ccode\u003eobject\u003c/code\u003e | new state - the whole state object (e.g. {\"val\": true, \"ts\": 12346345, \"lc\": 12346345} ) |\n| objPrev | \u003ccode\u003eobject\u003c/code\u003e | previous state - the whole state object |\n| msg | \u003ccode\u003eobject\u003c/code\u003e | the mqtt message as received from MQTT.js |\n\n\n# License\n\n\nMIT © [Sebastian Raff](https://github.com/hobbyquaker)\n\n[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat\n[mit-url]: LICENSE\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhobbyquaker%2Fmqtt-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhobbyquaker%2Fmqtt-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhobbyquaker%2Fmqtt-scripts/lists"}