Converting Tasmota switch to Openhab contact

I have an existing generic MQTT bridge thing for my Door reed switch which currently returns OPEN/CLOSED on my Door1_state
I would like to migrate this to Tasmota which returns ON/OFF for this sensor, but to reduce some of the automation changes is it possible to transform this channel from ON=CLOSED to OFF=OPEN

I have seen a “CUSTOM ON/OFF value” mentioned in the OpenHab UI but how do I code this in my thing file ??

**DOOR.thing**
 Bridge mqtt:broker:mqttbroker "Mosquitto" [ host="localhost", port=1883, secure=false, clientID="openhab" ]
    {
	Thing topic garage1 "sensor ESP32" @ "Garage" 
		{ 
         Channels:
			Type string : status "ESP32 status" [stateTopic="device/garagehw/LWT" ]
			
			Type switch : Door1_switch "Garage Door1" [commandTopic="cmd/garagehw/RELAY1", on="SWITCH", off="SWITCH" ]
			Type contact : Door1_state "Garage state Door1" [stateTopic="status/garagehw/SWITCH1"  ]

linked topic

Just put the ON and OFF in the custom part.


And the item will show OPEN or CLOSED:

Thanks I did see that in the related thread, how do I code this using a file based config?

Are you saying there is no custom mapping I can use for a type Contact

Type contact : Door1_state "Garage state Door1" [stateTopic="status/garagehw/SWITCH1"  ]

ideally I can use something like CustomClose=“ON” CustomOpen=“OFF”
or something list this not sure if you can chain multiple transform patterns ??

Type contact : Door1_state "Garage state Door1" [stateTopic="tele/garage/SENSOR" 
transformationPattern="JSONPATH:$.Door"  transformationPattern="MAP:tasmota-switch.map"] 

There is an on and off property for switch and contact Channels.

When using .things files always refer to the docs first. Alternatively you can create the Thing in the UI and look at the code tab. The fields have the same names in the UI and the files.

I’ve created a Thing using UI with two two channels one using Contact and the other a String
I see the String being populated with ON/OFF but nothing for the Contact
Ideally I would like to have contact OPEN=ON and OFF=CLOSE but perhaps I’m missing something
Is this even possible ie to map/transform channel data to item
ie transform ON->OPEN

channels:
  - id: testdoor1
    channelTypeUID: mqtt:contact
    label: test door 1
    description: mqtt tasmota test door1
    configuration:
      stateTopic: tele/mygarage/SENSOR
      off: OFF
      on: ON
  - id: testdoor1a
    channelTypeUID: mqtt:string
    label: testdoor1a
    description: ""
    configuration:
      stateTopic: tele/mygarage/SENSOR

Can do something like this???

Contact mydoor { channel="<channelUID>" [ profile="transform:MAP", function="|ON=open;OFF=closed" ] }

i use some mqtt contacts where tasmota is sending states 1 or ON and 0 or OFF

  - id: Durchgang
    channelTypeUID: mqtt:contact
    label: Durchgang
    description: ""
    configuration:
      stateTopic: tele/Zigbee/Durchgang/SENSOR
      transformationPattern:
        - REGEX:(.*\"Contact\".*)∩JSONPATH:$.Durchgang.Contact
      off: "0"
      on: "1"

The item connected to this channel is, of course, also a contact typye and is automatically transformed to OPEN/CLOSED
no Transformation needed

What type is your item connected to the contact channel?

thanks heaps it works !!

UID: mqtt:topic:test73b8f7d02e
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:testd2de8e6790
channels:
  - id: testdoorchannel
    channelTypeUID: mqtt:contact
    label: testdoor contact
    description: ""
    configuration:
      stateTopic: tele/mygarage/SENSOR
      transformationPattern:
        - JSONPATH:$.Door1
      off: OFF
      on: ON
1 Like

Could you define why it was not working

I didn’t have the transform on the channel and that topic had multiple json objects