Modbus - switch relay on/off

Via modbus binding, modbus poll and modbus data I can read a relay state of the unit:

Now it’s 0. Question is, how to switch on/off from the openhab.

My idea was use a Toggle card :

But when I change a state on the toggle card, relay state wil not change.
So I think I must implement a rule which write a 1 to relay mobus adress ?

I tried this command :

Modbus Data_relay_1_806.sendCommand(1)

but no luck

I don’t know anything about Modbus, but isn’t “Modbus Data_relay_1_806” the label of the thing in your screen shots? I.e. you should do something like “Relay_1.sendCommand(1)”.
Also, the item seems to be of type number, mabe toggle only works with switch?


Mything name is Modbud Data_relay_1_806 :

I think I must send a command to this name

why are you using a number for a coil ? your item wich you want to send the command is ModbusDatarelay1806_ValueasNumber so that means
this Data_relay_1_806.sendCommand(1) becomens ModbusDatarelay1806_ValueasNumber.sendCommand(1)

You need to review some openHAB basic principles. You interact with Items in rules or the UI. You may link Items to channels of Things.

Modbus binding provides switch type channels, which can be linked to Switch type Items, and this sounds like a more useful way to represent your relay.

ohh, not clear for me.
So step by step:
I have a modbus bridge :

then a poll:

and on the end a thing:

with channel:

It’s working. I can see if I will change a relay state in other software.
But now I want change a relay state in openhab. So I need a write on the register address 806 a value 0 or 1.
I tried via rule - sendCommand but it isn’t working.

sendCommand works with Items.
sendCommand does not work with channels or Things.

To make this work, you need -

A modbus TCP Thing, with details of your device.

A modbus poller Thing, with details of what registers to read.

A modbus data Thing, with details on particular register.

The modbus data Thing provides a number of channels to choose from, like number type. You’d probably want the switch type here.

You’d link your chosen channel to an Item of suitable type.

You’ve already got a Switch type Item called Relay_1, but it is linked to number type channel so it is not going to work very well.
Choose switch or number, and stay with it.

When you have your Item, you can use it in rules or UI widgets.

Thing I have on particular register 806 :

Item type I prefer a number:

but change to 1 isn’t working for me, also not a command in the rule. Maybe sendcommand isn’t the right one

That’s up to you. You’ll have to use UI widgets that work with numbers, too.

Okay, so you have now changed the type of Item named Relay_1. This change can be problematic, I suggest a re-boot of openHAB to make sure everyone thinks it is the same type. But look into this first as well …

Your data Thing has no write settings, it is a read-only Thing. You should be able to send numeric commands to the Item, but the Modbus binding will not do anything about them.
You’ll want to add write address, type, etc.

Can’t see what you are doing, not able to comment.

Are you sure that my Thing is read only ? When I will scroll down, I can see a write informations which I also defined :

I tried to add a widget :

This widget will show me a actual status but when I will change on the screen, I has no effect on the relay

next what I tried was add command into rule :

Modbus Data_relay_1_806.sendCommand(1)

but also not working

do you have a list with what registers you want to control and also what type etc?

sure I have :

I want control 806

Maybe this example will help

Bridge modbus:tcp:Smartlink_2 [ host="", port=502, id=2 , timeBetweenTransactionsMillis=1, connectMaxTries=3, reconnectAfterMillis=14400000 ] {

    Bridge poller breakers_car1 [ start=14240, length=2, refresh=2000, type="holding" ] {
        Thing data car1_breaker_write [ readStart="14240.0", readValueType="bit", writeStart="14241", writeValueType="uint16", writeType="holding"]

Switch Car1_breaker_write    "Set relay car"   (gss_modbus_devices_car1)   ["Status"]  { channel="modbus:data:Smartlink_2:breakers_car1:car1_breaker_write:switch" }
Switch Car1_breaker_write    "Set relay car"   (gss_modbus_devices_car1)   ["Status"]  { channel="modbus:data:Smartlink_2:breakers_car1:car1_breaker_write:switch" }

Yes, this is the key I think. Not link a “Value as Number”. You link directly a “Value as Switch”.

Bridge, poller a thing configuration looks ok. Must be, because data reading is working. I checked also write setup and also looks ok.

let me check, but not sure how to set via UI
No chance to change. only this:

See above. Unlink the number. Then link “Value as Switch”.

yes I did it:

but when I change to 1, no efect:

I can check relay status in the second SW and is still OFF

Of course nor, everything we guess here is based on what you tell us or show us. If you don’t show trhe write settings when you have a write problem, then we will guess that you have not set any.

Okay we can see a little more.
Are you sure you want a holding register type?
Are you sure your device wants FC6, not FC16 Modbus write command?
What do you get in your log when you attempt to command from a rule?

I don’t see how a toggle widget can do anything useful to your Number type Item.

Is that good or bad?

So I was directy by device because it was realy strange.
Let me say, error was in second sw which I used for evaluation. Don’t know why, status wasn’t updated.
So last setup with switch is working, so I can manualy switch on and off
Now my second question is how to change switch status via rule ?