Oulààà tu déterres des archives
J'avais presque oublié cette vidéo. Oui j'ai une grosse tête, j'ai en peu corrigé dans les dernières. J'ai moins la grosse tête
Bon j'ai vraiment dû fouiller pour retrouver le code.
Le voici.
Je l'avais trouvé tel que sur le Net à l'époque. Il pourrait à l'évidence être amélioré mais il fonctionnait.
La bestiole, c'est mon fils un jour qui est venu avec et m'a dit, tiens ils ne s'en servent pas au boulot.
Ca fonctionne bien cela dit. Mais j'ai un faible certain pour le petit dernier en zigbee direct dans HA. Ah le prêt à porter sur la confection de masse, éternel débat.
Bon j'arrête de délirer, voici le code
Format fichier:
flows(39).json (Taille : 12.67 Ko / Téléchargements : 25)
Ou direct copier / coller
J'avais presque oublié cette vidéo. Oui j'ai une grosse tête, j'ai en peu corrigé dans les dernières. J'ai moins la grosse tête
Bon j'ai vraiment dû fouiller pour retrouver le code.
Le voici.
Je l'avais trouvé tel que sur le Net à l'époque. Il pourrait à l'évidence être amélioré mais il fonctionnait.
La bestiole, c'est mon fils un jour qui est venu avec et m'a dit, tiens ils ne s'en servent pas au boulot.
Ca fonctionne bien cela dit. Mais j'ai un faible certain pour le petit dernier en zigbee direct dans HA. Ah le prêt à porter sur la confection de masse, éternel débat.
Bon j'arrête de délirer, voici le code
Format fichier:
flows(39).json (Taille : 12.67 Ko / Téléchargements : 25)
Ou direct copier / coller
Code :
[
{
"id": "de9ded18.1099f",
"type": "tab",
"label": "Modbus Energy meter",
"disabled": false,
"info": ""
},
{
"id": "b3ae0448.822d08",
"type": "comment",
"z": "de9ded18.1099f",
"name": "SDM120 Energy Meter",
"info": "",
"x": 140,
"y": 280,
"wires": []
},
{
"id": "53b4b356.bf124c",
"type": "modbus-read",
"z": "de9ded18.1099f",
"name": "SDM 120 Voltage",
"topic": "",
"showStatusActivities": true,
"logIOActivities": false,
"showErrors": true,
"unitid": "1",
"dataType": "InputRegister",
"adr": "0",
"quantity": "2",
"rate": "5",
"rateUnit": "s",
"delayOnStart": true,
"startDelayTime": "5",
"server": "40f20c7f.13a934",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"x": 140,
"y": 340,
"wires": [
[
"e4d3fade.1132a8"
],
[]
]
},
{
"id": "e4d3fade.1132a8",
"type": "function",
"z": "de9ded18.1099f",
"name": "Voltage",
"func": "var rawData = new ArrayBuffer(4);\nvar intView = new Uint16Array(rawData);\nvar fltView = new Float32Array(rawData);\n\nintView[0] = msg.payload[1]; //low\nintView[1] = msg.payload[0]; //high\n\nmsg.payload = parseFloat(fltView[0].toFixed(1));\nmsg.topic = \"voltage\";\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.topic + \":\" + msg.payload}); \n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 320,
"y": 340,
"wires": [
[
"94b7c2b7.b61ae",
"267d6c75.311c84"
]
]
},
{
"id": "e3643b3e.be3a88",
"type": "function",
"z": "de9ded18.1099f",
"name": "Current",
"func": "var rawData = new ArrayBuffer(4);\nvar intView = new Uint16Array(rawData);\nvar fltView = new Float32Array(rawData);\n\nintView[0] = msg.payload[1]; //low\nintView[1] = msg.payload[0]; //high\n\nmsg.payload = parseFloat(fltView[0].toFixed(1));\nmsg.topic = \"current\";\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.topic + \":\" + msg.payload}); \n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 320,
"y": 400,
"wires": [
[
"fa18b5f3.ba6be8",
"267d6c75.311c84"
]
]
},
{
"id": "4dbf9277.487e4c",
"type": "function",
"z": "de9ded18.1099f",
"name": "Power",
"func": "var rawData = new ArrayBuffer(4);\nvar intView = new Uint16Array(rawData);\nvar fltView = new Float32Array(rawData);\n\nintView[0] = msg.payload[1]; //low\nintView[1] = msg.payload[0]; //high\n\nmsg.payload = parseFloat(fltView[0].toFixed(1));\nmsg.payload = msg.payload * (-1)\nmsg.topic = \"power\";\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.topic + \":\" + msg.payload}); \n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 310,
"y": 460,
"wires": [
[
"c3697655.758e28",
"267d6c75.311c84"
]
]
},
{
"id": "593c6698.c25388",
"type": "function",
"z": "de9ded18.1099f",
"name": "Frequency",
"func": "var rawData = new ArrayBuffer(4);\nvar intView = new Uint16Array(rawData);\nvar fltView = new Float32Array(rawData);\n\nintView[0] = msg.payload[1]; //low\nintView[1] = msg.payload[0]; //high\n\nmsg.payload = parseFloat(fltView[0].toFixed(1));\nmsg.topic = \"frequency\";\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.topic + \":\" + msg.payload}); \n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 330,
"y": 520,
"wires": [
[
"c38e8fed.7fb6a",
"267d6c75.311c84"
]
]
},
{
"id": "7df027a2.13a1f8",
"type": "function",
"z": "de9ded18.1099f",
"name": "Energy",
"func": "var rawData = new ArrayBuffer(4);\nvar intView = new Uint16Array(rawData);\nvar fltView = new Float32Array(rawData);\n\nintView[0] = msg.payload[1]; //low\nintView[1] = msg.payload[0]; //high\n\nmsg.payload = parseFloat(fltView[0].toFixed(2));\nmsg.topic = \"energy\";\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.topic + \":\" + msg.payload}); \n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 320,
"y": 580,
"wires": [
[
"d87b3ecd.2dab2",
"267d6c75.311c84"
]
]
},
{
"id": "7d42a707.bcd618",
"type": "modbus-read",
"z": "de9ded18.1099f",
"name": "SDM 120 Current",
"topic": "",
"showStatusActivities": true,
"logIOActivities": false,
"showErrors": true,
"unitid": "1",
"dataType": "InputRegister",
"adr": "6",
"quantity": "2",
"rate": "5",
"rateUnit": "s",
"delayOnStart": true,
"startDelayTime": "5",
"server": "40f20c7f.13a934",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"x": 140,
"y": 400,
"wires": [
[
"e3643b3e.be3a88"
],
[]
]
},
{
"id": "576a7fbe.d0861",
"type": "modbus-read",
"z": "de9ded18.1099f",
"name": "SDM 120 Power",
"topic": "",
"showStatusActivities": true,
"logIOActivities": false,
"showErrors": true,
"unitid": "1",
"dataType": "InputRegister",
"adr": "12",
"quantity": "2",
"rate": "5",
"rateUnit": "s",
"delayOnStart": true,
"startDelayTime": "5",
"server": "40f20c7f.13a934",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"x": 140,
"y": 460,
"wires": [
[
"4dbf9277.487e4c"
],
[]
]
},
{
"id": "519b5a74.1a7314",
"type": "modbus-read",
"z": "de9ded18.1099f",
"name": "SDM 120 Frequency",
"topic": "",
"showStatusActivities": true,
"logIOActivities": false,
"showErrors": true,
"unitid": "1",
"dataType": "InputRegister",
"adr": "70",
"quantity": "2",
"rate": "5",
"rateUnit": "s",
"delayOnStart": true,
"startDelayTime": "5",
"server": "40f20c7f.13a934",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"x": 150,
"y": 520,
"wires": [
[
"593c6698.c25388"
],
[]
]
},
{
"id": "b84798db.04be98",
"type": "modbus-read",
"z": "de9ded18.1099f",
"name": "SDM 120 Energy",
"topic": "",
"showStatusActivities": true,
"logIOActivities": false,
"showErrors": true,
"unitid": "1",
"dataType": "InputRegister",
"adr": "342",
"quantity": "2",
"rate": "60",
"rateUnit": "s",
"delayOnStart": true,
"startDelayTime": "5",
"server": "40f20c7f.13a934",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"x": 140,
"y": 580,
"wires": [
[
"7df027a2.13a1f8",
"1b35ee5d.7dd512"
],
[]
]
},
{
"id": "94b7c2b7.b61ae",
"type": "ui_text",
"z": "de9ded18.1099f",
"group": "b1bb14f0043ca966",
"order": 0,
"width": 0,
"height": 0,
"name": "",
"label": "Voltage",
"format": "{{msg.payload}} V",
"layout": "row-spread",
"x": 500,
"y": 340,
"wires": []
},
{
"id": "fa18b5f3.ba6be8",
"type": "ui_text",
"z": "de9ded18.1099f",
"group": "b1bb14f0043ca966",
"order": 1,
"width": 0,
"height": 0,
"name": "",
"label": "Current",
"format": "{{msg.payload}} A",
"layout": "row-spread",
"x": 500,
"y": 400,
"wires": []
},
{
"id": "c3697655.758e28",
"type": "ui_text",
"z": "de9ded18.1099f",
"group": "b1bb14f0043ca966",
"order": 2,
"width": 0,
"height": 0,
"name": "",
"label": "Power",
"format": "{{msg.payload}} W",
"layout": "row-spread",
"x": 490,
"y": 460,
"wires": []
},
{
"id": "c38e8fed.7fb6a",
"type": "ui_text",
"z": "de9ded18.1099f",
"group": "b1bb14f0043ca966",
"order": 3,
"width": 0,
"height": 0,
"name": "",
"label": "Frequency",
"format": "{{msg.payload}} Hz",
"layout": "row-spread",
"x": 510,
"y": 520,
"wires": []
},
{
"id": "d87b3ecd.2dab2",
"type": "ui_text",
"z": "de9ded18.1099f",
"group": "b1bb14f0043ca966",
"order": 4,
"width": 0,
"height": 0,
"name": "",
"label": "Total Energy",
"format": "{{msg.payload}} kWh",
"layout": "row-spread",
"x": 510,
"y": 580,
"wires": []
},
{
"id": "267d6c75.311c84",
"type": "function",
"z": "de9ded18.1099f",
"name": "Build object",
"func": "watch_topic = \"energy\";\nvar output = {};\n\ncontext.set(msg.topic,msg.payload);\n\nif (context.get(\"voltage\")!==undefined) {\n output.voltage = context.get(\"voltage\");\n}\nif (context.get(\"current\")!==undefined) {\n output.current = context.get(\"current\");\n}\nif (context.get(\"power\")!==undefined) {\n output.power = context.get(\"power\");\n}\nif (context.get(\"frequency\")!==undefined) {\n output.frequency = context.get(\"frequency\");\n}\nif (context.get(\"energy\")!==undefined) {\n output.energy = context.get(\"energy\");\n}\nmsg.payload = output;\n\nif (msg.topic===watch_topic) {\n msg.topic = \"sdm120\";\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 770,
"y": 480,
"wires": [
[
"6d3190d1.e5037"
]
]
},
{
"id": "6d3190d1.e5037",
"type": "debug",
"z": "de9ded18.1099f",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"complete": "true",
"statusVal": "",
"statusType": "auto",
"x": 910,
"y": 480,
"wires": []
},
{
"id": "1b35ee5d.7dd512",
"type": "debug",
"z": "de9ded18.1099f",
"name": "data array",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 320,
"y": 640,
"wires": []
},
{
"id": "40f20c7f.13a934",
"type": "modbus-client",
"name": "Modbus SDM120",
"clienttype": "serial",
"bufferCommands": true,
"stateLogEnabled": false,
"queueLogEnabled": false,
"failureLogEnabled": false,
"tcpHost": "127.0.0.1",
"tcpPort": "502",
"tcpType": "DEFAULT",
"serialPort": "/dev/ttyUSB0",
"serialType": "RTU-BUFFERD",
"serialBaudrate": "9600",
"serialDatabits": "8",
"serialStopbits": "1",
"serialParity": "none",
"serialConnectionDelay": "100",
"serialAsciiResponseStartDelimiter": "",
"unit_id": "",
"commandDelay": 30,
"clientTimeout": 2000,
"reconnectOnTimeout": false,
"reconnectTimeout": 5000,
"parallelUnitIdsAllowed": false
},
{
"id": "b1bb14f0043ca966",
"type": "ui_group",
"name": "SDM120 Energy Meter",
"tab": "ae839dae17d774a1",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "ae839dae17d774a1",
"type": "ui_tab",
"name": "Modbus",
"icon": "memory",
"order": 28,
"disabled": false,
"hidden": false
}
]
Jean-Luc