Modbus binding with Wago 750-841

Hello

I’m trying to manage OpenHAB 2.5 operate discrete outputs of Wago 750-841 PLC for home lighting. I made a CodeSys program and configured OpenHAB, and it’s working. However there is small thing which not working correctly:
OpenHAB can switch light on, and reads status correctly if light was ON with a button, but for switching OFF I have to push switch quick twice. If I push “off” once it goes off, but then after 1 second it goes back to On. Can you please help me with that?

Here is my PLC program:

PROGRAM PLC_PRG
VAR
	LIGHT1, LIGHT2  : Fb_LatchingRelay;
END_VAR
VAR_GLOBAL
	EXT_LIGHT1  AT %MX0.0:BOOL;	(*Modbus 12288*)
	EXT_LIGHT1MEM AT %MX0.1:BOOL;	(*Modbus 12289*)
	EXT_LIGHT2  AT %MX0.2:BOOL;	(*Modbus 12290*)
	EXT_LIGHT2MEM  AT %MX0.3:BOOL;	(*Modbus 12291*)
END_VAR

LIGHT1(xSwitch:=BT1 OR EXT_LIGHT1); OU1:=LIGHT1.xActuator; EXT_LIGHT1MEM:=OU1; EXT_LIGHT1:=FALSE;
LIGHT2(xSwitch:=BT2 OR EXT_LIGHT2); OU2:=LIGHT2.xActuator; EXT_LIGHT2MEM:=OU2; EXT_LIGHT2:=FALSE;

Here is my .things file

Bridge modbus:tcp:wago [ host="192.168.1.222", port=502] {
Bridge poller LIGHT1 [ start=12288, length=2, refresh=1000, type="coil" ] {
Thing data ou1 [ readStart="12289", readValueType="bit", writeStart="12288", writeValueType="bit", writeType="coil" ]
}
Bridge poller LIGHT2 [ start=12290, length=2, refresh=1000, type="coil" ] {
Thing data ou2 [ readStart="12291", readValueType="bit" , writeStart="12290", writeValueType="bit", writeType="coil"]
}
}

Here is .items file:

Switch LIGHT1 "LIGHT1" { channel="modbus:data:wago:LIGHT1:ou1:switch" }
Switch LIGHT2 "LIGHT2" { channel="modbus:data:wago:LIGHT2:ou2:switch" }

And .sitemap

sitemap wago label="My first sitemap" {
      Frame label="Light control" {
Switch item=LIGHT1 label="LIGHT1" icon="light"
Switch item=LIGHT2 label="LIGHT2" icon="light"
}

Thanks in advance!
Happy New Year!

Hi

Have a look at docs regarding autoupdate: https://www.openhab.org/addons/bindings/modbus/#autoupdate-parameter-with-items

And see if this something what you are experiencing

Best
Sami

Hi Sami

With autoupdate=“false” switches acts same but little different. Switch goes to OFF, but light remain ON. But second click to switch turns OFF light. The problem is that states only changes when trigger goes from OFF to ON, but when it goes from ON to OFF nothing happens.

Anton

Here is what happens in log when I’m pushing switch once
11:40:42.309 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘LIGHT2’ received command OFF
11:40:42.310 [INFO ] [smarthome.event.ItemStateChangedEvent] - LIGHT2 changed from ON to OFF
11:40:42.991 [INFO ] [smarthome.event.ItemStateChangedEvent] - LIGHT2 changed from OFF to ON

Continuing the discussion from Modbus binding with Wago 750-841:

Hi all,

i am using Wago PLC 750-8207 …and i want to turn on my physical output from plc , i used the Modbus address 512 for but i am unable to write and read it.

please help me out and please tell me what will be modbus adress for %QX0.0, and %IX0.0

Thanks.

With autoupdate=false the item state in openhab
always matches what has been polled from modbus.

If the lights are not working as you expect, then perhaps you would need help to debug the wago plc code.

Just taking a wild guess: Are you sure all the data is served as modbus coils?

Btw, if you enable verbose logging, you can see exactly what is received from the plc.

Dear Sami

Thanks, the problem was in PLC program not an OpenHAB. I’ve changed a code a little and now OH operates PLC correctly.

Anton, what have you changed in your PLC code?

My mistake was using button and variable in same place. Button is impulse signal 1 then 0, variable is constant. So only thing to do was intermediate variable. So I made a trigger. I’m using 1 modbus address per 1 light.

I’ve changed variables names since first time, here is a code:


TRG1A:=(EXTOUT_1A_R1 AND NOT OUT_1A_R1) OR (OUT_1A_R1 AND NOT EXTOUT_1A_R1);
LIGHT1A(xSwitch:=INP1A OR TRG1A, xCentOFF:=masterOFF, xCentOn:=masterON); OUT_1A_R1:=LIGHT1A.xActuator; EXTOUT_1A_R1:=OUT_1A_R1;

VAR
	LIGHT1A: Fb_LatchingRelay;
        TRG1A: BOOL;


Global variables:
	EXTOUT_1A_R1	AT %MX0.0:BOOL;	(*Modbusadresse 12288*)

i’m using Building_common.lib btw in Codesys.

1 Like

ok thanks, now it is clear