I hear you - I went on the same journey recently with WLED stuff!
I think you can trim this down very easily already. For example, on your motion sensor, you could get rid of all the JS transforms by changing your things file as follows:
Type contact : occupancy "Occupancy" [ stateTopic="zigbee2mqtt/UNIQUE_ZIGBEE_ID", transformationPattern="JSONPATH:$.data.occupancy", on="true", off="false"]
Type contact : tamper "Tamper" [ stateTopic="zigbee2mqtt/UNIQUE_ZIGBEE_ID", transformationPattern="JSONPATH:$.data.tamper", on="true", off="false"]
Type contact : battery_low "Battery Low" [ stateTopic="zigbee2mqtt/UNIQUE_ZIGBEE_ID", transformationPattern="JSONPATH:$.data.battery_low", on="true", off="false"]
The above will use the JSONPATH transform to extract the required values, then map true
and false
to on
and off
(which for a contact channel actually means true
and false
will map to open
and closed
). If you want to switch it, you can map on="false"
and off="true"
…
(I’ve made an assumption here on what the device actually returns on these topics, so you may need to tweak)