How To : set up HA to communicate with Beckhoff PLC using ADS

Tags: #<Tag:0x00007fc4168c1a40>

Hi there,

I am completely new to home assistant.

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?

Thank you in advance!

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.

Hey that sounds cool. Didn’t know about that :wink:


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)

# Text to speech
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Example configuration.yaml entry
  device: 'x.x.x.x.1.1'
  port: 851
  ip_address: 192.168.xx.xx
# Example configuration.yaml entry
  - platform: ads
    adsvar: GBL.MAIN.dkZITR_3_6
    name: 'Drukknop'

# Example configuration.yaml entry
  - 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?

Hi there,

Still struggling in getting HA connected to the PLC.

In the log window I see th following messages appear when starting the HA container in docker

[services.d] starting services                                                                                                                           
[services.d] done.                                                                                                                                       
2020-10-14T17:58:32+0200 Info: Connected to 192.168.xx.xx                                                                                                
2020-10-14T17:58:32+0200 Error: something strange happen while waiting for socket in state: -1 with error: Interrupted system call                       
2020-10-14 17:58:37 ERROR (SyncWorker_4) [] Error subscribing to GBL.MAIN.dkZITR_3_6: ADSError: timeout elapsed (1861).      
2020-10-14 17:58:42 WARNING (MainThread) [homeassistant.components.switch] Setup of switch platform ads is taking over 10 seconds.                       
2020-10-14 17:58:42 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform ads is taking over 10 seconds.                       
2020-10-14 17:58:42 ERROR (SyncWorker_3) [] Error subscribing to GBL.MAIN.LED_DIM_MIN: ADSError: timeout elapsed (1861).

Does anyone have a clue what is happening?

Hi Rudy,

Judging by the comments in post one I’m assuming you’re dutch :slight_smile:

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”

Hopelijk ben je hiermee gesteld :wink:
Hope it helps!

Kind regards,


1 Like

Thank you for adding the missing piece for my setup to work. Hope this will reach the docs :+1:

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)