[SOLVED] MQTT: Publishing of "false/true" for switch channel doesn't work

  • Platform information:
    • openHAB version: 2.4.0 (release)

I set up a MQTT switch channel like this:

Thing mqtt:topic:myTopic (mqtt:broker:mybroker) {
    Channels:
        Type switch : myDebugSwitch [
            stateTopic="my/device/node/attribute",
            transformationPattern="MAP:on_true.map",
            transformationPatternOut="MAP:on_true.map",
            commandTopic="my/device/node/attribute/set",
            postCommand=true
        ]
}

with on_true.map being like this:

true=ON
false=OFF

and an item being like this:

Switch myDebugSwitch_Status "Debug Switch [%s]" <switch> { channel="mqtt:topic:myTopic:myDebugSwitch" }

So receiving a MQTT update my/device/node/attribute true successfully changes my switch, so that’s great.

Sadly it doesn’t work the other way round, when I change the switch to off, I get this log:

[WARN ] [rm.AbstractFileTransformationService] - Could not transform '0' with the file 'on_true.map' : Target value not found in map for '0'
[WARN ] [eneric.internal.generic.ChannelState] - Command '' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.

and OpenHAB publishes my/device/node/attribute/set 0 - so a zero instead of false.

So I edit my on_true.map to be like this:

true=ON
false=OFF
1=true
0=false

which only changes the error message to

[WARN ] [eneric.internal.generic.ChannelState] - Command 'false' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.false

but OpenHAB still publishes my/device/node/attribute/set 0 - which doesn’t cause the switch to switch, because it expects a false there

So what am I doing wrong?

There should be an option to set the on and off value

           Type switch : unreach       "Unreach"           [ stateTopic="tele/GF_KI_WindowsillLight/LWT", on="Offline", off="Online"    ]

I use it to signal an unreach state

Wouldn’t you want

true=ON
false=OFF
ON=true
OFF=false

But I think you have to be 2.5m1 at least.to get transformationPatternOut feature

Sorry no, that doesn’t change the published message.

No, that produces the first error message that 0 can’t be transformed :frowning:

I understand that formatBeforePublish is applied before the transform, so you might need that as %s to convert OnOffType to “ON”

There is your problem…

Ah okay, that’s what he meant with that cryptic abbrevation ^^
I just read documentation at https://www.openhab.org/addons/bindings/mqtt.generic/#channel-configuration and it’s mentioned there. I supposed that documentation fits latest released version, but obviously that’s not the case here…

That currently doesn’t change the output, but it makes the error message in log go away, thanks!

Confusingly, it’s ahead of the game. There is a version dropdown at top right but it defaults to “latest” instead of “standard release”