MQTT inbound messages

Hi,

I’m trying to create an item (Number or Switch) in order to receive the status of a D1 Relay.
I’m using ESP8266 to control the delay and to check the status of it:

Topics:

  • Hall/D1Relay/TRIGGER - to receive messages from openhab
  • Hall/D1Relay/STATUS - to send the status to openhab.

MQTT inbound message works like a charm. Below is the configuration of the item for outbound messages :

Switch Switch1 {mqtt=">[mosquitto:Hall/D1Relay/TRIGGER:command:ON:CLOSE],>[mosquitto:Hall/D1Relay/TRIGGER:command:OFF:OPEN]"}

In this way when the ESP will receive “CLOSE” or “OPEN” messages it will close or open the Relay.
Now I’m trying to get the status of the Relay that is published by the ESP controller:

if (relay_status == 1 ) {
	client.publish(D1RelaySTATUS,"CLOSE",true);
	Serial.println("D1RelaySTATUS = CLOSE ");
} 
else if (relay_status == 0) {
	client.publish(D1RelaySTATUS, "OPEN",true);
	Serial.println("D1RelaySTATUS = OPEN");
} 

And I don’t know how to define the item, more precisely
how to use option Transformation that is describe in https://github.com/openhab/openhab1-addons/wiki/MQTT-Binding.

Thank you

Here is the example of the item definition I use:

Switch	WiFiSwitch1 "Sonoff (mqtt)" <poweroutlet> { mqtt=">[broker:/sonoff1/cmnd/power:command:ON:default], >[broker:/sonoff1/cmnd/power:command:OFF:default], <[broker:/sonoff1/stat/POWER:state:default]" }

This used to both send commands and receive status.

I did honestly not understand the problem… did you assign inbound and outbound messages to separate items? Here are a few similar examples of how your configuration should look like https://github.com/arendst/Sonoff-Tasmota/wiki/openHAB#mandatory-topics--items

Thank you for your prompt response. Your examples ware enough to understand how I should configure my item.

Now is working …

To resolve this issue and help others it would be nice if you posted that solution :wink:

Ok. Please find the solution:

//Items
Switch Switch1 {mqtt=">[mosquitto:Hall/D1Relay/TRIGGER:command:ON:CLOSE],>[mosquitto:Hall/D1Relay/TRIGGER:command:OFF:OPEN],<[mosquitto:Hall/D1Relay/STATUS:state:MAP(relay.map)]"}
String State "Status: [%s]" <fire> {mqtt="<[mosquitto:Hall/D1Relay/STATUS:state:MAP(relay.map)]"}

and relay.map contain :

CLOSE=ON
OPEN=OFF