Wago PLC with modbus

  • Platform information: Raspberry Pi 4
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

Hello everybody. This is my first post here. I have just installed Openhab recently, because I choose it to run visual in terface for my home automation system which is based on wago PFC200 plc.

At the moment I only use paper UI and modbus binding, because I woyld kike to cobtrol my digital outputs by Openhab. It was not a huge hussle to setup working example, but soon I found that not everthing is working as it should.

When I am using only openhab to control digital output everything is correct. Problem starts when I try to change the state of the light by wall switch. I can see that openhab see the change in the logs and item itself (switch change a positon). But when I try to change state afterwards I have to double click on switch. Logs also confirmed that after just one click state of the Item change from off to on and soon after automaticly change from on to off and vice versa. When I change the state ofdigital output by wall switch again everything backs to normal. I run out of ideas what i am missing. Hope you can help me with this.

Welcome!
guess your problem is the item toggles between on and off with each event.
Think profiles should help you:

It might be helpful if we could see that too.

How are your Items configured? Have you looked at other WAGO users posts? I think WAGO usually ends up configured with different status reporting and command actioning registers.

Hi, thanks for the replay. Yesterday I wrote a post from my phone, so. As I said I’m not fluent with Openhab yet. I use only Paper UI for testing purposes. So I have three Things: Modbus Data, Modbus TCP Slave and Modbuss Poller.

Modbus TCP Slave is just for conneciton, so it works perfectly.

I want as many of logic put in may wago plc, so it would be great if Openhab works only as switch changer, at least when we talk about turning on and off the ligths.

I use Wago e-runtime enviroment (eCockpit!), so I’ve created two variables for Modbus communication. One is for read coil and one for write coil, and mapped it to modbus registers at Wago, and this also must work well, because I can change the state of the light.

events.log shows:

2020-10-09 09:13:01.173 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command ON
2020-10-09 09:13:01.227 [vent.ItemStateChangedEvent] - Stan_swiatla changed from OFF to ON
2020-10-09 09:13:01.391 [vent.ItemStateChangedEvent] - Stan_swiatla changed from ON to OFF

above I started with “wrong position” of my wall switch (pulse switch, Plc trigger on/off by detecting risgin edge of the signal). So only way to change state form Openhab was double click on a switch.

Below I pressed a wall switch and the light went on without problem, and Openhab saw this change.

Blockquote

2020-10-09 09:13:15.946 [vent.ItemStateChangedEvent] - Stan_swiatla changed from OFF to ON

Now I could change on and off the light without problem from openhab. The differnce here is that “Item_swiatla” receive command off and on.

Blockquote

2020-10-09 09:13:25.865 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command OFF
2020-10-09 09:13:25.896 [vent.ItemStateChangedEvent] - Stan_swiatla changed from ON to OFF
2020-10-09 09:13:26.691 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command ON
2020-10-09 09:13:26.726 [vent.ItemStateChangedEvent] - Stan_swiatla changed from OFF to ON
2020-10-09 09:13:27.591 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ >received command OFF
2020-10-09 09:13:27.622 [vent.ItemStateChangedEvent] - Stan_swiatla changed >from ON to OFF
2020-10-09 09:13:28.457 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command ON
2020-10-09 09:13:28.489 [vent.ItemStateChangedEvent] - Stan_swiatla changed from OFF to ON
2020-10-09 09:13:29.575 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command OFF
2020-10-09 09:13:29.591 [vent.ItemStateChangedEvent] - Stan_swiatla changed from ON to OFF
2020-10-09 09:13:30.123 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command ON
2020-10-09 09:13:30.140 [vent.ItemStateChangedEvent] - Stan_swiatla changed from OFF to ON
2020-10-09 09:13:41.510 [vent.ItemStateChangedEvent] - Stan_swiatla changed from ON to OFF

When I will use a wall switch again the situation is repeted.
My Item:

sorry for that, but new users can only add one photo per post:

ModbusDATA Thing:

ModbusPoller Thing:

In My wago PLC I detect change of Modbus_OUT varrible which is writable (at 32768 coil) and use internal PLC logic to create puleses that triger digital outputs (lights). Poller reads first coil at 0 modbus address (Modbus_IN variable).

