Invert on off in MQTT thing

Hi all,
I have a sonoff 4ch with Tasmota firmware that read open/close status of some valves with a contact in valves itself.
When the valve is close, contact is open and my Tasmota read ON, when valve is open the contact is close, putting GPIO to the GND, my Tasmota read OFF.
I need to invert this behaviour in my Openhab logic beacuse when MQTT status is OFF the valve is actually OPEN so i need it as ON.
I tried with this config in my thing file:

Type switch : EV_cameretta_status "Elettrovalvola cameretta Stato " [stateTopic="tele/collettore_b/SENSOR", transformationPattern="JSONPATH:$.Switch4", off="ON", on="OFF"]

Openhab still reading off with MQTT message OFF and on with message ON.

Any suggestion?

Many thanks in advance

You’ll want to do this on tasmota itself, not openHAB.

SwitchMode 2
Set switch to inverted follow mode (0 = ON, 1 = OFF). At the time when the circuit is closed, Tasmota will send OFF and opening the circuit sends ON.

That’s for a switch but that logic should still be handled at the device level imo.


That work like a charm.
Agree with you that logic should be handled at the device level but I couldn’t figure out how to do it.

Many many thanks!

Happy to help :slight_smile: have a great one!