OPC UA smart home integration, free and open source

Read and write the variables of an OPC UA server: PLCs (Siemens, Beckhoff, WAGO), gateways.
Read and write the variables of an OPC UA server from Gladys: PLCs (Siemens S7-1200/1500, Beckhoff TwinCAT, WAGO, B&R, Schneider), gateways (Kepware, Softing, Unified Automation) or any OPC UA server on your network.
Developed without the hardware: feedback welcome. The integration was tested against the Microsoft OPC PLC simulator, not against a real PLC.
What you get
- One Gladys device for the server, one feature per variable you declare: numbers (with their unit), on/off values and texts.
- Values updated by subscription: the server says when a value changes, nothing is polled.
- Writing, off by default: a dashboard switch or setpoint, a configuration button and a scene action write the variables you allowed.
- Three scene triggers (server lost, server back, variable in a bad state) and an OPC UA server dashboard widget.
Requirements
- Gladys 5.1 or later.
- An OPC UA server reachable from Gladys over TCP (
opc.tcp://), with a fixed IP address. On a Siemens S7-1500, turn on the OPC UA server of the CPU in TIA Portal and allow access to the data blocks you want to read.
Configuration
Server
- Enter the server address:
opc.tcp://, the IP address and the port, for exampleopc.tcp://192.168.1.50:4840(4840 by default, 4852 on Beckhoff, 49320 on Kepware). - Choose the security mode, and a user name and password if the server does not accept anonymous access.
- Save, then press Browse the server to list its variables.
Gladys identifies the server by the address and port typed here: changing them creates a new device.
Security and certificate
- None: no signature, no encryption. Fine on an isolated machine network.
- Sign or Sign & Encrypt, with the security policy the server
accepts (Basic256Sha256 is the most common). Gladys creates its own
certificate (
Gladys Assistant OPC UA, stored in the integration's data) on the first connection. Most servers reject an unknown certificate: trust it in the server (TIA Portal: certificate manager, Kepware: OPC UA Configuration Manager, TwinCAT:rejectedfolder moved totrusted), then wait a minute, Gladys tries again by itself. - The server certificate is accepted on first use and kept.
- With the None mode, a password may cross the network in clear text: prefer Sign & Encrypt when the server asks for one.
Variables
The Variables field holds entries separated by semicolons:
Name: NodeId [kind] [write] [options]
Flow: ns=3;s="Boiler"."FlowTemp" temperature; Pump: ns=3;s="Boiler"."Pump" switch; Mode: ns=2;s=Plant.Mode write
- NodeId: copied from Browse the server:
ns=3;s=Text(string),ns=2;i=1002(number),g=(GUID),b=(opaque). The semicolon inside a NodeId is understood. A NodeId stops at the first space, except between double quotes (Siemens names such asns=3;s="DB1"."Temp"work as they are).nsu=NodeIds are not supported. - Name: optional; without it, the variable takes its name on the server.
- Kind (optional):
temperature,humidity,pressure,power,energy,production,solar_power,grid_power,voltage,current,battery,volume,duration,value,binary,switch,setpoint,text. Without a kind: a Boolean is an on/off value, a number a plain value, a string or a date a text.energyandproductionare published in kWh, so Gladys computes the consumption and its cost. - write: the variable may be written from Gladys (see below).
switchandsetpointimply it. - Options:
scale=0.1andoffset=-40(value = raw × scale + offset),unit=kWh,min=andmax=(display bounds),precision=1(decimals).
Up to 100 variables. Arrays and structures are not supported. Check the configuration lists the entries that are wrong or missing on the server.
Writing
Writing is off until you turn on Allow writing. Then:
- a variable declared
switch(Boolean) orsetpoint(temperature) gets a control on the dashboard. They are on/off inputs and water-heater setpoints for Gladys, never switches or thermostats: voice assistants do not drive them; - any variable declared
writecan be written by the Write a value button and the Write an OPC UA variable scene action, by its name or NodeId: numbers (scale and offset reversed, range of the integer type checked), 0/1 or true/false, texts for a String variable.
The server must allow the write too. Writing a wrong variable can stop or
damage an installation: declare write only what Gladys must change.
Actions
- Browse the server: lists up to 60 variables (NodeId, type, access) from the Objects folder, or from the NodeId of a folder given as start node.
- Check the configuration: whether the server is connected, with which security, and the mistakes entry by entry.
- Write a value: writes a value to a declared variable.
Scenes
- The OPC UA server is lost (trigger), with the error as a variable.
- The OPC UA server is back (trigger).
- An OPC UA variable turns bad (trigger): the server reports a bad status (sensor fault, input lost), with the variable name and the status.
- Write an OPC UA variable (action).
The values themselves are features: use the usual "device value" triggers and conditions of Gladys for thresholds.
Dashboard
The OPC UA server widget shows the first six values and the health of the link: connected or not, security, variables in a good state, time of the last value.
Limits
- One server per integration.
- Gladys accepts 300 values a minute: the values are sent every sampling interval, or less often with many variables (100 variables: every 25 s). Only the changes are sent, and an unchanged value every 6 hours.
- The container has no broadcast: no automatic discovery of servers, type the address.
Troubleshooting
- The server does not answer: check the address and the port, and that the PLC accepts connections from the Gladys host (firewall).
- The server refuses the Gladys certificate: trust it in the server, see above.
- The server refuses the user name or password: check them, or the anonymous access setting of the server.
- No endpoint with this security mode: choose the mode and policy listed by the server.
- Detailed logs: set
LOG_LEVEL=debugon the integration.
Credits
Built on node-opcua (MIT) by Etienne Rossignon and contributors. OPC UA is a standard of the OPC Foundation. This integration is not affiliated with the OPC Foundation nor with any PLC manufacturer.
Configuration settings
These are the settings OPC UA asks for in its configuration screen in Gladys.
| Setting | Type | Required | Description |
|---|---|---|---|
| Getting started | section | No | Enter the address of the OPC UA server, save, then use "Browse the server" to find the NodeIds of its variables. Declare the variables you want, save again, and add the server from the Discovery tab: each variable becomes a feature, updated by subscription. |
| Language of the messages | select | No | Used for the texts given to the scenes. |
| Server | section | No | Give the PLC or the gateway a fixed IP address: Gladys identifies the server by its address and port. |
| Server address | string | No | opc.tcp://, the IP address and the port (4840 by default, 4852 on Beckhoff, 49320 on Kepware). |
| Security mode | select | No | With Sign or Sign & Encrypt, the server must trust the Gladys certificate once: see the documentation. |
| Security policy | select | No | Ignored with the None mode. |
| User name | string | No | Empty: anonymous access. |
| Password | secret | No | |
| Variables | section | No | Up to 100 variables. Writing a wrong variable can stop or damage an installation: declare "write" only what Gladys must change. |
| Variables | string | No | Entries separated by semicolons: name: NodeId, then kind, write and options. Kinds: temperature, humidity, pressure, power, energy, production, solar_power, grid_power, voltage, current, battery, volume, duration, value, binary, switch, setpoint, text (default: from the type). Options: scale= offset= unit= min= max= precision=. |
| Sampling interval | select | No | How often the server checks the variables for changes. Gladys accepts 300 values a minute: with many variables, the values are sent less often. |
| Allow writing | boolean | No | Off by default. When on, only the variables declared "write" (or switch, setpoint) can be changed from Gladys, and only if the server allows it. |
How to install OPC UA in Gladys
- In Gladys, open Integrations: OPC UA appears in the catalog, next to the native integrations, with a community badge.
- Click Install. Gladys pulls the Docker image (
ghcr.io/guim31/gladys-opcua:1.0.0), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration). - Open the Configuration screen of the integration, fill in the settings, and save.
- You can also install it directly from its repository URL: https://github.com/guim31/gladys-opcua.
OPC UA requires Gladys >=5.1.0. The catalog inside Gladys refreshes every hour, so a new version becomes available at most one hour after its release.
Not running Gladys yet? It is free and open source: follow the installation guide to get started.
About external integrations
OPC UA is an external integration: a community integration packaged as a Docker container and published on GitHub, that Gladys installs in one click and runs in a sandbox isolated from its core. It is published and maintained by guim31, not by the Gladys core team.
- Browse all integrations, native and community
- Build and publish your own external integration
- Source code on GitHub — source of this documentation