I started looking how to have Alexa answer a question with a Hubitat variable (i.e. Family Room Temp) but was side tracked when it was suggested I read this post. Events to SQL I was intrigued by the approach and although I've seen many references to Node-RED it never went further.
After reading the above thread I was motivated to work on another goal of mine: Log Hubitat events to a file for analysis. This is mostly for evaluating sensors for stability and thermal lag etc. I never meant to use it for long term logging. For my 44 devices a day created a 400k file.
So I took the plunge. I found Node-RED very easy to get installed and running. I had a little trouble getting started but with the help of @stephack I was able to get the logs I wanted in a spreadsheet usable form.
I've never used Node-RED before 4 days ago. I'm not a programmer however I have a technical background.
The information below should be very easy to implement, just copy, import into Node-RED, change to your IP address and change to you output file path and name the you should be good to go
Note: I've blocked the wx-ApiXU-Driver as it wasn't useful to me and created a lot of entries.
Added notes:
- Nothing has to be done with the Habitat Hub
- Websocket originally sounded too "network" to me, however there is nothing to do except to add in your IP address.
- I doubt this will work if the computer is not on the same router as the Hub.
I hope someone else finds this useful.
John
Sample File output.
DeviceID, Date/time, name, display name value and units.
The below code when imported to Node-RED requires only the change in IP address and output filename and path.
The flow as shown in Node-RED:
The Websocket screen showing where to enter your IP address
The output screen showing where to enter your path and file. The full path and filename are required.
The Red-Node code. Copy and import into the Node-RED browser window.
[
{
"id": "5c6c4fcd.b3df3",
"type": "tab",
"label": "Hubitat Events v3",
"disabled": false,
"info": "# Modified Hubitat_Events\n## Removed Reporting of:\n - Furnace Humidity\n - Furnace Pressure\n - Weather csteel\n - Pollen Forcaster\n\n## Fixed Time offset\n\n2019-08-27 seems to function correctly,\nwe are seeing fewer Outside Air Temperature reports\nthan expected. Perhaps the signal is too low.\n\n\n "
},
{
"id": "594eb080.cd6bc",
"type": "websocket in",
"z": "5c6c4fcd.b3df3",
"name": "",
"server": "",
"client": "e114cede.22aa1",
"x": 270,
"y": 180,
"wires": [
[
"be8fd9c3.60d0e8"
]
]
},
{
"id": "3e21ed55.1bbc42",
"type": "function",
"z": "5c6c4fcd.b3df3",
"name": "Make Payload",
"func": "\n// Do not log the below data:\nvar del_01 = \"Weather csteel\"\nvar del_02 = \"Pollen Forecaster\"\nvar del_03 = \"add new deletion here\"\nvar del_04 = \"add another deletion here\"\nvar del_05 = \"Furnace Lockout\"\t//displayName\nvar del_05a = \"humidity\"\t\t//name\nvar del_05b = \"pressure\"\nvar del_05c = \"illuminance\"\n//\n//\nvar adeviceId = msg.deviceId\nvar aname = msg.name\nvar adisplayName = msg.displayName\nvar avalue = msg.value\nvar aunit = msg.unit\nvar atimestamp = msg.timestamp\n// var adescriptionText = msg.descriptionText\n\nif (adisplayName == del_01 || adisplayName == del_02 || adisplayName == del_03 || adisplayName == del_04 || (aname == del_05a && adisplayName == del_05) ||(aname == del_05b && adisplayName == del_05)||(aname == del_05c && adisplayName == del_05))\n{\n\t//msg.payload = [atimestamp,aname,adisplayName,\"filtered out >>>>>>>>>>>>>>>>>>>>>>>>>\"]\n\t//return msg;\n}\nelse\n{\n\tmsg.payload = [adeviceId, atimestamp,aname,adisplayName,avalue,aunit]\n\treturn msg;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 600,
"y": 320,
"wires": [
[
"1c9ffaf8.c48935",
"ea37bc04.469b2"
]
]
},
{
"id": "1c9ffaf8.c48935",
"type": "csv",
"z": "5c6c4fcd.b3df3",
"name": "",
"sep": ",",
"hdrin": "",
"hdrout": false,
"multi": "one",
"ret": "\\r\\n",
"temp": "timestamp, name:, displayname:,value,unit",
"skip": "0",
"strings": true,
"x": 710,
"y": 240,
"wires": [
[
"439fbcc2.ffd4b4"
]
]
},
{
"id": "439fbcc2.ffd4b4",
"type": "file",
"z": "5c6c4fcd.b3df3",
"name": "",
"filename": "C:\\work_Node-RED\\data_02.csv",
"appendNewline": false,
"createDir": false,
"overwriteFile": "false",
"encoding": "none",
"x": 870,
"y": 180,
"wires": [
[]
]
},
{
"id": "be8fd9c3.60d0e8",
"type": "moment",
"z": "5c6c4fcd.b3df3",
"name": "timestamp",
"topic": "timestamp",
"input": "",
"inputType": "date",
"inTz": "America/New_York",
"adjAmount": "0",
"adjType": "hours",
"adjDir": "subtract",
"format": "MM-DD-YYYY HH:mm",
"locale": "en_US",
"output": "timestamp",
"outputType": "msg",
"outTz": "America/New_York",
"x": 470,
"y": 240,
"wires": [
[
"3e21ed55.1bbc42",
"fb183530.4d10a8"
]
]
},
{
"id": "43c6437e.68eb6c",
"type": "comment",
"z": "5c6c4fcd.b3df3",
"name": "Hubitat Events Log v3",
"info": "# This flow reads the Hubitat generated events logging the data to a file in csv format",
"x": 160,
"y": 60,
"wires": []
},
{
"id": "ea37bc04.469b2",
"type": "debug",
"z": "5c6c4fcd.b3df3",
"name": "Payload",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 860,
"y": 320,
"wires": []
},
{
"id": "fb183530.4d10a8",
"type": "debug",
"z": "5c6c4fcd.b3df3",
"name": "timestamp",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 850,
"y": 100,
"wires": []
},
{
"id": "e114cede.22aa1",
"type": "websocket-client",
"z": "",
"path": "ws://192.168.18.265/eventsocket",
"tls": "",
"wholemsg": "true"
}
]