Json from Tasmota for window sensor - how to

Hello,

I am using a Sonoff Zigbee Bridge with Tasmota zbbridge firmware with MQTT. I have managed to pair a Sonoff window sensor which then gets propagated via MQTT to OpenHAB. I have an item which looks like this:

Number WINDOW_1 "Window" { mqtt="<[moquette:tele/zbbridge/SENSOR:state:JSONPATH($.ZbReceived.0x2B14.Contact)" }

Which makes WINDOW_1 receive JSON like this:

{"ZbReceived":{"0x2B14":{"Device":"0x2B14","Contact":1,"Endpoint":1,"LinkQuality":42}}}

and in this case assign the value 1.

So far so good. Yet, it means I have to create a second item which would be a Contact that I could then assign in a rule the values OPEN or CLOSED depending on this one being 0 or 1.

However, I would like to have this all in one step. Is there a way to tell OpenHAB to make the 0 be mapped to CLOSED and 1 to OPEN for a Contact item directly receiving the JSON? So I would only have one Contact item instead of two items?

I’d be very happy if somebody could enlight me on this, since I’ve been reading through documentation, tried differend MAP() stuff even in the label, but nothing worked for me so far.

Thanks a lot!

With the MQTT 1.x binding, no, you’ll have to write a rule. You can’t chain two different transformations.

Hello @rlkoshak ,

thank you for your quick answer. So I suppose with OpenHAB3 / newer MQTT binding that would work?

Thanks!

Yes but the configuration is radically different. There are several tutorials on the forum for ways to migrate from the 1.x binding to the 2.X+ binding.

As Rich says, yes. And if you use the UI it’s quite easy: you just define what on (Open) and off (Closed) should map to within the Thing Channel itself, which in your case would be 0 and 1.

Or if you wanted to stick with the configuration files, here’s my go-to converting from MQTTv1 to MQTTv2:

Thank you both for your explanations. I will give it a shot and see what happens… :slight_smile: