Looking for experiences with modbus/plc and HASS

Hi All,

Now that I have bitten by the HA bug, I am looking at ways to automate more things in my house. But, I prefer wired over wireless where possible. And I am looking into using a Railduino PLC to connect over ethernet to HASS using modbus (over ethernet).

I do not have this setup yet, but am asking because I am researching what I am getting myself into if I do :slight_smile:

The main thing I want to know now is this: I am replacing several toggle wallswitches to momentary switched. If those are connected to a PLC (railduino) input, who does the polling to see the state change or the momentary button? Is that somethings that is handled in the PLC, and gets send as a message/event to HASS. Or does HASS need to continuously poll the PLC (say at 10Hz to “catch” a 100+ms button press)?

Anyone with PLC+HASS experience that cares to share some knowledge and experience?


I have my home automated with PLC and started to add HASS a few weeks ago. Here is what works so far:

  • Read binary coils (status of light or on off).
  • Read word register (temperature of rooms)
  • Write binary coils (turning light on or off)

What does not work yet:

  • Write word register (e.g. to set a dimm value for light)

There are various posts about this last issue around here but no one seems to care to answer them. Maybe I will have to dig deeper into Hass/Python myself and will try to implement that.

Maybe my answer doesn’t help you much but at least you know now that you are not the only MODBUS user out there. :slight_smile:

ha, thanks @arnadan, I am not yet using a modbus plc, but I am considering it, since I prefer wired over wireless for my “smart home” stuff. What plc are you using?

Thanks for sharing your experiences though. Do you know/feel reading coils is fast enough to detect pressing of a momentary switch? It will take, say, 100ms or so, so the coil should be read with a frequency of at least 10Hz.

I am using a Wago PLC programmed with CoDeSys.

All my switches are read by the PLC which is fast enough for that. The PLC then turns on/off lights and keeps the status of those lights in coils. HASS then only reads or sets those status coils. So I don’t have to detect any short signals directly from HASS.

Hi Arnadan,

Would you mind posting your modbus config?

  type: tcp
  host: <my IP address>
  port: 502

# switches
  platform: modbus
  - name: Licht Buero
    coil: 12288
# sensors
  - platform: modbus
    - name: T Aussen
      unit_of_measurement: °C
      register: 12297
      count: 1
      scale: 0.1


I have a Wago PLC also.
For me the PLC is always the “boss”. So all switches and commands are on his control.
HASS is only used to bypass the controls. As such I am always sure that my automation is working even when my HASS is down.

It took me a while to get it configured as I am not a modbus expert. But I found quite some weird things with the implementation in HASS…Not sure however if this is due to the python script or a different “implementation of the modbus protocal of wago”. However this link may help you to get past some strange behaviours : Modbus sensor

