Hey All,
I'm trying to calculate the average temp from 2 temperature sensors which are stored in global variables. Here's my flow, how can I set it up to calculate the average?
Thanks!
[
{
"id": "5e73126742dd6de3",
"type": "inject",
"z": "bd5d8f0934d852df",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 220,
"y": 720,
"wires": [
[
"92eef5368866f343",
"1e02e4439dfe79f2"
]
]
},
{
"id": "92eef5368866f343",
"type": "change",
"z": "bd5d8f0934d852df",
"name": "Hanging Lamp Temp",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "currentTempHangingLamp",
"tot": "global"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 500,
"y": 680,
"wires": [
[
"5b2168d7ab676831"
]
]
},
{
"id": "1e02e4439dfe79f2",
"type": "change",
"z": "bd5d8f0934d852df",
"name": "Bookshelf Temp",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "currentTempBookshelfTemp",
"tot": "global",
"dc": true
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 400,
"y": 740,
"wires": [
[
"5b2168d7ab676831"
]
]
},
{
"id": "ba4501feab4a54cd",
"type": "function",
"z": "bd5d8f0934d852df",
"name": "calculate average",
"func": "var lamp = msg.payload[1]\nvar bookshelf = msg.payload[2]\n\nmsg.payload = ((lamp + bookshelf)/2);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 910,
"y": 720,
"wires": [
[]
]
},
{
"id": "8462518c70518a74",
"type": "debug",
"z": "bd5d8f0934d852df",
"name": "debug 351",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1070,
"y": 640,
"wires": []
},
{
"id": "5b2168d7ab676831",
"type": "join",
"z": "bd5d8f0934d852df",
"name": "",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "payload",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 710,
"y": 720,
"wires": [
[
"ba4501feab4a54cd",
"8462518c70518a74"
]
]
}
]