Timestamp for Sensor Type 1

I have 10 Type 1 (temperature/humidity) Sensors split on 2 Gateways. I have the readings saving to a CSV and have published a dashboard. There are 2 issues however.

1: insert the timestamp in the CSV row

I can see the timestamp in the complete message object in 2 locations, but I cannot figure out how to have this time save in the file.

2: save (or display) the temperature in Fahrenheit instead of Celsius

Dashboard users would like to see temp in F so they do not have to convert.

Any advice on these subjects would be greatly appreciated.

Can you share your Node-Red flow so we can take a look?

flows.json (64.5 KB)
See attached flow.
The node I have to test are labeled "Time, function 6, Sensor4 test (csv), Sensor 4 test (write file)

I don’t have one of these sensors at my desk at the moment. Can you do me a favor and attach a debug node to the output of one of the wireless device nodes, make sure the debug node is set to output complete message object. Then send me the output from that debug node when the sensor transmits. I can create an inject node from that to use for testing.

It looks like all of the function nodes are currently empty. Have you not attempted to obtain the timestamp yet? It’s a simple Javascript function to do that.

Thank you,
Travis

Perhaps a simple modification to this flow will do what you need:

Hi @powerna To complement @TravisE_NCD_Technica comment, I’m sharing a basic flow example. In this example, we use switch nodes to filter only sensor data and further filter by device MAC address. Subsequently, you can process the sensor data and format the date in a human-readable format. Here is the flow:

[{"id":"e00c90f3a45af11c","type":"switch","z":"f908487c97b77286","name":"sensor data","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"sensor_data","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":570,"y":180,"wires":[["1de8cce7b7da9425"]]},{"id":"1de8cce7b7da9425","type":"switch","z":"f908487c97b77286","name":"mac","property":"payload.addr","propertyType":"msg","rules":[{"t":"eq","v":"your_device_mac","vt":"str"},{"t":"eq","v":"00:13:a2:00:42:3c:9e:1c","vt":"str"},{"t":"eq","v":"00:13:a2:00:42:3c:9e:b7","vt":"str"},{"t":"eq","v":"00:13:a2:00:42:3c:9e:af","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":710,"y":180,"wires":[["4ac6451922017484","8562271bedc56a07"],[],[],[]]},{"id":"4ac6451922017484","type":"split","z":"f908487c97b77286","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","property":"payload","x":910,"y":120,"wires":[["1117ef0fdde2692f"]]},{"id":"1117ef0fdde2692f","type":"switch","z":"f908487c97b77286","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"temperature","vt":"str"},{"t":"eq","v":"humidity","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1030,"y":120,"wires":[[],[]]},{"id":"9c64224f6b969eb1","type":"csv","z":"f908487c97b77286","name":"Sensor1","sep":",","hdrin":false,"hdrout":"once","multi":"one","ret":"\\r\\n","temp":"timestamp,temperature,humidity","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":1200,"y":80,"wires":[["2003911f96582a32"]]},{"id":"2003911f96582a32","type":"file","z":"f908487c97b77286","name":"Sensor 1","filename":"C:\\users\\z6finpit\\desktop\\files\\Sensor1.csv","filenameType":"str","appendNewline":false,"createDir":true,"overwriteFile":"false","encoding":"none","x":1340,"y":80,"wires":[["6d6feefac0c40f7d"]]},{"id":"6d6feefac0c40f7d","type":"debug","z":"f908487c97b77286","name":"debug 8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1480,"y":80,"wires":[]},{"id":"7f8ae5a2c60935b1","type":"change","z":"f908487c97b77286","name":"date","rules":[{"t":"set","p":"payload.timestamp","pt":"msg","to":"$moment(payload.received).format(\"YYYY-MM-DD HH:MM:SS\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":80,"wires":[["9c64224f6b969eb1"]]},{"id":"8562271bedc56a07","type":"change","z":"f908487c97b77286","name":"sensor data","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.sensor_data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":80,"wires":[["7f8ae5a2c60935b1"]]}]

I have tested the flow, and you should see the following:

image

In this case, you need to use the ‘Wireless Gateway’ node to obtain all the sensor data, as shown in the screenshot below:


Inside the ‘MAC’ switch node, you should add the MAC addresses of all your devices to split the data accordingly. You can also add additional rules by clicking the ‘Add’ button.


In order to give the timestamp format, you can use the JSONata functions.

source: Anyone one convert timestamp (epoc) to formatted time string in a single change node? - General - Node-RED Forum

Please take a look and let us know if you have any questions.
Thank you,
Eduardo M.

Thanks - this is what we were looking for. However, I have 2 inconsistencies in the results.

1 - time stamp only seems to update every hour

2 - not every row is receiving the correct format
image

Hi @powerna My bad, within the “date” node, in the “format” function, minutes and seconds should be in lowercase, as shown below:

  • $moment(payload.received).format(“YYYY-MM-DD HH:mm:ss”)

I have conducted the tests, and the date is being added correctly. Please find the attached screenshot. I apologize.

csv_file

Thank you,
Eduardo M.