Log Hubitat Events to file on PC

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 :slight_smile:

Note: I've blocked the wx-ApiXU-Driver as it wasn't useful to me and created a lot of entries.
Added notes:

  1. Nothing has to be done with the Habitat Hub
  2. Websocket originally sounded too "network" to me, however there is nothing to do except to add in your IP address.
  3. 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
image

The output screen showing where to enter your path and file. The full path and filename are required.
Node%2C%20Write%20to%20File

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"
}
]
5 Likes

so, will she answer the question of temp now ?

I am doing some similar. I have it look at the event socket and log to a text file. I also have it monitor for SQL db error and send me a pushover notification. Eventually I want to have it send a reboot command to the hub when the SQL error happened. Assuming that's it won't further cause problem :wink:.

No.....at least not mine :frowning: This became a tangent endeavor.

For those using node-red have you noticed any slowdown of the HE hub? Any problems with HE doing this?

None what so ever since NodeRed listens to the websocket port. It’s already broadcasting anyway so the events are picked up.

No issues here.

1 Like

I've been collecting Events for 4 days straight and no issues.

2 Likes

HI I need help here, please see the print screen below

image

Solve: I installed the "node-red-contrib-moment"

Glad to see you got it working. :slight_smile:

1 Like

I must be doing something stupid. I get the websocket connected the green dot under it that says connected. However, as soon as I enter the path of the data file into File Node, I lose the green dot.

Also, in the Moment Node, you are using New York. Since I am in Dallas/Fort Worth, what should I be using instead?

Ok, I re-imported but this time chaned the IP address of my hub and the path to the data file before importing. I used 2 "\" instead of one "" in entering the file path because yours did. When I imported, the websocket gave the green connected dot. However,

I was getting " 1/21/2020, 9:02:51 PMnode: 8ddcc60d.6000f8msg : error "TypeError: Cannot read property 'timestamp' of null"

I tried to change New_York to Dallas and then to Chicago. Both times, it disconnected me from the websocket. I diidn't see anywhere in the documentation of the Moment node of how to designate which time zone.

I've not used this for some time, in fact I accidentally deleted the whole folder :frowning:

But Is there some option in moment to select a timestamp of some sort? My program chart shows a different timestamp block where you show "moment"

Perhaps that was it.

Also if you look at the code, under type: moment the name: is "timestamp" and the topic is "timestamp"