Issue with switch Type Configuration for MQTT in OpenHAB

Hello everyone,

I’m encountering an issue with configuring a switch item in OpenHAB that communicates via MQTT. I’m trying to create an item to monitor the status of a battery widget and toggle between on and off.

Here is my code:

Type switch : batteryCritical "Battery Critical" [
    stateTopic="nukihub/lock/battery/critical",
    on="1",
    off="0"
]

However, when I try to change the status, I get the following error:

Command '0' from channel 'mqtt:topic:nukihub:batteryCritical' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.0

Error Explanation: The error message indicates that the value '0' is not supported by the OnOffType since it expects either ON or OFF (in uppercase), rather than '1' and '0'.

How do i do the transformation correctly?

Can you share the entire configuration for the whole Thing named nukihub


Thing mqtt:topic:nukihub (mqtt:broker:mosquitto) {
        Channels:
             Type string : lockState "Lock State" [
                stateTopic="nukihub/lock/state",
                allowedStates="unlocking,locked,unlocked,ack"
            ]

            // Lock Action (commands to control the lock)
            Type string : lockCommand "Lock Command" [
                stateTopic="nukihub/lock/action",
                commandTopic="nukihub/lock/action",
                allowedStates="--,lock,unlock,ack"
            ]
            Type switch : batteryCritical "Battery Critical" [
                stateTopic="nukihub/lock/battery/critical",
                ON="1",
                OFF="0"
            ]
            Type number : batteryLevel "Battery Level" [
                stateTopic="nukihub/lock/battery/level"
            ]
            Type string : bridgeStatus "Bridge Status" [
                stateTopic="nukihub/maintenance/mqttConnectionState"
            ]
    }

The configuration for the batteryCritical Channel is different from your first post - is that deliberate?

Which version of openHAB are you running?

I am on oh 4.3.1 and I experimented in the meanwhile to get the correct syntax last post is my last test version

The version in your first post should be the correct one. When you make a change to your configuration file, is openHAB recognising the change? You can see the change happening in the log, and also if you look at the Thing in MainUI?

Here is the log

2025-01-12 11:31:22.723 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mqtt.things'
2025-01-12 11:31:23.758 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'pihole.fritz.box' with clientid openHAB
2025-01-12 11:31:24.394 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '0' from channel 'mqtt:topic:nukihub:batteryCritical' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.0

config

Thing mqtt:topic:nukihub (mqtt:broker:mosquitto) {
        Channels:
             Type string : lockState "Lock State" [
                stateTopic="nukihub/lock/state",
                allowedStates="unlocking,locked,unlocked,ack"
            ]

            // Lock Action (commands to control the lock)
            Type string : lockCommand "Lock Command" [
                stateTopic="nukihub/lock/action",
                commandTopic="nukihub/lock/action",
                allowedStates="--,lock,unlock,ack"
            ]
            Type switch : batteryCritical "Battery Critical" [
                stateTopic="nukihub/lock/battery/critical",
                on="1",
                off="0"
            ]
            Type number : batteryLevel "Battery Level" [
                stateTopic="nukihub/lock/battery/level"
            ]
            Type string : bridgeStatus "Bridge Status" [
                stateTopic="nukihub/maintenance/mqttConnectionState"
            ]
    }

I’m on 4.2.3, and it works fine with the configuration shown in your latest post. Assuming that your channel is actually receiving real integers, rather than integer strings…

Screencastfrom2025-01-1211-32-56-ezgif.com-optimize

Here is the definition

It says:

lock/opener/battery/critical: 1 if battery level is critical, otherwise 0

It’s via mqtt I thought everything is like a string?

It’s also solved via upgrade to OH4.3.2