6/13/2024, 10:45:56 AMnode: Temperature Handlerfunction : (error)
"TypeError: Cannot read properties of undefined (reading 'readFile')"
[
{
"id": "2ffefe74a7d3908d",
"type": "file in",
"z": "f2116ba899830da1",
"name": "temp read",
"filename": "/home/debian/temp.txt",
"filenameType": "str",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 380,
"y": 720,
"wires": [
[
"5def5a4cb6ba7bf6"
]
]
}
]
the file exists, permissions are 777 (for testing)
Here's the entire flow just in case.
{
"id": "f2116ba899830da1",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "9a72c14afcfe7cde",
"type": "mqtt in",
"z": "f2116ba899830da1",
"name": "Heatpump/heat",
"topic": "heatpump/heat",
"qos": "2",
"datatype": "auto-detect",
"broker": "38bf5da89401e7ba",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 140,
"y": 220,
"wires": [
[
"b9f5d8c69ebecb0b"
]
]
},
{
"id": "cdaf3563d4dbe443",
"type": "mqtt in",
"z": "f2116ba899830da1",
"name": "Auto MQTT",
"topic": "heatpump/auto",
"qos": "2",
"datatype": "auto-detect",
"broker": "38bf5da89401e7ba",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 130,
"y": 340,
"wires": [
[
"06732bcc45d44c8f"
]
]
},
{
"id": "232b922219c09889",
"type": "mqtt in",
"z": "f2116ba899830da1",
"name": "Fan MQTT",
"topic": "heatpump/fan",
"qos": "2",
"datatype": "auto-detect",
"broker": "38bf5da89401e7ba",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 120,
"y": 40,
"wires": [
[
"6d0162ef5ac15ca1"
]
]
},
{
"id": "8434a9bf5dc59c66",
"type": "mqtt in",
"z": "f2116ba899830da1",
"name": "Cool MQTT",
"topic": "heatpump/cool",
"qos": "2",
"datatype": "auto-detect",
"broker": "38bf5da89401e7ba",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 130,
"y": 120,
"wires": [
[
"4117b0a8545ff458"
]
]
},
{
"id": "2c567478d696b027",
"type": "mqtt in",
"z": "f2116ba899830da1",
"name": "Desired MQTT",
"topic": "heatpump/desired",
"qos": "2",
"datatype": "auto-detect",
"broker": "38bf5da89401e7ba",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 140,
"y": 440,
"wires": [
[
"25eacfa4065e1ac2"
]
]
},
{
"id": "6c71cf659898f4f6",
"type": "mqtt in",
"z": "f2116ba899830da1",
"name": "Temp MQTT",
"topic": "heatpump/temp",
"qos": "2",
"datatype": "auto-detect",
"broker": "38bf5da89401e7ba",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 130,
"y": 540,
"wires": [
[
"5b4243b766ac3bd6"
]
]
},
{
"id": "6d0162ef5ac15ca1",
"type": "switch",
"z": "f2116ba899830da1",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ON",
"vt": "str"
},
{
"t": "eq",
"v": "OFF",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 330,
"y": 40,
"wires": [
[
"3d4a86e60cd25ae3"
],
[
"d4a4f76557c8de3d"
]
]
},
{
"id": "4117b0a8545ff458",
"type": "switch",
"z": "f2116ba899830da1",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ON",
"vt": "str"
},
{
"t": "eq",
"v": "OFF",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 330,
"y": 120,
"wires": [
[
"97835733171620c4",
"d17414d88237089c",
"3d4a86e60cd25ae3"
],
[
"7dcf49e09582cbac",
"d4a4f76557c8de3d"
]
]
},
{
"id": "b9f5d8c69ebecb0b",
"type": "switch",
"z": "f2116ba899830da1",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ON",
"vt": "str"
},
{
"t": "eq",
"v": "OFF",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 330,
"y": 220,
"wires": [
[
"d8063f57c29aca44",
"7dcf49e09582cbac",
"3d4a86e60cd25ae3"
],
[
"d17414d88237089c",
"d4a4f76557c8de3d"
]
]
},
{
"id": "3d4a86e60cd25ae3",
"type": "exec",
"z": "f2116ba899830da1",
"command": "home/debian/fan_on.sh",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "Fan ON",
"x": 680,
"y": 20,
"wires": [
[
"ddef8c95892a987f"
],
[],
[]
]
},
{
"id": "7dcf49e09582cbac",
"type": "exec",
"z": "f2116ba899830da1",
"command": "home/debian/cool_off.sh",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "Cool OFF",
"x": 880,
"y": 140,
"wires": [
[],
[],
[]
]
},
{
"id": "feef1ff0a4219b77",
"type": "exec",
"z": "f2116ba899830da1",
"command": "home/debian/cool_on.sh",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "Cool ON",
"x": 680,
"y": 100,
"wires": [
[
"4452067148b87859"
],
[],
[]
]
},
{
"id": "d17414d88237089c",
"type": "exec",
"z": "f2116ba899830da1",
"command": "home/debian/heat_off.sh",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "Heat OFF",
"x": 880,
"y": 240,
"wires": [
[],
[],
[]
]
},
{
"id": "9f316e51d609cefd",
"type": "exec",
"z": "f2116ba899830da1",
"command": "home/debian/heat_on.sh",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "Heat ON",
"x": 700,
"y": 200,
"wires": [
[
"7082cffb63cc10ac"
],
[],
[]
]
},
{
"id": "97835733171620c4",
"type": "delay",
"z": "f2116ba899830da1",
"name": "",
"pauseType": "delay",
"timeout": "30",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 500,
"y": 120,
"wires": [
[
"feef1ff0a4219b77"
]
]
},
{
"id": "d8063f57c29aca44",
"type": "delay",
"z": "f2116ba899830da1",
"name": "",
"pauseType": "delay",
"timeout": "30",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 500,
"y": 220,
"wires": [
[
"9f316e51d609cefd"
]
]
},
{
"id": "06732bcc45d44c8f",
"type": "switch",
"z": "f2116ba899830da1",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ON",
"vt": "str"
},
{
"t": "eq",
"v": "OFF",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 330,
"y": 340,
"wires": [
[
"5def5a4cb6ba7bf6"
],
[]
]
},
{
"id": "25eacfa4065e1ac2",
"type": "file",
"z": "f2116ba899830da1",
"name": "desired.txt",
"filename": "/home/debian/desired.txt",
"filenameType": "str",
"appendNewline": false,
"createDir": false,
"overwriteFile": "true",
"encoding": "none",
"x": 370,
"y": 440,
"wires": [
[]
]
},
{
"id": "5b4243b766ac3bd6",
"type": "file",
"z": "f2116ba899830da1",
"name": "temp.txt",
"filename": "/home/debian/temp.txt",
"filenameType": "str",
"appendNewline": false,
"createDir": false,
"overwriteFile": "true",
"encoding": "none",
"x": 360,
"y": 540,
"wires": [
[]
]
},
{
"id": "36ca8d85981c0d22",
"type": "file in",
"z": "f2116ba899830da1",
"name": "desired read",
"filename": "/home/debian/desired.txt",
"filenameType": "str",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 370,
"y": 660,
"wires": [
[
"5def5a4cb6ba7bf6"
]
]
},
{
"id": "2ffefe74a7d3908d",
"type": "file in",
"z": "f2116ba899830da1",
"name": "temp read",
"filename": "/home/debian/temp.txt",
"filenameType": "str",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 380,
"y": 720,
"wires": [
[
"5def5a4cb6ba7bf6"
]
]
},
{
"id": "743f7d650d452752",
"type": "watch",
"z": "f2116ba899830da1",
"name": "desired watch",
"files": "/home/debian/desired.txt",
"recursive": "",
"x": 170,
"y": 660,
"wires": [
[
"36ca8d85981c0d22"
]
]
},
{
"id": "00c584c303162185",
"type": "watch",
"z": "f2116ba899830da1",
"name": "temp watch",
"files": "/home/debian/temp.txt",
"recursive": "",
"x": 170,
"y": 720,
"wires": [
[
"2ffefe74a7d3908d"
]
]
},
{
"id": "ddef8c95892a987f",
"type": "mqtt out",
"z": "f2116ba899830da1",
"name": "Fan Condition",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "38bf5da89401e7ba",
"x": 1280,
"y": 40,
"wires": []
},
{
"id": "4452067148b87859",
"type": "mqtt out",
"z": "f2116ba899830da1",
"name": "Cooling",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "38bf5da89401e7ba",
"x": 1260,
"y": 120,
"wires": []
},
{
"id": "7082cffb63cc10ac",
"type": "mqtt out",
"z": "f2116ba899830da1",
"name": "Heating",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "38bf5da89401e7ba",
"x": 1260,
"y": 200,
"wires": []
},
{
"id": "d4a4f76557c8de3d",
"type": "exec",
"z": "f2116ba899830da1",
"command": "/home/debian/fan_off.sh",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "Fan OFF",
"x": 880,
"y": 60,
"wires": [
[
"ddef8c95892a987f"
],
[],
[]
]
},
{
"id": "5def5a4cb6ba7bf6",
"type": "function",
"z": "f2116ba899830da1",
"name": "Temperature Handler",
"func": "const fs = global.get('fs');\n\nfs.readFile('/home/debian/desired.txt', 'utf8', (err, desiredData) => {\n if (err) {\n node.error('Error reading desired temperature file', err);\n return;\n }\n const desiredTemp = parseFloat(desiredData.trim());\n\n fs.readFile('/home/debian/temp.txt', 'utf8', (err, actualData) => {\n if (err) {\n node.error('Error reading actual temperature file', err);\n return;\n }\n const actualTemp = parseFloat(actualData.trim());\n\n let msg = null;\n\n if (actualTemp >= desiredTemp + 2) {\n msg = { topic: 'heatpump/cool', payload: 'ON' };\n } else if (actualTemp <= desiredTemp - 2) {\n msg = { topic: 'heatpump/heat', payload: 'ON' };\n } else if (actualTemp <= desiredTemp + 1) {\n msg = { topic: 'heatpump/cool', payload: 'OFF' };\n } else if (actualTemp >= desiredTemp - 1) {\n msg = { topic: 'heatpump/heat', payload: 'OFF' };\n }\n\n if (msg) {\n node.send([msg, null]);\n }\n });\n});\nreturn [null, null];",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 680,
"y": 660,
"wires": [
[
"4117b0a8545ff458",
"c04c50d381c27c80"
],
[
"b9f5d8c69ebecb0b",
"bc6ff2b69b0a7c28"
]
]
},
{
"id": "c04c50d381c27c80",
"type": "debug",
"z": "f2116ba899830da1",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 600,
"wires": []
},
{
"id": "bc6ff2b69b0a7c28",
"type": "debug",
"z": "f2116ba899830da1",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 720,
"wires": []
},
{
"id": "38bf5da89401e7ba",
"type": "mqtt-broker",
"name": "Test",
"broker": "localhost",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "home/test",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]
I am an old electrician and am a little lost in software.