Publish to 2 mqtt topics with only an item

How could I publish to 2 topics with only one item. The objective is like on the image

I have a rollershutter and I would like to up and down with only that item and not to use 2 different items. Is it possible? How could I program it?

The item declaration (.item file):
Rollershutter Shutter_GF_Living “Living Room Shutter” (GF_Living) [“Blinds”] {channel=“mqtt:topic:LR_Shutter:LivingRoom_Shutter_Up”,channel=“mqtt:topic:LR_Shutter:LivingRoom_Shutter_Down”}

The mqtt generic things declaration (.things file):
Thing topic LR_Shutter_Up “LR_Shutter_Up” (mqtt:broker:mosquitto)
{
Channels:
Type rollershutter : LivingRoom_Shutter_Up “LivingRoom Shutter Up” [commandTopic=“out/A_Roller_Shades_1_Up/state”]
}
Thing topic LR_Shutter_Down “LR_Shutter_Down” (mqtt:broker:mosquitto)
{
Channels:
Type rollershutter : LivingRoom_Shutter_Down “LivingRoom Shutter Down” [commandTopic=“out/A_Roller_Shades_1_Down/state”]
}

You can archive this with MQTT1. MQTT2 does not support this broken MQTT topic design though. An MQTT topic represents one state and that’s what MQTT2 supports :slight_smile:

I recommend some additional logic on your µController to software emulate a
H-Bridge and have one MQTT topic only.

Cheers, David

One approach would be to define your Item as a Proxy item and trigger a rule to send the command to the right topic using the publishMQTT Action.

How could I do that? I don’t know :frowning:

And in the case of a rollershutter, the received command is a number?

rule “Roller Shutter”
when
Item Shutter_GF_Living received command
then
if (receivedCommand == 100)
{
mqttActions.publishMQTT(“out/P_Prueba/state”,“ON”)
}
else (receivedCommand == 0)
{
mqttActions.publishMQTT(“out/P_Prueba/state”,“OFF”)
}
end

Not necessarily. As documented [here] (https://www.openhab.org/docs/concepts/items.html), Rollershutter can accept OnOff, IncreaseDecrease, and Percent as commands. But it stores is state only as a percent.

And how could I receive the same message from different topic? I mean, for example, I have 2 sensor, first “in/F_Garage_Door_Opened/state” send OPEN/CLOSE and second “in/F_Garage_Door_Closed/state” send OPEN/CLOSE too, but I’m only interested in the command OPEN from the two topic, and I would like to program a contact item that is OPEN when it is OPEN from “in/F_Garage_Door_Opened/state” and is CLOSE when it is OPEN from “in/F_Garage_Door_Closed/state”.

I tried this:
Mqtt thing:
Thing topic Garag_Contact “Garag_Contact” (mqtt:broker:mosquitto)
{
Channels:
Type contact : Garage_Contact_Opened “Garage Contact Opened” [stateTopic=“in/F_Garage_Door_Opened/state”]
Type contact : Garage_Contact_Closed “Garage Contact Closed” [stateTopic=“in/F_Garage_Door_Closed/state”]
}

Item:
Contact Garage_Contact “Garage Contact” (gGarage) [“GarageDoor”] {channel=“mqtt:topic:Garag_Contact:Garage_Contact_Opened”,channel=“mqtt:topic:Garag_Contact:Garage_Contact_Closed”}

Rule:
rule “Garage Contact”
when
Item Garage_Contact received update
then
if(Garage_Contact.state == OPEN)
{
Garage_Contact.postUpdate(CLOSED)
}
else
{
Garage_Contact.postUpdate(OPEN)
}
end

But doesn’t work

Please How to use code fences.

There is a bug in the binding right now that makes this not possible using just one Item. You need two separate Items , one for each topic, and a Rule to forward the new states to Garage_Contact which will become a proxy Item not linked to any Channels.

Is this still not supported?

There are cases, like for example with a Rollershutter, where it makes sense to split the topics: One topic for position commands and a seperated one for up and down commands as those are something completely different. As far as I can see this is not supported at the moment?