Combine MQTT and MODBUS in switch item

Hello.

i have wall switch with mqtt. Switch send into topic “Dum/Vypinac7/sv1” ON/OFF.
Light is conected on modbus.
can mqtt command be combined with modbus in one item?

Switch Light14 "light 1" <light> (Office, gLight) ["Lighting"] {modbus="r2:1", mqtt=">[mosquitto:Dum/Vypinac7/sv1:command:*:default], <[mosquitto:Dum/Vypinac7/sv1:state:default]",autoupdate="true" }

In log:

2019-09-13 17:27:50.573 [GroupItemStateChangedEvent] - gLight changed from OFF to ON through Light14
2019-09-13 17:28:08.893 [GroupItemStateChangedEvent] - gLight changed from ON to OFF through Light14

In paperUI, the switch switches but the light is off.
If I switch the switch manually, the light comes on.

if I use rules, it works.
I don’t want to use rules for switches, it has about 100 lines (15 switch functions) and if I have 5-10 switches, the rules respond slowly.

Thanks

Try changing the autoupdate to false

If you were using MQTT and Modbus version 2 bindings, you could use a follow profile.

The modbus binding is only going to respond to a command, not a state change, so you need to find out how to get MQTTv1 to produce a command on input.

Something else wrong there. This is not a difficult job. You might need to think about if really you want both devices updating to the same Item. Remember Modbus polls regularly.

I use modbus 1.x
I also tried modbus 2.4, I tried [profile = “follow”] but it doesn’t work.
Still change state from mqtt does not create a command for modbus.

Thanks for help

Follow profile works fine, but you must use it with Modbus-2 (because it has to work on a channel).

Or, you can configure your MQTT-1 to produce commands (that your Modbus-1 binding will see).

It’s up to you. Let us know if you want help.

I use MQTT binding 1.x and Modbus binding 1.x

My .items:
Switch Light14 "Bodove svetla" <light> (Office, gLight) ["Lighting"] {modbus="r2:1", mqtt=">[mosquitto:Dum/Vypinac7/sv1:command:*:default], <[mosquitto:Dum/Vypinac7/sv1:state:default]", autoupdate="true" [profile ="follow"] }

If I change the status from ON to OFF via MQTT, the status of item Light14 is changed but command for modbus is not generated… Thx.

You can’t use the follow profile with the modbus 1.x
You can’t tell MQTT to use the topic inbound as a command as it is the same outbound topic so you’ll end up with an MQTT infinite loop.
You are going to have to bite the bullet and either use modbus 2.x or MQTTv2
For now I would advise you go for modbusv2. I am not sure if you’ll end up with an infinite loop in MQTTv2 just the same.

Perhaps you can get rid of that to prevent loops. What is your purpose in sending openHAB commands to a wall switch, is this controlling a light as well?

Good point…
Then we would have:

Switch Light14 "Bodove svetla" <light> (Office, gLight) ["Lighting"] {modbus="r2:1", mqtt="<[mosquitto:Dum/Vypinac7/sv1:command:default]", autoupdate="true" }

Maybe pointless, I’m sending a state of light.
If the light is ON, the wall switch sends OFF, if the light is OFF the wall switch sends ON :slight_smile:
A better solution would be if the wall switch would send a “change” and openhab would switch the item.
How to configure an item in openhab for “change” from MQTT?

What item?
The wall switch should only send info to OH not receive any. What sort of device is it?

Don’t know. You don’t describe this wall switch. Maybe it lights up when “on”. Maybe it is directly controlling a light.

Can you change it to have different incoming and outgoing topics?

Cannot do that.

yeah, thas works :slight_smile:

Coolio, I thinks there was a bit of confusion from all parts in what you actually had and wanted to achieve.
@rossko57, great insight, thanks

@nav208, please mark the topic as solved, thanks

can the item be set that the wall switch will only send “CHANGE” to the topic “Dum / Switch1 / sv1” and openhab would switch the item (switch) to the opposite value?
Any transform? Without rules…

Do you mean the payload “CHANGE” everytime?
Then it would be:

Switch Light14 "Bodove svetla" <light> (Office, gLight) ["Lighting"] {modbus="r2:1", mqtt="<[mosquitto:Dum/Vypinac7/sv1:command:CHANGE]", autoupdate="true" }

Yes, when set MQTT

yes, but not working.
If wall switch send into topic Dum/Vypinac7/sv1 value “CHANGE”, item in openhab is not switched.

No, because the value sent into openhab is CHANGE, not the switch payload,
The binding is replacing EVERY payload, with CHANGE
Set the item definition as it was before, when it was working
I am not sure I understand what you want to do

Again, cannot do that.
What’s wrong with rules?