Hey All,
I have a motion sensor that turns on lights, in addition to that I have a fan that I want to turn on and off based on the temperature. I set the "temperature threshold" and write the value to a text file. I also write the currentTemp to a text file. I then compare the values to determine if the fan turns on or off.
To do this I'm setting the threshold and currentTemp values to flow variables and using function nodes to do the comparison. For some reason both functions are triggering simultaniously and not working properly. How can I write these functions so the work correctly?
Thanks!
Rich
[
{
"id": "9e5e69a5e191851d",
"type": "switch",
"z": "787c361b51b9d832",
"name": "ON",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "cont",
"v": "ON",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 622,
"y": 435,
"wires": [
[
"0271de3c43e83b63",
"15df05b0c1c9bc03",
"47799609d55e4892",
"3c181d2edef0aa42"
]
]
},
{
"id": "8fb38073d051089f",
"type": "change",
"z": "787c361b51b9d832",
"name": "Set currentTemp FLOW Value",
"rules": [
{
"t": "set",
"p": "currentTemp",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 370,
"y": 240,
"wires": [
[]
]
},
{
"id": "15df05b0c1c9bc03",
"type": "file in",
"z": "787c361b51b9d832",
"name": "READ tempNow.txt",
"filename": "/home/pi/scripts/temperature/currentTemps/insideFromApt.txt",
"filenameType": "str",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 130,
"y": 240,
"wires": [
[
"8fb38073d051089f"
]
]
},
{
"id": "47799609d55e4892",
"type": "file in",
"z": "787c361b51b9d832",
"name": "READ fanThreshold.txt",
"filename": "/home/pi/scripts/temperature/currentTemps/fanThreshold.txt",
"filenameType": "str",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 140,
"y": 180,
"wires": [
[
"6283761a5021dc1f"
]
]
},
{
"id": "6283761a5021dc1f",
"type": "change",
"z": "787c361b51b9d832",
"name": "Set threshold FLOW Value",
"rules": [
{
"t": "set",
"p": "threshold",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 380,
"y": 180,
"wires": [
[
"a5e0f4f975982884"
]
]
},
{
"id": "3c181d2edef0aa42",
"type": "delay",
"z": "787c361b51b9d832",
"name": "",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 600,
"y": 220,
"wires": [
[
"fe6085756568d779",
"0ae75004c433dcc1"
]
]
},
{
"id": "fe6085756568d779",
"type": "function",
"z": "787c361b51b9d832",
"name": "is currentTemp greater then ON",
"func": "if (flow.currentTemp >= flow.threshold){\nmsg.payload = 'ON';}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 710,
"y": 160,
"wires": [
[
"ca07b1e317370f3a"
]
]
},
{
"id": "0ae75004c433dcc1",
"type": "function",
"z": "787c361b51b9d832",
"name": "is currentTemp greater then OFF",
"func": "if (flow.currentTemp < flow.threshold){\nmsg.payload = \"OFF\";}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 710,
"y": 260,
"wires": [
[
"d3f0d0e1559e86df"
]
]
},
{
"id": "d3f0d0e1559e86df",
"type": "change",
"z": "787c361b51b9d832",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "OFF",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 960,
"y": 260,
"wires": [
[
"adc79e3075a38133",
"7430bc2f365004ac"
]
]
},
{
"id": "ca07b1e317370f3a",
"type": "change",
"z": "787c361b51b9d832",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ON",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 940,
"y": 160,
"wires": [
[
"9ccddd93d34e7fc1",
"7430bc2f365004ac"
]
]
},
{
"id": "7430bc2f365004ac",
"type": "debug",
"z": "787c361b51b9d832",
"name": "debug 299",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1090,
"y": 100,
"wires": []
}
]