[Solved] ModBus and cheap 4 relay module (D18994)

Hello !

I have a cheap relays module with ModBus support integrated. I`ve tested it with my debug scripts and it works well. Here is my short manual about it: link (russian lang). Relays on this card could not be accessed as coils and another scheme used instead.
For example if i need to enable relay number 2 i should write value 0x0200 to holding register 2, and i should write 0x0100 if it need to be changed back to open state.
My question is: how to use such kind of control scheme as reular Switch item if it is possible? I have a led lamp connected to such board and i need to enable and disable it with some schedule or manually.
Thanks!

I think you can use the newly updated Modbus binding version

A trsnsformation of Openhab Switch Item ON/OFF to Modbus holding register number values should be possible.

2 Likes

I`m not experienced with modbus and OH at a moment :frowning: but i will try to understand how to use it. I will post results there.
Thanks again for your response !

Seems i not enough experienced yet (in OH configuration mostly) to understand how to bind different modbus commands (and may be check its state) for Switch item. Ive trying to build vegitables micro-farm in own room and this relay module should be used for activation/deactivation of light and water pump. It was mounted before i`ve found OH.

Thanks to @rossko57 for help again!

It works!
Here is example that switching On/Off relay 2 on such board:

Board definition as modbus device. (Note that register numbers on such devices starting from 1, not from 0. eg 1-4) :

serial.slave2.connection=/dev/ttyAMA0:9600:8:none:1:rtu:35:1500:none:none
serial.slave2.id=1
serial.slave2.start=1
serial.slave2.length=4
serial.slave2.type=holding

Item definition:

Switch Light  "Main Light" (ALL)   {modbus=">[slave2:1:trigger=ON,transformation=256],>[slave2:1:trigger=OFF,transformation=512]"}

This line will write to holding register 2 (with index 1 in my modbus definition) on device slave2 numerical values 256 (0x0100) to switch relay to Closed state and 512 (0x0200) backwise as described in device documentation.

Note, that you should upgrade modbus binding in order to enable transformation functionality.

2 Likes

Great to hear the new binding works for you!

Best
Sami

1 Like

Thank you very much for great job!

Regards,
Oleg

Hi all,

I have the same relay board. I want to controll my roller shutter with it. In my Installation I would like to have 2 relays to control 1 roller shutter. So one is for up and one for down. So I could define 2 relays like that:

Switch Light “Roller1 up” (ALL) {modbus=">[slave2:0:trigger=ON,transformation=256],>[slave2:0:trigger=OFF,transformation=512]"}
Switch Light “Roller1 down” (ALL) {modbus=">[slave2:1:trigger=ON,transformation=256],>[slave2:1:trigger=OFF,transformation=512]"}

Is it also possible to unify both relays into 1 item/switch? So that I have UP, DOWN and STOP as triggers?

Something like that:
Switch Light “Roller1” (ALL) { … }

  • STOP sends 512 to both holding registers
  • UP sends 256 to the first and 512 to the second register
  • DOWN sends 512 to the first and 256 to the second register

Thanks for supporting me

Hi

I think it should be possible, just add more entries like >[…] with same trigger.

Best
Sami

Would this be possible?

Switch Light “Roller1” (ALL)
{modbus=">[slave2:0:trigger=UP,transformation=256],>[slave2:0:trigger=STOP,transformation=512],>[slave2:0:trigger=DOWN,transformation=512],>[slave2:1:trigger=UP,transformation=512],>[slave2:1:trigger=STOP,transformation=512],>[slave2:1:trigger=DOWN,transformation=256]"}

Looks good to me. Let me know if it does not work.

Best
Sami

Hi thanks for the support.

I have a stupid question.

If I have my item defined as follows:
Switch Relay1 “Relay1” (ALL) {modbus=“slave1:1”}
and the modbus (sniffed on bus) has the expected telegram.

But for the relay card I need to have a transformation from 1 to 0100 and from 0 to 0200. Therefore I added the following:

Switch Relay1 “Relay1” (ALL) {modbus=">[slave1:1:trigger=*,transformation=256],>[slave1:1:trigger=0,transformation=512]"}
Unfortunately after that change I have no telegram on bus.

What I am doing wrong?

Do I need to install anything, that this transformation works?

Thanks

regards Daniel

Hi

You need the 1.10.0-SNAPSHOT as indicated in the docs. Transformation was introduced there. You should find installation instructions somewhere from here.

If you have that version already, it might be worthwhile to check logs for any errors

Best
Sami

Edit : perhaps this thread helps with the installation Replacing openhab2 Paper UI installed binding with custom jar