OPC UA Interface to HA

Hi all,

out of curiosity (wanting understand OPC UA a little better), I started building a small bridge to expose HA contents via OPC UA. I used a Python OPC UA implementation (https://github.com/FreeOpcUa/python-opcua) and am finally able to browse nodes and their current state via a OPC UA client, see the screenshot.

My initial status could probably be enhanced to allow interaction with HA (e.g. propagating values written to OPC UA nodes), expose events when entity values change or expose services as OPC UA methods.

However, beyond the feasibility of all this, I have no real application in mind so far. Any ideas where this might be useful ?

Regards,
Lars

P.S. For the curious, I have uploaded my current attempt to https://github.com/LarsAC/ha2ua if you want to take a look. The code is not really polished, so beware.

1 Like

Hi
I got a syntax error in line 9 in the server.py:
"import homeassistant.remote as remote
ModuleNotFoundError: No module named ‘homeassistant’

My config is: Home Assistant 0.65.3 running on a PI3

thx in adv

I want to try ! Seems interesting :wink:
Can you create an addon for testing purposes!

Will add more documentation how to make it work over the next couple of days. Roughly you need a venv with the hass python bindings and the free OPC UA stuff mentioned in my first post.

Lars

1 Like

Yes! I worked using OPC UA :slight_smile: no problem
But, it’s interesting if you create a https://www.home-assistant.io/developers/hassio/addon_tutorial/

Another point it’s create a OPC UA client for use inside hass: https://www.home-assistant.io/developers/creating_components/
We can connect to a OPC TAG for a temperature sensor, or switch, or… similar to modbus component: https://www.home-assistant.io/components/modbus/

This is the inspiration :smile:

Regards,

@LarsAC What do you think of my proposals?

  • Hassio Addon for OPC UA Bridge. Use HA from other OPC Client.
  • OPC UA component for access to sensors, tags, …

Regards,

Hi,

Thanks for your ideas. While the addon to hass.io makes perfect sense, I am not using hass.io, so I have little motivation for developing.

For the component with an OPC UA sensor: while this would be probably easy, what kind of OPC server would you like to talk to?

Lars

OPC UA server. I test using Matrikon or Kepware.

1 Like

Yes, but what sensors do you have available via those ?

Lars

valves and temperature

Interested if there was any progress creating a OPCUA add-on for HassIO?
I would like to do some monitoring and control of a swimming pool using a B&R PLC for local control and use OPCUA to communicate with the HA system. I have several spare PLC’s to use and OPCUA can be easily enabled in the PLC, we have tested the communication using a POC running Python and have that working (IOT project for work).

  • Solar valve bypass valve open/closed
  • Water temp into solar heater
  • Water temp out of solar heat
  • Pool pump on/off cycle control
  • Water pressure into filter
  • Water pressure out of filter

I’m very interested too in the progress or is there a different integration for OPC-UA? I too am looking to expose the home assistant sensors to a B&R PLC…

1 Like

I am working on an opcua component. very beta at this point but stable.

I’ll make a repository on GitHub and link it within a few days

cool minix1234, looking forward to a opcua HA component.
In past I used FHEM which had a modbus slave component so you could “map” FHEM’s sensors to modbus registers (read/write) so I could make a HMI on an industrial SCADA system.
If there was a OPCUA component which could “map” HA tags/sensors/input_…" with read/write access, this would be a great solution also to link as HMI.

that I believe would be closer to the OPs original intent.

I’m looking to gather some data for logging, graphing and programmatic other uses from several systems.

I will create a GitHub repo soon. just reviewing the sync vs async component setup requirements.

I based the component off of the modbus component and they are using thread locks while I have not. I just want to make sure it won’t cause stability issues.

(I program for fun and as required for work/ work around but it is not my formal training)

I guess you need to install opcua with : pip install opcua ?

If I do that on my Hassio Home Assistant I get :

➜ ~ pip install opcua
Collecting opcua
Using cached opcua-0.98.12.tar.gz (571 kB)
Requirement already satisfied: python-dateutil in /usr/lib/python3.8/site-packages (from opcua) (2.8.1)
Requirement already satisfied: pytz in /usr/lib/python3.8/site-packages (from opcua) (2020.4)
Collecting lxml
Using cached lxml-4.6.2.tar.gz (3.2 MB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/tmp/pip-install-lwedsz99/lxml/setup.py’"’"’; file=’"’"’/tmp/pip-install-lwedsz99/lxml/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ egg_info --egg-base /tmp/pip-pip-egg-info-zlixhpse
cwd: /tmp/pip-install-lwedsz99/lxml/
Complete output (3 lines):
Building lxml version 4.6.2.
Building without Cython.
Error: Please make sure the libxml2 and libxslt development packages are installed.
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I can’t seem to install lxml ?

I now remember back why I did not tried https://github.com/LarsAC/ha2ua any further.
It didn’t work on Home Assistant’s shell/Linux. (direct install on Home Assistant OS installation Type)

I went on using NodeRed instead where NodeRed would be a simulated Modbus Slave with Modbusregisters filled with data from HA.

Does anyone have a step-by-step solution how to install opcua ( https://github.com/FreeOpcUa/python-opcua) succesfully on HA ? Or does your opcua addon does not require this ?

it will require it.

I am using a devcontainer on windows with Linux subsystem/docker and was able to install.

initial test on my RPI 3/hassio also works.

which flavor of Linux are you using?

have you tried installing those suggested development packages?

libxml2-devel
libxslt-dev

I’m using a hassio image (vm) running on Proxmox on a NUC.
Linux version 5.4.84

I installed this following Drzzs & Wiskerz007 script, see https://www.youtube.com/watch?v=JAHKftNVTco
install script here : https://github.com/whiskerz007/proxmox_hassos_install

I think it installs HASSOS (own HA OS), maybe this Linux can not be expanded ? (aside from the HA shared Config folder) ?

I cannot manually install libxml2-devel :

➜ ~ sudo pip install libxml2-devel or libxslt-dev
ERROR: Could not find a version that satisfies the requirement libxml2-devel (from versions: none)
ERROR: No matching distribution found for libxml2-devel

or is there a different way of installing these ? (apt-get install does not work also).

Maybe it’s possible to install an extra docker container of your software ? I installed Portainer also on this HASOSS. Some HA Addons also install docker containers.

Im not sure, but i think you are trying to install the python library in the HASSIO supervisor and not the homeassistant image

you can use portainer to open a console in the “homeassistant” container. or am I totally missing the idea of how you have home assistant installed?


Here is my Portainer view :

It is installed on Proxmox, I don’t have the same view as you.
Only have 1 running container.
All addons & homeassistant parts are “images” which have a state “Unused” which is not true.

I’ll try your approach of running install opcua in homeassistant container