Home Automation HAT - Reading state of output


  • 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.


  • 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.

  • Thanks Alex.

    If anyone is looking for the same functionality, this is how I implemented it.
    [
    {
    "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": []
    }
    ]

  • This is a seperate topic - however I can't an option to create a new thread.  I have an issue with the HAT seemingly becoming unavailable after a period of time (the period varies from 5 seconds to several minutes).  I have written a few Python test scripts to read the relay status's and a couple of One Wire Bus temp sensors - the error is indicating a loss of comms to the module.  The HAT was shipped to me a few weeks ago so I assume it is the latest firmware and I have updated the ioplus stuff from Github.  I am struggling to understand precisely what is happening - is there a debug switch I can throw programmatically to get an understanding why it seems to lose comms?

     

    Traceback (most recent call last):
      File "/usr/local/lib/python3.9/dist-packages/libioplus/__init__.py", line 197, in getRelays
        val = bus.read_byte_data(DEVICE_ADDRESS + stack, RELAY_VAL_ADD)
      File "/usr/local/lib/python3.9/dist-packages/smbus2/smbus2.py", line 435, in read_byte_data
        ioctl(self.fd, I2C_SMBUS, msg)
    TimeoutError: [Errno 110] Connection timed out

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/home/vk4rtt/vk4rtt/read_hat.py", line 29, in <module>
        print(io.getRelayCh(0,1),io.getRelayCh(0,2),io.getRelayCh(0,3),io.getRelayCh(0,4),io.getRelayCh(0,5),io.getRelayCh(0,6))
      File "/usr/local/lib/python3.9/dist-packages/libioplus/__init__.py", line 212, in getRelayCh
        val = getRelays(stack)
      File "/usr/local/lib/python3.9/dist-packages/libioplus/__init__.py", line 200, in getRelays
        raise Exception(e)
    Exception: [Errno 110] Connection timed out


  • Hi Peter,

     

    Increase the frequency of the Raspberry Pi I2C port to 400k.

    For some use cases, solve the problem.

    Alex.

     


Please login to reply this topic!