Home Automation HAT - Reading state of output

Brecht

New member
Hi,

Is there any possibility to read the state of an (relay) output of a Home Automation HAT in node-red?
I want to do this so after a restart of the controller I can read the current state of the outputs.
 

alexburcea

Moderator
Staff member
Hi,

There is no way to do that with the native node, but you can use the exec node to run "ioplus 0 relrd" command

Alex.
 

Brecht

New member
Thanks Alex.

If anyone is looking for the same functionality, this is how I implemented it.
Code:
[
    {
        "id": "53c0f0e617b483a8",
        "type": "function",
        "z": "dd4d5a2b1c1bbc97",
        "name": "ConvertToBits",
        "func": "var StateInt;\nvar StateStr;\nvar Msg0, Msg1, Msg2, Msg3, Msg4, Msg5, Msg6, Msg7;\nStateInt = parseInt(msg.payload);\nStateStr = (\"00000000\" + (StateInt).toString(2)).slice(-8);\n//(\"00000000\" + number.toString(2)).slice(-8)\nMsg0 = {payload: StateStr[7]};\nMsg1 = {payload: StateStr[6]};\nMsg2 = {payload: StateStr[5]};\nMsg3 = {payload: StateStr[4]};\nMsg4 = {payload: StateStr[3]};\nMsg5 = {payload: StateStr[2]};\nMsg6 = {payload: StateStr[1]};\nMsg7 = {payload: StateStr[0]};\n\nreturn[Msg0, Msg1, Msg2, Msg3, Msg4, Msg5, Msg6, Msg7];\n//return [StateStr[7], StateStr[6], StateStr[5], StateStr[4], StateStr[3], StateStr[2], StateStr[1], StateStr[0]];",
        "outputs": 8,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1700,
        "y": 800,
        "wires": [
            [
                "0e5c85dda2cc8c74"
            ],
            [
                "21c6dd80a634ea21"
            ],
            [
                "464bf9377763f61e"
            ],
            [
                "dd3ef335b42108d0"
            ],
            [
                "93ba721bf89d75fe"
            ],
            [
                "38f998d6ae1c3125"
            ],
            [
                "bc79ab0fda0d1ea0"
            ],
            [
                "08712587792d318d"
            ]
        ]
    },
    {
        "id": "0e5c85dda2cc8c74",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit0(LSB)",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1940,
        "y": 660,
        "wires": []
    },
    {
        "id": "21c6dd80a634ea21",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1930,
        "y": 700,
        "wires": []
    },
    {
        "id": "464bf9377763f61e",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1930,
        "y": 740,
        "wires": []
    },
    {
        "id": "dd3ef335b42108d0",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1930,
        "y": 780,
        "wires": []
    },
    {
        "id": "93ba721bf89d75fe",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit4",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1930,
        "y": 820,
        "wires": []
    },
    {
        "id": "38f998d6ae1c3125",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit5",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1930,
        "y": 860,
        "wires": []
    },
    {
        "id": "bc79ab0fda0d1ea0",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit6",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1930,
        "y": 900,
        "wires": []
    },
    {
        "id": "08712587792d318d",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Bit7(MSB)",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1940,
        "y": 940,
        "wires": []
    },
    {
        "id": "9f77d6d6b9854375",
        "type": "exec",
        "z": "dd4d5a2b1c1bbc97",
        "command": "/home/admin/ioplus-rpi/ioplus 6 relrd",
        "addpay": "",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 1350,
        "y": 980,
        "wires": [
            [
                "d1aa42b78c10491d",
                "53c0f0e617b483a8"
            ],
            [
                "6cad37c7e7d67d1e"
            ],
            [
                "0006851ee5c36bf7"
            ]
        ]
    },
    {
        "id": "59ca4553b59a58de",
        "type": "inject",
        "z": "dd4d5a2b1c1bbc97",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1080,
        "y": 980,
        "wires": [
            [
                "9f77d6d6b9854375"
            ]
        ]
    },
    {
        "id": "6cad37c7e7d67d1e",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Standard error",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1660,
        "y": 980,
        "wires": []
    },
    {
        "id": "0006851ee5c36bf7",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Return code",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1650,
        "y": 1020,
        "wires": []
    },
    {
        "id": "d1aa42b78c10491d",
        "type": "debug",
        "z": "dd4d5a2b1c1bbc97",
        "name": "Standard output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1660,
        "y": 940,
        "wires": []
    }
]
 
Top