As far as I understood the python script controlling hass has also recently be changed…I had no time yet to install the newest version of hass 46.1 (Switch pymodbus to pypi (@andrey-git - #7677) (modbus docs))

Hope this will “revamp” the modbus discussion in HASS.



Hi @hschroyen,

I own Wago PLC and ambitous plans to base whole home automation system on it - as a Boss, 3km of SFTP :slight_smile: . I am wondering about using Home Assistant as a visualisation tool for the whole (complicated) system… It seems you already have tried that!

Please correct me if I am wrong, but need to ask here…
To make it works the way ‘only bypassing’ data from PLC to HASS, I have to map all needed registers in .yaml file, implement constant-perioding polling their state with python script and then construct the visualisation based on that data ?


For complex tasks you need to slice the elephant in slices :slight_smile:
So in my case I communicate with the PLC via modbus.

For this you have 3 parts :

1 the modbus configuration


type: tcp
port: 502

2 the switch :
I make always sure that the plc can do his work even when hass is down.
So my coil -() is always controlled by the plc. With the switches from hass I am controlling the coils as “permanent on” or “permanent off” in which I put additional -||- registers. so for each coil I have a switch permanent on and permanent off.
All switches are controlled by the hass config :


platform: modbus

  • name: Licht Buero
    coil: 12288

3 the sensors.

And yes for the sensors I had to write the python script. However it was never clear to me if this was due to a bug or due to a strange modbus implementation of the modbus protocal by WAGO. At a certain moment I had something working but I saw that the adresses of the registers moved each time I restarted the PLC or the HASS installation. I did not spend more time to investigate after I had my python solution. At a certain moment somebody wrote to me that he found an error in the HASS implementation but I did not have the time to try it.

Hope this helps a bit.

Do keep me informed…always interested in wago plc’s :slight_smile:



1 Like

Hi @arnadan

Does this mean it doesn’t work with HASS at all, or haven’t you got it working yet?

I have a Carlo Gavazzi smart-house system installed in my home (SH2WEB), wich can be accessed with modbus tcp. It automates everything (lights, ventialtion, temperature, alarms etc) like a PLC would in your case, and also have all functions readable/writable via modbus. But I need to write to holding registers to set parameters or control the functions.

If this works with HASS I am going to try it out and compare with Openhab wich I use today to create some automations on top of smart-house (like weather, sonos, network devices etc).

Openhab has no problem to poll and use the 220 modbus-registers it reads/writes to today. Is HASS capable of this or not?

Meanwhile I think I figured out how it works: one can use the Modbus.write_register service. But I didn’t have the time to test it yet .

Someone made progress on this?

I also own a Wago PLC, but i have it configured to send MQTT to HASS.
This means that everything stops working when HASS is down.

I tried programming the PLC (Wago 750-881) to do the automation, but in the config it can only be the PLC that controls the outputs OR modbus.


I am running this setup with Wago PLC now for 2 year…so nothing to progress I think.
It is true that only the PLC or the modbus can control the coil. However that is not a problem if you configure the PLC as below

|-|--------------------------() Lamp


modbus register

I hope it is a bit clear

If not feel free to contact me on email



I’m strugling with the configuration of my Wago PLC. I want to configure my Wago PLC to be controlled by PLC but I want to control coils from HASS as well.

I’m not an expert in PLC so I didn’t get your solution. So from what you are saying is that it is possible to run a PLC program and use modbus as well to control registers?

If it’s possible to you to make it bit more clear I would glad.

Thank you very much

Hi, I have a PLC that is controlling all the lights and heating in my house. I have now added HASS on top of this and it is possible to control things from either PLC or from HASS. I am not using a Wago PLC but a SIEMENS S7 300 so I guess it is a bit different from your setups… The PLC is not programmed using ladder but instead a language called STL which is basically assembly language. But the principle should be the same I think. my light switches are connected to digital inputs on my PLC, they are momentary so that when I press one of them I get a pulse in the PLC which I use to toggle the light on and off. I now added a signal from HASS (using modbus) and in the PLC I am triggering the same light toggle by looking for rising edge of that signal. I also send the status of the light back to HASS on the same modbus address.

1 Like

Wow, thought the post was 13 days old… Anyway - here’s an example

I’m new to HASS but have been programming Wago PLC for some time. Which PLC/ version of CoDeSys are you using?

Wago PLC-program:
To answer your question, let’s say you publish a 16-bit (or several) register on Modbus.
You also have an internal array of bits that is already controlling the outputs in your PLC.

Make a ST-function with two inputs, one 16-bit (DWORD) and one array of bool [0…15] <= 16bit size, make 16 BOOLEAN outputs.

Write the ST code like this:
// Define inputs
modbusReg : WORD;
localReg : ARRAY[0…15] OF BOOL;
out1: BOOL;

out 16: BOOL;
// Define local variables
i : INT;
tmpModbusReg: ARRAY [0…15] OF BOOL;
tmpOutputs : ARRAY [0…15] OF BOOL;
// Code
// Convert DWORD/DINT from Modbus to BOOLEANS
X:= modbusReg,
B00=> tmpModbusReg[0],

B31=> tmpModbusReg[15]);

// Loop through inputs both from Modbus and local
FOR i := 0 TO 15BY 1 DO
 IF tmpModbusReg[i] = 1 OR localReg[i] = 1
 tmpOutputs[i] := 1;

// Copy array to outputs
out1 := tmpOutpus[0];
out16 := tmpOutpus[15];

HASS-experts must correct me if it is not possible to send/ convert BOOLEANS to a WORD and send as a register on Modbus.

See also this project. It’s a simple and cheap arduino modbus rtu client. I made it for home assistant to control lights, loads, temperatures


I need some help to integrate my s7 300 PLC into HA. in the PLC I have all the lights and blinds of my house and some sensor, since Node Red i have managed to communicate and manage the outputs of the PLC but I can not add to HA a switch to control it. I have configured modbus but I can not get anything to appear in HA.

Under what condition did you set the coil number?

Hi @Per_Manholm
Im like you have a Carlo Gavazzi smart-house system installed in my house with a SH2web.
I have just started with hassio and would love to use hassio over the SHtool.
I find the SHTool not that user friendly and have some trouble with kalenderfunktionen.

Im curious did you mange to get it working?

Br Martin