-
-
Save jtp10181/764473153499f504e9f7c7b5c3be941a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "d6c32c6174d9ffaa", | |
"type": "tab", | |
"label": "Hubitat Log to InfluxDB", | |
"disabled": false, | |
"info": "" | |
}, | |
{ | |
"id": "386d8faf8d8dc58b", | |
"type": "hubitat event", | |
"z": "d6c32c6174d9ffaa", | |
"name": "Hubitat Events", | |
"server": "3b6080dc.a2527", | |
"x": 160, | |
"y": 200, | |
"wires": [ | |
[ | |
"e4a1a4c1666366b5" | |
] | |
] | |
}, | |
{ | |
"id": "9401cd44cd3705c2", | |
"type": "debug", | |
"z": "d6c32c6174d9ffaa", | |
"name": "Debug Messages", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "payload", | |
"targetType": "msg", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 850, | |
"y": 260, | |
"wires": [] | |
}, | |
{ | |
"id": "f494695eb8b1091c", | |
"type": "function", | |
"z": "d6c32c6174d9ffaa", | |
"name": "Set Influx Data", | |
"func": "const ACTIVE = 'active';\nconst CLOSED = 'closed';\nconst DETECTED = 'detected';\nconst FOLLOW_SCHEDULE = 'follow schedule';\nconst GOOD = 'good';\nconst HEATING = 'heating';\nconst LOCKED = 'locked';\nconst MUTED = 'muted';\nconst OFF = 'off';\nconst ON = 'on';\nconst OPEN = 'open';\nconst PRESENT = 'present';\nconst PUSHED = 'pushed';\nconst SLEEPING = 'sleeping';\nconst TOUCHED = 'touched';\nconst WET = 'wet';\n\nvar v = {\n 'value' : null,\n 'isBinary' : null\n};\n\nvar msgPl = msg.payload;\n\nif(msgPl.name == \"acceleration\") {\n v.value = (msgPl.value == ACTIVE ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"alarm\") {\n v.value = (msgPl.value != OFF ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"button\") {\n v.value = (msgPl.value != PUSHED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"carbonMonoxide\") {\n v.value = (msgPl.value == DETECTED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"consumableStatus\") {\n v.value = (msgPl.value == GOOD ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"contact\") {\n v.value = (msgPl.value == OPEN ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"door\") {\n v.value = (msgPl.value != OPEN ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"lock\") {\n v.value = (msgPl.value == LOCKED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"motion\") {\n v.value = (msgPl.value == ACTIVE ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"mute\") {\n v.value = (msgPl.value == MUTED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"presence\") {\n v.value = (msgPl.value == PRESENT ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"shock\") {\n v.value = (msgPl.value == DETECTED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"sleeping\") {\n v.value = (msgPl.value == SLEEPING ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"smoke\") {\n v.value = (msgPl.value == DETECTED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"sound\") {\n v.value = (msgPl.value == DETECTED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"switch\") {\n v.value = (msgPl.value == ON ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"tamper\") {\n v.value = (msgPl.value == DETECTED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"thermostatMode\") {\n v.value = (msgPl.value != OFF ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"thermostatFanMode\") {\n v.value = (msgPl.value != OFF ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"thermostatOperatingState\") {\n v.value = (msgPl.value == HEATING ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"thermostatSetpointMode\") {\n v.value = (msgPl.value != FOLLOW_SCHEDULE ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"touch\") {\n v.value = (msgPl.value != TOUCHED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"windowFunction\") {\n v.value = (msgPl.value == ACTIVE ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"water\") {\n v.value = (msgPl.value == WET ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"windowShade\") {\n v.value = (msgPl.value == CLOSED ? 1 : 0);\n v.isBinary = true;\n}\n\nelse if(msgPl.name == \"threeAxis\") {\n var vz = msgPl.value.split(',');\n var x = vz[0];\n var y = vz[1];\n var z = vz[2];\n v.value = {\n x: vz[0],\n y: vz[1],\n z: vz[2]\n };\n v.isBinary = false;\n}\nelse if (msgPl.value && msgPl.value.match(/.*[^0-9\\.,-].*/)) { // match if any characters are not digits, period, comma, or hyphen.\n //v.value = '\"' + msgPl.value + '\"';\n v.value = msgPl.value;\n v.isBinary = false;\n}\n\n// Catch any other general numerical event (carbonDioxide, power, energy, humidity, level, temperature, ultravioletIndex, voltage, etc).\nelse {\n v.value = Number(msgPl.value);\n v.isBinary = false;\n}\n\n//Build new Message\n//This is Built for output to 'influxdb batch'\n//First build the fields data\nvar msgFields;\nif (msgPl.name == \"threeAxis\") {\n msgFields = {\n\t\tvalueX: v.value.x,\n\t\tvalueY: v.value.y,\n\t\tvalueZ: v.value.z\n\t};\n} \nelse if (v.isBinary) {\n msgFields = {\n\t\tvalue: msgPl.value,\n\t\tvalueBinary: v.value\n\t};\n}\nelse {\n msgFields = {\n\t\tvalue: (Array.isArray(v.value) ? v.value.join(',') : v.value),\n\t};\n}\n\n//Build the payload\nvar msgInflux = { payload: [],topic:\"influx-event\" };\nmsgInflux.payload = [\n\t{\n\t\tmeasurement: msgPl.name,\n\t\tfields: msgFields,\n\t\ttags: {\n\t\t\tdeviceId: msgPl.deviceId,\n\t\t\tdisplayName: msgPl.displayName,\n\t\t\tunit: msgPl.unit,\n\t\t\ttype: msgPl.type\n\t\t},\n\t\ttimestamp: new Date()\n\t}\n];\n\n//console.log(util.inspect(msg, {showHidden: false, depth: null}))\nreturn msgInflux;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 580, | |
"y": 200, | |
"wires": [ | |
[ | |
"3c7518f41c997c90" | |
] | |
] | |
}, | |
{ | |
"id": "3c7518f41c997c90", | |
"type": "influxdb batch", | |
"z": "d6c32c6174d9ffaa", | |
"influxdb": "d2c5820fa73a6858", | |
"precision": "", | |
"retentionPolicy": "", | |
"name": "influx batch v2.0 save", | |
"database": "database", | |
"precisionV18FluxV20": "ms", | |
"retentionPolicyV18Flux": "", | |
"org": "", | |
"bucket": "", | |
"x": 860, | |
"y": 200, | |
"wires": [] | |
}, | |
{ | |
"id": "e4a1a4c1666366b5", | |
"type": "function", | |
"z": "d6c32c6174d9ffaa", | |
"name": "Filter Events", | |
"func": "const includeList = [\n\t\"acceleration\",\n\t\"alarm\",\n\t\"battery\",\n\t\"battery_mV\",\n\t\"breathRateAverage\",\n\t\"carbonDioxide\",\n\t\"carbonMonoxide\",\n\t\"cloudiness\",\n\t\"contact\",\n\t\"coolingSetpoint\",\n\t\"cpuPct\",\n\t\"current\",\n\t\"dbSize\",\n\t\"door\",\n\t\"ecoMode\",\n\t\"energy\",\n\t\"freeMemory\",\n\t\"goal\",\n\t\"heartRateAverage\",\n\t\"heatingSetpoint\",\n\t\"hrvAverage\",\n\t\"humidity\",\n\t\"illuminance\",\n\t\"level\",\n\t\"lock\",\n\t\"lqi\",\n\t\"medianD\",\n\t\"motion\",\n\t\"pH\",\n\t\"power\",\n\t\"powerFactor\",\n\t\"presence\",\n\t\"pressure\",\n\t\"rssi\",\n\t\"scheduledSetpoint\",\n\t\"shock\",\n\t\"sleepScore\",\n\t\"sleeping\",\n\t\"smoke\",\n\t\"status\",\n\t\"steps\",\n\t\"switch\",\n\t\"tamper\",\n\t\"temperature\",\n\t\"temperatureC\",\n\t\"temperatureF\",\n\t\"thermostatFanMode\",\n\t\"thermostatMode\",\n\t\"thermostatOperatingState\",\n\t\"thermostatSetpoint\",\n\t\"thermostatSetpointMode\",\n\t\"threeAxis\",\n\t\"touch\",\n\t\"ultravioletIndex\",\n\t\"uptime\",\n\t\"voltage\",\n\t\"water\",\n\t\"windDirection\",\n\t\"windSpeed\",\n\t\"windowFunction\",\n\t\"windowShade\"\n];\n\nvar retMsg;\n\n//Case insensitive compare\nvar filterMatch = includeList.filter( str => \n str.localeCompare(msg.payload.name, 'en', { sensitivity: 'base' }) == 0\n)\n\nif (filterMatch.length > 0) {\n retMsg = msg;\n}\n\nreturn retMsg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 370, | |
"y": 200, | |
"wires": [ | |
[ | |
"f494695eb8b1091c" | |
] | |
] | |
}, | |
{ | |
"id": "3b6080dc.a2527", | |
"type": "hubitat config", | |
"name": "Hubitat Hub", | |
"usetls": false, | |
"host": "", | |
"port": "80", | |
"appId": "", | |
"nodeRedServer": "", | |
"webhookPath": "/hubitat/webhook", | |
"autoRefresh": true, | |
"useWebsocket": false, | |
"colorEnabled": false, | |
"color": "#000000" | |
}, | |
{ | |
"id": "d2c5820fa73a6858", | |
"type": "influxdb", | |
"hostname": "127.0.0.1", | |
"port": "8086", | |
"protocol": "http", | |
"database": "database", | |
"name": "InfluxDB", | |
"usetls": false, | |
"tls": "", | |
"influxdbVersion": "2.0", | |
"url": "http://localhost:8086", | |
"rejectUnauthorized": false | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment