I implemented my home automation with a Beckhoff PLC. Now I am ready to ‘move one step up’, getting HA to link the Beckhoff PLC and integrate it with other devices in our home (e.g. Denon AVR, Philips Android TV).
I recently bought a QNAP TS-453D NAS. I installed docker and created a HA container. HA is running on my QNAP and it automatically detected my Denon AVR, which I can control from the dashboard (on/off, volume). Very nice as a starter!
Looking for information on how to hook up my Beckhoff PLC to HA, I find some posts but up to now no information how to set up the connection from scratch in a step by step way. Could someone help me out here?
I never used a PLC with HA. But what about modbus or maybe mqtt. Just used mqtt with plc from Schneider electric which is based on codesys too. Maybe beckhoff also supports an integration through mqtt.
Thank you for the suggestion Patrick. I will have a look at it.
I have a Beckhoff CX-8190 PLC. Out of the box, it supports real-time Ethernet, ADS UDP, ADS TCP, EAP (EtherCAT Automation Protocol) on it’s Ethernet ports. Probably the PLC, which is running Windows 7 Embedded, supports modbus TCP by installing a licensed software (TF6250?). However I would have to pay for this, whereas ADS is supported by default and HA has an integration for it. So the latter would still be my preferred method. On top of that, some of the posts in this forum indicate that people have been able to link a Beckhoff PLC to HA.
In the meantime, I have done some further research and trials.
As a reminder : I run HA on a QNAP NAS TS-453D, under a docker container.The PLC is a CX-8190 running Windows Embedded 7. I use Twincat 3.
My configuration.yaml file currently looks like this…
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Example configuration.yaml entry
ads:
device: 'x.x.x.x.1.1'
port: 851
ip_address: 192.168.xx.xx
# Example configuration.yaml entry
switch:
- platform: ads
adsvar: GBL.MAIN.dkZITR_3_6
name: 'Drukknop'
# Example configuration.yaml entry
sensor:
- platform: ads
adsvar: 'GBL.H3C.HomeAutomation.Constants.LED_DIM_MIN'
unit_of_measurement: 'Level'
adstype: uint
name: 'DimLevel'
The ‘device’ tag is set to the ams-id that can be found in the Twincat programming environment, as is the IP address, which is fixed by the way. The PLC port is set to ‘851’ by default (so not ‘801’).
I also found out that HA needs pyADS installed in order to be able to communicate with a plc. I opened a console terminal and launched the command ‘pip install pyads’ which returned a message that the package was already installed. Great (I think)!
The HA user interface starts without reporting any visible error. The entities that are defined in the configuration file appear in the entities list, but with the indication ‘unavailable’. So, I guess no communication is established with the PLC, or the adsvar names are not formatted as it should, or I am trying to address variables that are not reachable by ADS.
I also logged in to the PLC via my PC and opened the ‘static routes’ dialog. I let the PLC do a search for ADS compliant devices on my network. It only found the PC from which I am developing. Does this mean that the HA instance on QNAP is not responding to ADS traffic? Or is this normal? Is pyADS service running, even if it is installed on HA? Can I check this in some way?
Some questions concerning the adsvar parameter :
Is the prefix for TwinCAT3 ‘GBL’ or ‘GVL’?
Do yo need to specify the whole variable path or just the variable name?
Can you reach any variable defined in the PLC or do you need to define variables in a special way in the PLC environment in order to be exposed to ADS?
Sometimes string type variable are surrounded by quotes and sometimes not (e.g. device parameter is specified between quotes, adsvar typically not (in my configuration file, I tried both as a test by the way)
Can anyone elaborate on this and point me in the right direction please?
Judging by the comments in post one I’m assuming you’re dutch
I haven’t got a clue regarding the errors you see but I got my setup (though TwinCAT 2) connected yesterday. First it wasn’t working, but something from work reminded me of what might be the cause and in my case it seemed to help. At work we use ProFace HMI’s which use a TwinCAT .tpy file to know where the variables are in memory. But the PLC only allows for ads connections from a device to which it has a route.
Connect to your plc using TwinCAT and add a route to your hassio server. In my case it was a raspberry pi. Since the pi isn’t running an AMS router, the remote must be set to “None” instead of static/temporary.
In Dutch:
Op men werk gebruiken we proface schermen. Die gebruiken een gecompileerde TwinCAT file om te weten waar de data zit, maar de plc staat enkel ads read/write to van een toestel waarmee die een route heeft. Die route hadden wij eerst niet en we kregen als gevolg daarvan foutmeldingen. Zo’n proface, en in hassio geval bv. een raspberry pi heeft geen ams router aan boord. Daarom moet je vanop je plc een route leggen naar het toestel. AMS NetId = IP-address.1.1, remote target “None”
Thank you for adding the missing piece for my setup to work. Hope this will reach the docs
In case others are not as familiar with how to add the route, this is done via the “Routes” section on the “System” level (Beckhoff Information System - English)
Hi Sébastien,
I’ll look into this later tonight. But I assume that ams IP is a typo since it’s normally ams (net) ID.
Can you copy-paste the yaml content using code tags? That way the formatting etc remains.
Example tags
Is the DK1 in a global variable list?
Also note that the default port for TC2 is 801 while gor TC3 it’s 851.
You can also pm me if you like the conversation to happen in Dutch. In that case I’ll update the thread if new know-how comes to light
DK1 is idd a global variable list with the name Gelijkvloers. But even Gelijkvloers.DK1 doesn’t work.
I use twincat2 so port 801 is correct.
Thx for the help!
At this moment I can toggle a switch to turn on/off the light but the status off the toggle switch is always off.
The real status of the light is in another entity ( light) .
Is there a way to combine the status and the toggle of the light in one entity ?
You could try a template light as a workaround. Show the template light in your frontend: it will switch the switch and use the light state behind the scenes.
After several tests, I still don’t manage to establish communication between HA (running on RPI3+) and my Beckhoff CX-9020.
First important question, I installed the image ‘Home Assistant Operating System’
Somebody has communication working started from this package ?
Second question, it seems after latest python update 3.10 the ADS support is broken ?
I see people telling 'downgrade python to version 3.9, can you do this from the HA web interface ?
Im make some time ago tutorial about TwinCat3 with HomeAssistant - Its in Polish but there is step by step showing how to do it - could be useful for someone
I spent some time figuring out why my ADS link wouldn’t work.
Turns out I forgot to open the firewall ports required for the ADS communication.
You need to allow access on ports in the Windows Defender Firewall with Advanced features:
Discovery: 48899 / udp (also outgoing)
Not secured: 48898 / tcp (also outgoing)
Secure ADS: 8016 / tcp (also outgoing)
Normally the firewall is configured by Beckhoff’s installation on the IPC, but as I am running the TwinCAT locally on my workstation, the ports weren’t configured yet.