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

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?

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.
image_2021-02-13_085157

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,

Bart

2 Likes

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)

Hi Bart,

I added the route as you mentioned.
My configuration in the .yaml file looks like this

ams ip : ‘5.4.243.48.1.1’

ads:
device: ‘192.168.2.36.1.1’
port: 801
ip_address: 192.168.2.36

#ADS config
switch:

  • platform: ads
    adsvar: .DK1
    name: ‘Drukknop Toilet’

But I get the following error in the logs :

Do you have any idea?

Kind Regards,
Sébastien

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 :slightly_smiling_face:

1 Like

Hi Bart,
Unfortunately I can’t PM you directly it would be easier … ( also in dutch :slight_smile: )

Here is my Yaml config file:

image

ads:
  device: '5.4.243.48.1.1'
  port: 801
  ip_address: 192.168.2.36
  
#ADS config
switch:
  - platform: ads
    adsvar: .DK1
    name: 'Drukknop Toilet'

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!

Hi Bart,

The communication part is working now!

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 ?

Many thanks,
Sébastien

Sébastien,

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.

light:
  - platform: template
    lights:
      bureau_light_template:
        friendly_name: "Bureau Light"
        value_template: >-
          {% if is_state('light.bureau_light', 'on') %}
            on
          {% else %}
            off
          {% endif %}
        turn_on:
          service: switch.turn_on
          entity_id: switch.bureau_light
        turn_off:
          service: switch.turn_off
          entity_id: switch.bureau_light
      wc_light_template:
        friendly_name: "WC Light"
        value_template: >-
          {% if is_state('light.wc_light', 'on') %}
            on
          {% else %}
            off
          {% endif %}
        turn_on:
          service: switch.turn_on
          entity_id: switch.wc_light
        turn_off:
          service: switch.turn_off
          entity_id: switch.wc_light

Regards,
Hannes

1 Like

Hello,

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 ?

Thanks for you feedback

Hello,

Any news on this one. I’m struggling to get the ADS working. So I’m thinking which python versio n is working.

Im make some time ago tutorial about TwinCat3 with HomeAssistant - Its in Polish but there is step by step showing how to do it :slight_smile: - could be useful for someone :slight_smile: