MQTT on/off to contact item open/closed

I’ve done a fair bit with mqtt and I’ve got used to a switch using ON and OFF as incoming states for switches.

THen I heard about a contact item and that it’s read only, so thought I’d give it a go.

So my Item is now defined as:

Contact alarm_zone_familyrm “Family Room State” (g_alarm,g_motion_detection) {mqtt=“<[frodo:Paradox/Zone/Family Rm:state:MAP(onoff.map)]”}`

And i’ve made a map file the following:

OFF=closed
ON=open
NULL=off

I assume the left side of the map is what will be received (ie ON OFF by mqtt) and this is translated to “closed and open”?

If so this isn’t working as I’ve written it. I’m not seeing the events being updated.

The transform service has been installed. I’ve been following this thread: State / Command in MQTT messages - #4 by rlkoshak

Yes, that is correct. It may be a case of “grasping at straws”, but I think you should use all-caps to the right in your transform file, i.e. like this:

OFF=CLOSED
ON=OPEN

You also need to change the last entry in the transform file, since “off” (or “OFF”) is not a valid state for a Contact item.

hmm no matter what I do i can’t see it attempting to do anything with these items.

Ahhh, seems some of my item names have changed (they’re pulled from my alarm), that didn’t help.

Have you checked to make sure that your alarm system (or whatever it is that sits at “the other end” of MQTT) is actually sending the messages “ON” and “OFF”?

Along those same lines have you made sure it works without the transformation (i.e. maybe the space in your topic is causing issues in OpenHAB)

Yeah I found the issue, the topic names had all changed. I just had my panel replaced, and the installer had got the zone names close, but not exact (changes in case, changes in some names), so it wasn’t working because the expected topic was wrong.

PEBKAC. ID10T

Just on contact items, they don’t display anything like a switch does do they? So to see their state do I have to update the label with [%s]?

Depends what your icon type is. I find that for doors / windows the contact items show open/closed fine. For Motion I’ve had to make sure all mine are switches.

But, yes using [%s] in your label or in Sitemap will show the current status.