VFD Control using Modbus RTC

Hi Fellow DIY'ers
Im currently building a hvac control system for a piggery where ill control all the fans using dashboard, rpi5, usb-rs485, modbus etc. here is my sample code, enjoy if you can use some of it for your projects.

    {
        "id": "0ffd7e16e625f993",
        "type": "modbus-flex-getter",
        "z": "c588c80b92a968b7",
        "name": "",
        "showStatusActivities": false,
        "showErrors": true,
        "showWarnings": true,
        "logIOActivities": false,
        "server": "691f551bdceac91b",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 890,
        "y": 200,
        "wires": [
            [
                "212bfa1611758bfe"
            ],
            []
        ]
    },
    {
        "id": "fdba5ea78651f043",
        "type": "ui_slider",
        "z": "c588c80b92a968b7",
        "name": "speed",
        "label": "Speed",
        "tooltip": "",
        "group": "977e52f003fb5a09",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": true,
        "outs": "end",
        "topic": "speed",
        "topicType": "str",
        "min": 0,
        "max": "100",
        "step": "5",
        "className": "",
        "x": 250,
        "y": 180,
        "wires": [
            [
                "858f2e6f5988132b",
                "6d21e4e8c27902d7"
            ]
        ]
    },
    {
        "id": "858f2e6f5988132b",
        "type": "ui_gauge",
        "z": "c588c80b92a968b7",
        "name": "sg1",
        "group": "977e52f003fb5a09",
        "order": 2,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Speed",
        "label": "%",
        "format": "{{value}}",
        "min": 0,
        "max": "100",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "diff": false,
        "className": "",
        "x": 670,
        "y": 180,
        "wires": []
    },
    {
        "id": "23f4d2f43777506d",
        "type": "ui_button",
        "z": "c588c80b92a968b7",
        "name": "start",
        "group": "977e52f003fb5a09",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Start",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "1",
        "payloadType": "num",
        "topic": "run",
        "topicType": "str",
        "x": 250,
        "y": 240,
        "wires": [
            [
                "6d21e4e8c27902d7"
            ]
        ]
    },
    {
        "id": "5e334651d0883c1d",
        "type": "ui_button",
        "z": "c588c80b92a968b7",
        "name": "stop",
        "group": "977e52f003fb5a09",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Stop",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "6",
        "payloadType": "num",
        "topic": "run",
        "topicType": "str",
        "x": 250,
        "y": 280,
        "wires": [
            [
                "6d21e4e8c27902d7"
            ]
        ]
    },
    {
        "id": "212bfa1611758bfe",
        "type": "debug",
        "z": "c588c80b92a968b7",
        "name": "debug 24",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1160,
        "y": 220,
        "wires": []
    },
    {
        "id": "3096ddcb15b3fbea",
        "type": "modbus-flex-write",
        "z": "c588c80b92a968b7",
        "name": "write",
        "showStatusActivities": true,
        "showErrors": true,
        "showWarnings": true,
        "server": "691f551bdceac91b",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 930,
        "y": 240,
        "wires": [
            [
                "212bfa1611758bfe"
            ],
            []
        ]
    },
    {
        "id": "6d21e4e8c27902d7",
        "type": "function",
        "z": "c588c80b92a968b7",
        "name": "speed-1",
        "func": "if (msg.topic === \"speed\") {\n    var speed = msg.payload * 100;\n    msg.payload = {\n        \"fc\": 6,          // Function code for writing a single holding register\n        \"unitid\": 1,      // Node address\n        \"address\": 4096,  // Frequency setting address (1000H in decimal)\n        \"value\": speed,\n        \"quantity\": 1     // Frequency value to set (100% corresponds to 10000)\n    };\n} else if (msg.topic === \"run\") {\n    var command = msg.payload;\n    msg.payload = {\n        \"fc\": 6,          // Function code for writing a single holding register\n        \"unitid\": 1,      // Node address\n        \"address\": 8192,  // Start command address (2000H in decimal)\n        \"value\": command,\n        \"quantity\": 1     // Start/stop command value (0001 for start, 0006 for stop)\n    };\n}\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 240,
        "wires": [
            [
                "3096ddcb15b3fbea"
            ]
        ]
    },
    {
        "id": "cd93c2f776221428",
        "type": "inject",
        "z": "c588c80b92a968b7",
        "name": "test",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "test",
        "payload": "{\"fc\":3,\"unitid\":1,\"address\":4096,\"quantity\":10}",
        "payloadType": "json",
        "x": 930,
        "y": 100,
        "wires": [
            [
                "0ffd7e16e625f993"
            ]
        ]
    },
    {
        "id": "691f551bdceac91b",
        "type": "modbus-client",
        "name": "test",
        "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": "0x3A",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true,
        "showErrors": true,
        "showWarnings": true,
        "showLogs": true
    },
    {
        "id": "977e52f003fb5a09",
        "type": "ui_group",
        "name": "Smågris 1 øst",
        "tab": "c8057a05c64f69f5",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "c8057a05c64f69f5",
        "type": "ui_tab",
        "name": "Ventilasjon",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]```
[
    {
        "id": "0ffd7e16e625f993",
        "type": "modbus-flex-getter",
        "z": "c588c80b92a968b7",
        "name": "",
        "showStatusActivities": false,
        "showErrors": true,
        "showWarnings": true,
        "logIOActivities": false,
        "server": "691f551bdceac91b",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 890,
        "y": 200,
        "wires": [
            [
                "212bfa1611758bfe"
            ],
            []
        ]
    },
    {
        "id": "fdba5ea78651f043",
        "type": "ui_slider",
        "z": "c588c80b92a968b7",
        "name": "speed",
        "label": "Speed",
        "tooltip": "",
        "group": "977e52f003fb5a09",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": true,
        "outs": "end",
        "topic": "speed",
        "topicType": "str",
        "min": 0,
        "max": "100",
        "step": "5",
        "className": "",
        "x": 250,
        "y": 180,
        "wires": [
            [
                "858f2e6f5988132b",
                "6d21e4e8c27902d7"
            ]
        ]
    },
    {
        "id": "858f2e6f5988132b",
        "type": "ui_gauge",
        "z": "c588c80b92a968b7",
        "name": "sg1",
        "group": "977e52f003fb5a09",
        "order": 2,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Speed",
        "label": "%",
        "format": "{{value}}",
        "min": 0,
        "max": "100",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "diff": false,
        "className": "",
        "x": 670,
        "y": 180,
        "wires": []
    },
    {
        "id": "23f4d2f43777506d",
        "type": "ui_button",
        "z": "c588c80b92a968b7",
        "name": "start",
        "group": "977e52f003fb5a09",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Start",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "1",
        "payloadType": "num",
        "topic": "run",
        "topicType": "str",
        "x": 250,
        "y": 240,
        "wires": [
            [
                "6d21e4e8c27902d7"
            ]
        ]
    },
    {
        "id": "5e334651d0883c1d",
        "type": "ui_button",
        "z": "c588c80b92a968b7",
        "name": "stop",
        "group": "977e52f003fb5a09",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Stop",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "6",
        "payloadType": "num",
        "topic": "run",
        "topicType": "str",
        "x": 250,
        "y": 280,
        "wires": [
            [
                "6d21e4e8c27902d7"
            ]
        ]
    },
    {
        "id": "212bfa1611758bfe",
        "type": "debug",
        "z": "c588c80b92a968b7",
        "name": "debug 24",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1160,
        "y": 220,
        "wires": []
    },
    {
        "id": "3096ddcb15b3fbea",
        "type": "modbus-flex-write",
        "z": "c588c80b92a968b7",
        "name": "write",
        "showStatusActivities": true,
        "showErrors": true,
        "showWarnings": true,
        "server": "691f551bdceac91b",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 930,
        "y": 240,
        "wires": [
            [
                "212bfa1611758bfe"
            ],
            []
        ]
    },
    {
        "id": "6d21e4e8c27902d7",
        "type": "function",
        "z": "c588c80b92a968b7",
        "name": "speed-1",
        "func": "if (msg.topic === \"speed\") {\n    var speed = msg.payload * 100;\n    msg.payload = {\n        \"fc\": 6,          // Function code for writing a single holding register\n        \"unitid\": 1,      // Node address\n        \"address\": 4096,  // Frequency setting address (1000H in decimal)\n        \"value\": speed,\n        \"quantity\": 1     // Frequency value to set (100% corresponds to 10000)\n    };\n} else if (msg.topic === \"run\") {\n    var command = msg.payload;\n    msg.payload = {\n        \"fc\": 6,          // Function code for writing a single holding register\n        \"unitid\": 1,      // Node address\n        \"address\": 8192,  // Start command address (2000H in decimal)\n        \"value\": command,\n        \"quantity\": 1     // Start/stop command value (0001 for start, 0006 for stop)\n    };\n}\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 240,
        "wires": [
            [
                "3096ddcb15b3fbea"
            ]
        ]
    },
    {
        "id": "cd93c2f776221428",
        "type": "inject",
        "z": "c588c80b92a968b7",
        "name": "test",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "test",
        "payload": "{\"fc\":3,\"unitid\":1,\"address\":4096,\"quantity\":10}",
        "payloadType": "json",
        "x": 930,
        "y": 100,
        "wires": [
            [
                "0ffd7e16e625f993"
            ]
        ]
    },
    {
        "id": "691f551bdceac91b",
        "type": "modbus-client",
        "name": "test",
        "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": "0x3A",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true,
        "showErrors": true,
        "showWarnings": true,
        "showLogs": true
    },
    {
        "id": "977e52f003fb5a09",
        "type": "ui_group",
        "name": "Smågris 1 øst",
        "tab": "c8057a05c64f69f5",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "c8057a05c64f69f5",
        "type": "ui_tab",
        "name": "Ventilasjon",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

1 Like