Quite possible, I will check it later. For now I saw that on papaer UI I can only change from default to follow, which is “destroing” the behavior of the switching logic. How can I use: rawbutton-toggle-switch in Paper UI?

Change your Item option “enforce autoupdate”, that is the last thing you want.
As per binding docs, you most likely want to inhibit autoupdate, veto it.

Then show us another events.log and try to explain what happens, and what you would like to happen instead.

Veto auto updates changed only that I do not need quickly double click to change state of the lighit after switching on the wall. So logs looks the same:

here I switched off by openhab:

2020-10-09 11:24:23.299 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command OFF
2020-10-09 11:24:23.401 [vent.ItemStateChangedEvent] - Stan_swiatla changed from ON to OFF

Switched on by OH:

2020-10-09 11:24:23.724 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command ON
2020-10-09 11:24:23.847 [vent.ItemStateChangedEvent] - Stan_swiatla changed from OFF to ON

here I used wall swtich to off (lights went off)

2020-10-09 11:24:37.240 [vent.ItemStateChangedEvent] - Stan_swiatla changed from ON to OFF

here i tried to switch lights to on in OH, but lights stayed off.

2020-10-09 11:25:01.071 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command ON

Another switch in OH changed state of the light to ON (command was off, but soon after OH reads the change of the state in Wago).

2020-10-09 11:25:28.065 [ome.event.ItemCommandEvent] - Item ‘Stan_swiatla’ received command OFF
2020-10-09 11:25:28.165 [vent.ItemStateChangedEvent] - Stan_swiatla changed from OFF to ON

PLC reacts on rising edge of the signal, so I have a script generating pulses when modbus write coli changes state.

Impuls_swiatlo(IN:=xModbus_OUT, PT:=T#200MS);
Impuls_swiatlo_2(IN:=NOT xModbus_OUT, PT:=T#200MS);

Well, openHAB sends 0 for OFF or 1 for ON over Modbus. Your lights want a toggle i.e. a pulse for ON, a pulse for OFF?

You could use a writeTransform on your modbus to send 1 for any command.

Yes, But I already do it in PLC. When modbus receive 1 I generate short pulse, and when it comes 0, I generate another pulse. This works, otherwise it wouldn’t switch lights at all.

No, you don’t, I think. When your WAGO register changes from 0 to 1, you make a pulse. If the WAGO end is 1 and openHAB sends another 1 … nothing happens?

When wago register is 1 and openhab sends 1 nothing happens, but that would mean OH wants to turn the light on when it is already on.

Can you tell me how can I force OH to alwayes generate 1 for any command? That would solve a problem maybe.

Do you think the coil that openHAB sends to actually reflects the on/off state of the light? The actual state is read from a different register.

Yes, use writeTransform and a little javascript that just returns 1. This will not help you unless you change your WAGO script as well.

Yes I know, but if I have read and write in one Item I thought it is connected. Openhab reads the state of the output perfectly from read register which is reflecting state of PLC output. And thought, that when I switch light in the wall, OH will not try to switch it again, when it knows it changed the status.

I don’t know what that means.

If you command your openHAB Item ON, the linked modbus channel will send a 1.
That’s it. It doesn’t matter what state your Item is in, it doesn’t matter what state the target WAGO register is already in.

A UI widget might limit things - a slider for instance cannot be slid to ON to generate a command if already in ON position.

Hi, I think I found a problem in this topic:

There is a chapter: Set coil to true on any command

(inspired by [Modbus] Coil reset only after item update to ON (OFF excepted) #4745 )
Reads from index 0, writes to index 1. All writes (no matter what command) are converted to 1.
Number NumberItem “Number [%.1f]” {modbus="<[slave1:0],>[slave1:1:transformation=ON]"}

I just need to achive this behavior. How to add "transformation=ON". Can you tell me if I can do it in Paper UI or do I have to move everything to files? I will do it anyway, but now I just want to know if this works for me.

That old post is talking about a completely different binding version.

Did already address this

Just put ON or 1 in the writeTransform box of your channel in PaperUI.
I’ve never used it that way, but I think that will work actually having a transformation script.

1 Like