OPC UA Interface to HA

succes :

I first had to unhide these running containers. In Portainer in settings :

there were entries which hide all ha addons & components.
Now I see all containers running and could shell into the homeassistant container and succesfully install opcua with pip install opcua.

thanks ! :slight_smile:
Now i can try the opcua addons furtherā€¦

Glad it worked.

I am just testing the security type setups and will post a github repo link soon.

this will allow creation of OpcUA sensors in HA.

I tried LarsAC 's first initial addon since that is also what I want most (mapping HA variables to OPC UA tags).

I then also got the error:

I got a syntax error in line 9 in the server.py:
"import homeassistant.remote as remote
ModuleNotFoundError: No module named ā€˜homeassistantā€™

strange because python class/module homeassistant.remote should be there in homeassistant container I guess ?

I havenā€™t actually tried the OP code for mapping. I got tied into this looking for a way to create opcua based sensors and write data back as needed. so I wont be much help.

But if you would like to try out an my custom component feel free to check out my repository at: opcua custom component

Hello,

Itā€™s my first post within home assistant community.
Im very interesting opc ua connection with home assistant. Im trying to connect codesys with home assistant with opc ua. Anybody can help me?

monty_burns_007, how did you configure larsACs addon? minix1234, i tried to install your custom component, but im beginner in home assistant, Can you show me about it?

Thanks everybody.

evening,

you need to create a folder named custom_components in the home assistant configuration directory (same one as the configuration.yaml).

then make a subdirectory in the custom_components called ā€œopcuaā€. which contains all the files of my repo.

restart and it should be installed

Hello,

Thank you Minimix pour you HA Componant.

I have a problem since I add this three line in configuration.yaml file, HA crash.

opcua:
  - name: WAGO_OPC_UA  
  url: "opc.tcp://192.168.0.21:4840/"

I need to restart my virtual machine on the QNAP NAS.

An idea ?

is the spacing of your provided yaml correct? url should be directly under the name

do you have any logs from the virtual machine?

Home-assistant.log file :

2021-03-03 14:00:26 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.


2021-03-03 14:00:34 CRITICAL (Thread-3) [opcua.client.ua_client.Socket] Received an error: MessageAbort(error:StatusCode(BadSecurityPolicyRejected), reason:None)
2021-03-03 14:00:34 ERROR (Thread-3) [opcua.client.ua_client.Socket] Protocol Error
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/opcua/client/ua_client.py", line 101, in _run
    self._receive()
  File "/usr/local/lib/python3.8/site-packages/opcua/client/ua_client.py", line 121, in _receive
    self._call_callback(0, ua.UaStatusCodeError(msg.Error.value))
  File "/usr/local/lib/python3.8/site-packages/opcua/client/ua_client.py", line 129, in _call_callback
    raise ua.UaError(
opcua.ua.uaerrors._base.UaError: No future object found for request: 0, callbacks in list are dict_keys([2])

evening,

error message makes me think the target is rejecting your connection request.

what is the endpoint target url? does it require security/encryption?

have you connected to this device using regular opcua clients? if so what are the settings in such clients?

Hello,

I use UaExpert client to test the communication with a Wago PFC100 and all is good.

On this WAGO, I need to configure the OPC UA Endpoint with Security Policy - None, and unlimited anonymous acccess. And now I havenā€™t HA crash.
I will increase security little by littleā€¦

By the way, what is the syntax to define login/password in configuration.yaml file ?

And how to change the refresh rate?

so two things.

  1. I havenā€™t implement any automatic client certificate generation. So that will be step one.

each certificate has a specific Uri, so both need to be listed in the yaml.

below is an example of mine connecting to a freeopcua server I have running in docker. I borrowed the client certificate from the freeopcua GitHub examples found on GitHub. I then copied those files into my ssl directory and listed them as per below.

FreeOpcUA GitHub example files

opcua:
  - name: target1
    url: "opc.tcp://192.168.50.113:4840/"
    session_timeout: 600000
    secure_timeout: 600000

  - name: target2
    url: "opc.tcp://192.168.50.113:4840/"
    application_uri: "urn:example.org:FreeOpcUa:python-opcua"
    session_timeout: 600000
    secure_timeout: 600000
    security_string: "Basic256Sha256,SignAndEncrypt,/ssl/certificate-example.der,/ssl/private-key-example.pem"
  1. Iā€™m not familiar with Wago, or what youā€™ll need to do to get that opc ua server to trust your clients certificate. hopefully they have good documentation.

  2. is your Wago also using user rights access as well? you can add the following to your yaml

username: ####
password: ####
  1. refresh is fixed at the moment. but can be something we look at making variable. I believe it is 30 seconds default. what kind of rates are you looking for?

Also out of curiosity, what are you looking to achieve with the opcua add-on?

that is a slick piece of industrial automation, I see it supports modbus TCP, which is baked into home assistant by default and may be more stable. though less secure.

I have opened an issue in github for this. I wanted to keep track on things for the project.

did this error prevent HA from loading?

With OPC UA, I looking to replace ModbusTCP with the WAGO PLC.
This equipment is great with CodeSys to acquire and control the actuators of my house.

The HA Modbus TCP extension is not fully finalized, especially with regard to reading multiple float register.

YEs, this error prevent the loading of HA.
We can continue this discussion about this issue on GITHUB.

This is correct, I simply add this two line in configuration.yaml and I have a beginning of security element.

opcua:
  - name: WAGO_OPC_UA
    url: "opc.tcp://192.168.0.21:4840/"
    username: !secret WAGO_OPC_UA_user
    password: !secret WAGO_OPC_UA_password

I now check the client certificateā€¦

  1. refresh is fixed at the moment. but can be something we look at making variable. I believe it is 30 seconds default. what kind of rates are you looking for?

A variable would be a good thing. From 1second to 1 hour.

I will look into the scan interval settings. basic searching so far implies it should be relatively easy to implement.

in the mean time you can try this work around for faster scan intervals.

https://community.home-assistant.io/t/dynamically-varying-sensor-scan-interval/159233/4

Thank you !

A simple scan_interval: 10 in the sensors.yaml file

- platform: opcua
  scan_interval: 10
  nodes:
    - name: Sensor1
      hub: WAGO_OPC_UA
      nodeid: "ns=4;s=|var|WAGO 750-8101 PFC100 2ETH.Application.Publish_NativeMQTT.dwMyCounter"
      unit_of_measurement: degrees