Non standard MQTT input (not open/on closed/off)

Struggling with this and am unable to find the right terms to search for although undoubtedly I am not the first to ask…

OH 2.4

MQTT feed incoming from RF link I get data such as

From RF open/closed sensor, physical state open - rflink/EV1527/0e20a0/R/SWITCH 0a
From RF open/closed sensor, physical state closed - rflink/EV1527/0e20a0/R/SWITCH 0e

I am having issues building this input into rules as clearly 0a & 0e do not fit in the normal framework, somehow I need to change them to OPEN & CLOSED (I think) so I can use them in the normal fashion but for the life of me cannot figure out how, some expert advice would be much appreciated!

Hello,
You can use an incoming MAP Transformation. You need to install the Map Transformation Service to use this.


And than you create a map file that maps your custom values to open and closed as described in the example section. You have to save this map file to the transformation folder that is in the same place as your rules and items folders.
You can than call this transformation from paper ui as an incoming transformation in the channel settings of the generic mqtt thing of type contact in paperui

Hope this helps,
Best regards Johannes

An alternative to what Johannes described using the map transformation, the MQTT Generic Thing supports defining the mapping without a transform.

You can put 0a in the “Custom On/Open value” and the binding will convert that to OPEN. It’s not clear whether what you wrote above is the full message received or not. If it is, then put the full text of the OPEN message on the left and the full test of the other one in the CLOSED message.

I can’t remember if this was available in MQTT 2.4 so if you don’t see the above you will need to move up to MQTT 2.5 M1 or later.

1 Like

Ah I didn’t know those were available for contacts too :see_no_evil:, I wrote the answer while in line at the post office so I didn’t look it up. yes that would indeed be the easier solution.

If I had a nickle for every time I wrote an answer in just the same situation I could retire.

2 Likes

Thank you folks for your responses, I will work through them and update the solution here for the next person who stumbles across it…

For completeness this is the entry in mqtt.things:

Bridge mqtt:broker:mosquitto [ host="192.168.60.100", secure=false ] {

//Front Gate Sensor
 Thing topic frontgate "Front Gate Contact" {
  Channels:
  Type string : sensor [stateTopic="rflink/EV1527/048edb/R/CMD" ]
 }

and in items:

String sensorFrontGate "Front Gate Contact Sensor" <motion> (gAll, gSensor) {channel="mqtt:topic:mosquitto:frontgate:sensor"}

The item sensorFrontGate ends up being 0a or 0e and so I need to change it to OPEN/CLOSED here (or before here) in order to use in rules, as this does not work:

when
 Item sensorFrontGate changed to 0a
then
 <stuff and bobs>
end

I am using mosquitto as the broker and the binding from David Graeff I don’t really use the GUI so will be looking to do this at a conf file level

So …

when
 Item sensorFrontGate changed to "0a"

But do see above about doing the ‘translation’ directly in the channel and using a Contact type Item.

Have all working, thanks for the pointers!

For anyone else who may read this, here is what I did:

in transform/rf.map

0a=OPEN
0e=CLOSED

in things/mqtt.things

Bridge mqtt:broker:mosquitto [ host="192.168.60.100", secure=false ] {

//Front Gate Sensor
 Thing topic frontgate "Front Gate Contact" {
  Channels:
  Type string : sensor [stateTopic="rflink/EV1527/0e20a0/R/SWITCH" ]
 }
}

in items/gate.item

String sensorFrontGate "Front Gate Contact Sensor" <motion> (gAll, gSensor) 
{channel="mqtt:topic:mosquitto:frontgate:sensor"[profile="transform:MAP", function="rf.map"]}

Ouput in log is:

 2019-06-01 14:24:02.014 [vent.ItemStateChangedEvent] - sensorFrontGate changed from CLOSED to OPEN
2019-06-01 14:24:05.076 [vent.ItemStateChangedEvent] - sensorFrontGate changed from OPEN to CLOSED

Don’t forget to install the MAP transformation, that got me for a few mins :slight_smile:

Cheers all!