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

Tags: #<Tag:0x00007f7394add400>

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:

Hello,

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?

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) [homeassistant.components.ads] 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) [homeassistant.components.ads] Error subscribing to GBL.MAIN.LED_DIM_MIN: ADSError: timeout elapsed (1861).

Does anyone have a clue what is happening?