Hi, Thanks Colin and Steve
Having thought about this more, I would like to develop simple code, that can be eventually incorporated into my Arduino thermostat code, so I can use if, then, millis, true, false ... etc
I have a working Node-RED code that checks for a difference in temperature and outputs that number and if the same outputs 0.
Also it sends true, but at the moment I am at a loss how to do check if this change is still true after 10 seconds has passed ( in the real code this will be over 5 minutes ) but for testing this is fine.
Here is my Node-RED code so far
[
{
"id": "91022929bf1fc133",
"type": "inject",
"z": "78823dae3d2dd990",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "20.0",
"payloadType": "num",
"x": 400,
"y": 390,
"wires": [
[
"bc6ef697189fa2a9"
]
]
},
{
"id": "22cc28fa0c441d5a",
"type": "inject",
"z": "78823dae3d2dd990",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "20.01",
"payloadType": "num",
"x": 400,
"y": 430,
"wires": [
[
"bc6ef697189fa2a9"
]
]
},
{
"id": "60bfe79be59ae3f1",
"type": "inject",
"z": "78823dae3d2dd990",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "20.2",
"payloadType": "num",
"x": 400,
"y": 470,
"wires": [
[
"bc6ef697189fa2a9"
]
]
},
{
"id": "942bb207e1aa8841",
"type": "debug",
"z": "78823dae3d2dd990",
"name": "debug 165",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 650,
"y": 350,
"wires": []
},
{
"id": "bc6ef697189fa2a9",
"type": "function",
"z": "78823dae3d2dd990",
"name": "Check against previous",
"func": "\nvar previous = flow.get(\"previousvalue\") || 0; // Get stored value, use payload if nothing is stored\nflow.set(\"previousvalue\", msg.payload); // Save this value for next time\n\nvar difference = msg.payload - previous; // Compare the two\nmsg.payload = difference;\n\n\nif (difference == 0) \n{\n global.set(\"timer\", false); // Save this value for checking against time.\n node.send(msg); \n}\nelse\n{\n global.set(\"timer\", true); // Save this value for checking against time.\n node.send(msg); \n}\n\n\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 630,
"y": 390,
"wires": [
[
"942bb207e1aa8841",
"c62fcc1c2b353cd3"
]
]
},
{
"id": "c62fcc1c2b353cd3",
"type": "function",
"z": "78823dae3d2dd990",
"name": "Check rise in temperature against time",
"func": " \nmsg.payload = global.get(\"timer\");\n\nif (msg.payload === true) \n{\n\n// Need code here to check if temperature has increased over 30 seconds\n\n node.send(msg); \n\n// If temperature has NOT increased over 30 seconds\n global.set(\"timer\", false);\n\n}\n\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 950,
"y": 390,
"wires": [
[
"c65b5322fa0ebc4b"
]
]
},
{
"id": "c65b5322fa0ebc4b",
"type": "debug",
"z": "78823dae3d2dd990",
"name": "debug 166",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1010,
"y": 350,
"wires": []
},
{
"id": "14053d0daad1e222",
"type": "comment",
"z": "78823dae3d2dd990",
"name": "Temperatures",
"info": "",
"x": 380,
"y": 350,
"wires": []
}
]