Write Value Converter: Convert Boolean Switch to 0/1 for MQTT

Hi everyone, I’m trying to use the Write Value Converter in OpenRemote so that a UI switch sends 0 or 1 to an MQTT topic.

Desired behavior:

  • Switch ON (true) → publish "1"
  • Switch OFF (false) → publish "0"

My current attribute configuration:

{
  "id": "7JjAmJDHMbzQSFy7343hOn",
  "writeValueConverter": {
    "true": "1",
    "false": "0"
  },
  "updateOnWrite": true,
  "publishTopic": "obk19BE4911/0/set",
  "type": "MQTTAgentLink"
}

Problem: when I click the switch in the UI, it shows a send failure and nothing is published to the broker.

If I don’t use the Write Value Converter, the broker receives true or false normally

Question: is there any specific configuration detail in the Write Value Converter to make a Boolean switch send 0 and 1 correctly to MQTT?

Hey @Alexsandro it should be clear in the UI and comments but the keys need to be uppercase:

String converterKey = ValueUtil.getValueCoerced(value, String.class).map(str -> str.toUpperCase(Locale.ROOT)).orElse(NULL_LITERAL);

So:

"writeValueConverter": {
    "TRUE": "1",
    "FALSE": "0"
  }

Hopefully that will resolve your issue.

It worked perfectly! Thank you!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.