id: status
channelTypeUID: mqtt:contact
label: Status
description: null
configuration:
stateTopic: zigbee2mqtt/XIAOMI_DOOR_SENSOR_1/contact
off: “true”
on: “false”
Same sensor.
EDIT: Just FYI, I am using z2mqtt’s “advanced” feature breaking all states into their own topics instead of one json string. So that might be a difference here.
Looking at your JSON string you could just use the contact part without any additional JSON file like you do for your other topics.
You could then use state description meta data to change false/true to whatever you want.
Take into account though that this is only visual, i e. In rules you still would need to use false/true (if i am not wrong).
Another option would be to just use a transform map file. This would change the value before it gets to the item and is similar to that JSON code. Maybe also a lot simpler.
I think you would need to chain JSON and transformation map transforms for this. Here is a post talking about it with an example (JSONPATH:$.STA∩MAP:statizone.map).
Never tried it myself though.
Edit: in your case the chain would be JSONPATH:$.contact∩MAP:contact.map (or however you define the map file).
finally after restarting OH the approach with the aqaracontact.js file is working.
Don’t know why this bugged me I also restarted several times while trying yesterday…
It rings a bell with me that JSON booleans in MQTT are a bit quirky, possibly not handled at all; that’s not the same as "contact":"true"
If someone could figure that out, the docs or binding may need enhancement.
The little JS script above handles the JSON natively (of course) and interprets the boolean directly.
The test would be to apply JSONPATH to the same payload and see what the result is in a String.