Contents of "Websocket Events"

I'm using Node-RED to create a simple "Events" logger, writing a file to my PC. In parsing the Websocket received Event I cannot find the timestamp.

Below is the raw websocket output for a device message
and the matching "device page" Event entry.

So my question is:

Is the time and date not part of the Websocket message? Or is it there and I don't know how to access it?

I read the documentation and could not find any info on the websocket message content.

Thanks
John

The Node-RED output from debug (complete msg object)

image

image https://community.hubitat.com/uploads/default/original/3X/3/0/30963aab287ad5d09fbc1f32081a7903821c5ea6.png

I'm not sure how you are formatting you event data before outputting to the log file, but you should be able to manually add the timestamp using now() or date().

Eg
msg.timestamp = now()
Or
msg.timestamp = new Date()

1 Like

I'm using the "change" flow and am getting unexpected results.

I use "set" msg.payload.timestamp and using 55555 as a value (just for testing): Nothing is added to the output msg

If I use "set" msg.timestamp and using 55555 as a value: The timestamp is added after the _msgid and does not make it into the output file.

Please export and share your entire flow (PM me if you don't want to share publicly). I will look at it...probably tonight...have a birthday party most of the day today.

@stephack

Thanks for the offer. I keep reducing the flow to try to figure out how to add a time stamp.
This flow doesn't even try to add the time stamp it just tries to set the existing "descriptionText":null
to either 55555 or "55555" or '55555' none would work.
So I guess I'm missing something basic. I read numerous posts and node_RED documentation and from what I read....it should work.

John

PS ip has been changed.

[
   {
       "id": "72eeb5dd.1ce42c",
       "type": "websocket in",
       "z": "5c6c4fcd.b3df3",
       "name": "Events In",
       "server": "4c2883b4.d7d41c",
       "client": "",
       "x": 80,
       "y": 40,
       "wires": [
           [
               "a7e86f87.90c7b",
               "2750d54b.b373ea"
           ]
       ]
   },
   {
       "id": "2750d54b.b373ea",
       "type": "change",
       "z": "5c6c4fcd.b3df3",
       "name": "",
       "rules": [
           {
               "t": "set",
               "p": "descriptionText",
               "pt": "msg",
               "to": "'55555'",
               "tot": "str"
           }
       ],
       "action": "",
       "property": "",
       "from": "",
       "to": "",
       "reg": false,
       "x": 410,
       "y": 40,
       "wires": [
           [
               "21ba6e4a.12d1a2"
           ]
       ]
   },
   {
       "id": "a7e86f87.90c7b",
       "type": "debug",
       "z": "5c6c4fcd.b3df3",
       "name": "OBJECT",
       "active": true,
       "tosidebar": true,
       "console": true,
       "tostatus": false,
       "complete": "true",
       "targetType": "full",
       "x": 710,
       "y": 140,
       "wires": []
   },
   {
       "id": "21ba6e4a.12d1a2",
       "type": "debug",
       "z": "5c6c4fcd.b3df3",
       "name": "AfterSET",
       "active": true,
       "tosidebar": true,
       "console": true,
       "tostatus": false,
       "complete": "payload",
       "targetType": "msg",
       "x": 720,
       "y": 60,
       "wires": []
   },
   {
       "id": "4c2883b4.d7d41c",
       "type": "websocket-listener",
       "z": "",
       "path": "ws://192.168.1.137/eventsocket",
       "wholemsg": "false"
   }
]

Can you share the entire flow including the output to the log? It would help me understand exactly what you are trying to do and how to format the solution. I won't get to it till tomorrow. I'm exhausted at this point. Kids are an energy and time black hole.

1 Like

My ultimate goal is to log the sensor data from the Hubitat Events feed to a file on my PC. I also need to add a timestamp to the data.

I thought I could simply add the timestamp to the Payload using the "change" Node. However I could not seem to make any changes to the Payload.

I tried:

  1. Change Node - Set (adding a new variable to the payload)
  2. Change Node - Delete ( could not delete any variables from the payload
  3. Change Node - Set a current Variable.

I'm guess I'm missing something basic. I have boiled the task down to the four nodes , hoping if I can learn how to manipulate the Payload I could figure out the rest.

image

Thanks for your help.

John

PostedFlow Debug:

8/25/2019, 3:24:20 AMnode: OBJECT
msg : Object
{ payload: "{"source":"DEVICE","name":"hum…", _session: object, _msgid: "7f79ee59.a84d5" }
8/25/2019, 3:24:20 AMnode: AfterSET
msg.payload : string[220]
"{"source":"DEVICE","name":"humidity","displayName":"Furnace Lockout","value":"33.79","unit":"%","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout humidity is 33.79%"}"
8/25/2019, 3:24:22 AMnode: OBJECT
msg : Object
{ payload: "{"source":"DEVICE","name":"tem…", _session: object, _msgid: "33ccaf4b.8673d" }
8/25/2019, 3:24:22 AMnode: AfterSET
msg.payload : string[236]
"{"source":"DEVICE","name":"temperature","displayName":"Furnace Lockout","value":"89.9","unit":"\u00b0F","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout temperatur

PostedFlow Console:

25 Aug 03:24:15 - [info] [debug:OBJECT]
{ payload:
   '{"source":"DEVICE","name":"rssi","displayName":"Vista20","value":"-49","unit":null,"deviceId":1390,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":null}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: 'a7dd396c.dfa0b8' }
25 Aug 03:24:15 - [info] [debug:AfterSET] {"source":"DEVICE","name":"rssi","displayName":"Vista20","value":"-49","unit":null,"deviceId":1390,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":null}
25 Aug 03:24:20 - [info] [debug:AfterSET]
{ payload:
   '{"source":"DEVICE","name":"humidity","displayName":"Furnace Lockout","value":"33.79","unit":"%","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout humidity is 33.79%"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '7f79ee59.a84d5' }
25 Aug 03:24:20 - [info] [debug:OBJECT]
{ payload:
   '{"source":"DEVICE","name":"humidity","displayName":"Furnace Lockout","value":"33.79","unit":"%","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout humidity is 33.79%"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '7f79ee59.a84d5' }
25 Aug 03:24:20 - [info] [debug:AfterSET] {"source":"DEVICE","name":"humidity","displayName":"Furnace Lockout","value":"33.79","unit":"%","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout humidity is 33.79%"}
25 Aug 03:24:22 - [info] [debug:AfterSET]
{ payload:
   '{"source":"DEVICE","name":"temperature","displayName":"Furnace Lockout","value":"89.9","unit":"\\u00b0F","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout temperature is 89.9\\u00b0F"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '33ccaf4b.8673d' }
25 Aug 03:24:22 - [info] [debug:OBJECT]
{ payload:
   '{"source":"DEVICE","name":"temperature","displayName":"Furnace Lockout","value":"89.9","unit":"\\u00b0F","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout temperature is 89.9\\u00b0F"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '33ccaf4b.8673d' }
25 Aug 03:24:22 - [info] [debug:AfterSET] {"source":"DEVICE","name":"temperature","displayName":"Furnace Lockout","value":"89.9","unit":"\u00b0F","deviceId":1419,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Furnace Lockout temperature is 89.9\u00b0F"}
25 Aug 03:24:46 - [info] [debug:AfterSET]
{ payload:
   '{"source":"DEVICE","name":"rssi","displayName":"Outside Air Sensor","value":"-83","unit":"\\u00b0F","deviceId":1803,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":null}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: 'cd906637.2a70a8' }
25 Aug 03:24:46 - [info] [debug:OBJECT]
{ payload:
   '{"source":"DEVICE","name":"rssi","displayName":"Outside Air Sensor","value":"-83","unit":"\\u00b0F","deviceId":1803,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":null}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: 'cd906637.2a70a8' }
25 Aug 03:24:46 - [info] [debug:AfterSET] {"source":"DEVICE","name":"rssi","displayName":"Outside Air Sensor","value":"-83","unit":"\u00b0F","deviceId":1803,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":null}
25 Aug 03:25:02 - [info] [debug:AfterSET]
{ payload:
   '{"source":"DEVICE","name":"temperature","displayName":"Porch Temp-Humidity","value":"61.52","unit":"\\u00b0F","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Temperature is 61.52\\u00b0F"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '3b9775be.a8469a' }
25 Aug 03:25:02 - [info] [debug:OBJECT]
{ payload:
   '{"source":"DEVICE","name":"temperature","displayName":"Porch Temp-Humidity","value":"61.52","unit":"\\u00b0F","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Temperature is 61.52\\u00b0F"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '3b9775be.a8469a' }
25 Aug 03:25:02 - [info] [debug:AfterSET] {"source":"DEVICE","name":"temperature","displayName":"Porch Temp-Humidity","value":"61.52","unit":"\u00b0F","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Temperature is 61.52\u00b0F"}
25 Aug 03:25:02 - [info] [debug:AfterSET]
{ payload:
   '{"source":"DEVICE","name":"humidity","displayName":"Porch Temp-Humidity","value":"75.1","unit":"%","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Humidity is 75.1%"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '9aa6c498.98a2b8' }
25 Aug 03:25:02 - [info] [debug:OBJECT]
{ payload:
   '{"source":"DEVICE","name":"humidity","displayName":"Porch Temp-Humidity","value":"75.1","unit":"%","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Humidity is 75.1%"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '9aa6c498.98a2b8' }
25 Aug 03:25:02 - [info] [debug:AfterSET] {"source":"DEVICE","name":"humidity","displayName":"Porch Temp-Humidity","value":"75.1","unit":"%","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Humidity is 75.1%"}
25 Aug 03:25:02 - [info] [debug:AfterSET]
{ payload:
   '{"source":"DEVICE","name":"pressure","displayName":"Porch Temp-Humidity","value":"1016.0","unit":"hPa","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Pressure is 1016.0 hPa"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '1026d51a.3115eb' }
25 Aug 03:25:02 - [info] [debug:OBJECT]
{ payload:
   '{"source":"DEVICE","name":"pressure","displayName":"Porch Temp-Humidity","value":"1016.0","unit":"hPa","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Pressure is 1016.0 hPa"}',
  _session: { type: 'websocket', id: '922a7ae3.e67688' },
  _msgid: '1026d51a.3115eb' }
25 Aug 03:25:02 - [info] [debug:AfterSET] {"source":"DEVICE","name":"pressure","displayName":"Porch Temp-Humidity","value":"1016.0","unit":"hPa","deviceId":1811,"hubId":null,"locationId":null,"installedAppId":null,"descriptionText":"Pressure is 1016.0 hPa"}

I think I see your problem. It's in the config of your websocket node and AfterSet debug node.

Firstly, the websocket in:
Click on the pencil icon to edit your Path and then change the Send/Receive to "entire message".
Choosing "payload" ends up sending the events as a string value. You could potentially add another node to convert it to an object, but that's just adding unneeded complication. Sending the entire message returns an object that is much easier to manipulate.

Secondly, in your AfterSet debug node:
You would also need to change this to "complete msg object"

When you choose to use the entire message, there will no longer be a msg.payload value, just msg.deviceId, msg.name, etc. Now you can add anything you need to the msg object including msg.timestamp.

3 Likes

@stephack
Thanks so much for straightening me out. I think as being new to anything Java I was under the impression that "Payload" was the data, as opposed to a structure of the data.

I hope your party went well :slight_smile:

Regards,

John

Np...the party was great....for the kids anyway.

Your instincts were correct. A lot of what NR nodes output is in the msg.payload.....just not in this case. Just use the debug output as your guide. It will usually show you the format of the data and if it is an object would usually let you walk through each level.