OPCUA interface with HA using Asyncua module

Hi all,

I have been working with the integration of various PLC to HA over OPC UA for the past few months. My initial approach was to develop a gateway which connect to the PLC over restful api. After a couple of integration, I found that it would be much benefitial to have a custom integration in HA for OPC UA.

I found an older project which uses the python-opcua, which is deprecated and decided to start a new integration using opcua-asyncio.

The project is currently in development and is per poll based. Asycua component. Follow the instruction shown in the README.md file to start using!

2 Likes

Hello,

i got it to work as custom component but i get an error with version 2024.1

Logger: asyncua
Source: custom_components/asyncua/init.py:210
Integration: asyncua
First occurred: 9:05:47 AM (3 occurrences)
Last logged: 9:06:47 AM

Runtime error: argument to node must be a NodeId object or a string defining a nodeid found ns=2;s=Siemens s7 300.Data.1 of type <class ‘homeassistant.util.yaml.objects.NodeStrClass’>

can you help please ?

Thank you very much

Hi Kassem-ajjan,

can you share your yaml configuration here? I might be able to diagnose it with more details.

I might have found the bug. I think it might be caused from a recent update in homeassistant. I am working on a fix now together with a easier integration with hacs for better tracking and updates.

Hello,

Thanks to JanHre on github i have a solution for opcua integration
Hi
at init.py

  nodeid = service.data[ATTR_NODEID]

replace all

 nodeid = str(service.data[ATTR_NODEID])

at sensor.py

        hub = hass.data[OPCUA_DOMAIN][hub_name]

        sensors.append(
            OpcuaNodeidSensor(
                hub,
                node[CONF_NAME],
                node[CONF_NODEID],

replace

        hub = hass.data[OPCUA_DOMAIN][hub_name]
        node_id = str(node[CONF_NODEID])

        sensors.append(
            OpcuaNodeidSensor(
                hub,
                node[CONF_NAME],
                node_id,
1 Like

I have just added the feature to install this custom integration using HACS. Follow the
guide in the README.md file.

Bug with the recent HA update 2024.1 is also resolved.

Hi,
How to write to an opc-ua server from HA

Hi Maerks69,

to write value to a node using this integration, you can find a new service under Developer ToolsServicesasyncua: set value

Paste the following code sample in UI Mode in the data section and make the necessary changes:

hub: plc-01    # unique hub ID defined in the coordinator
nodeid: ns=1;s=1000
value: false    # identifier type defined from the server

In YAML Mode, paste the following code sample and make the necessary changes:

service: asyncua.set_value
target: {}
data:
  hub: plc-01
  nodeid: ns=1;s=1000
  value: false