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

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