Rule not working with string from MQTT

I have a water leak sensor connected to Obenhab through ZigbeetoMqtt.

The sensor reports a water leak as either “true” or “false”. I have set this item up in my items file:

String RyTTER0_VANDALARM_ALARM_STRING "Vandalarm" (Zigbee) {mqtt="<[MPmqtt:zigbee2mqtt-rytterstue/VandalarmRytterstue:state:JSONPATH($.water_leak)]"}

It works and receives messages from the sensor. I have also made a switch item to use as the alarm (on/off):

Switch RyTTER0_VANDALARM_ALARM

To change the switch according to the message from the sensor I have made this rule:

rule "Vandalarm"

when
    Item RyTTER0_VANDALARM_ALARM_STRING changed 
   
then
    if(RyTTER0_VANDALARM_ALARM_STRING.state == true){
        RyTTER0_VANDALARM_ALARM.sendCommand(ON)
    }
    else{
        RyTTER0_VANDALARM_ALARM.sendCommand(OFF)
        
    }
end

The rule receive the update from the string vaiable and starts up but always ends with sending a command(off) to the switch. What am I missing here?

I assume true is the string?
If so, try it with “true”.
The rule basically runs through to OFF because your first == is not met.

1 Like

Thanks for your help, that should have been quite obvious.