OH3 MQTT Command and State ON OFF "0" & "1" transformation issues

Hello,
Inbound MQTT state messages are not being transformed, and result in an error;

2021-05-27 23:56:20.570 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '0' with the file 'command.map' : Target value not found in map for '0'
2021-05-27 23:56:20.573 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.

“command.map” exists in the Transform folder.
Screen Shot 2021-05-28 at 7.55.21 am

I need inbound MQTT state messages to be transformed from “1” to “ON”, and “0” to “OFF”.

To test sending Mqtt state messages to OH3, I use MQTT Explorer

Test setup includes vanilla OH3 Raspian build on Raspberry Pi 4.

  • OH version = 3.0.2 - Release Build
  • Mosquitto installed
  • MQTT Broker configured
  • 1 x Thing (a switch)
  • 1 x Channel (MQTT channel linked to the switch)
  • 1 x Item (linked to the channel)
  • 2 x Topics (1 x state, 1 x command)
    I use a mac, so i have MQTT Explorer installed to monitor & troubleshoot MQTT messages.

pretty straight forward so far!

Resulting config below

thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:pi4MqttBroker
channels:
  - id: onofftestchannel
    channelTypeUID: mqtt:switch
    label: onofftestchannel
    description: ""
    configuration:
      commandTopic: myhome/test/command
      postCommand: false
      transformationPatternOut: MAP:command.map
      stateTopic: myhome/test/state
      TransformationPattern: MAP:command.map

The transformation MAP error occurs regardless of what payload I send… of “ON” or “OFF” or “0” or “1” are all not processed. result in error.

Outbound MQTT command topic message are OK and are transformed. (if I edit the mapping file for additional maps). if i turn the switch on, topic with payload of “1” is sent.

I had this working successfully for about an hour. I then started to back stuff up, and add comments to the command.map file… and since then transformation map has stopped working.

Is there a transformation cache or similar I can clear?

I’ll try removing and re-adding the transformation service later this evening.

Did you define the on adf off of the thing channel like this:
image

Thanks, I’ll be home in a couple of hours to have a look.
I’m pretty sure the custom on off values in your screen grab were set at
1
and
0

respectively. I’ll have a look and edit them to ON OFF and see if that helps.

They would have been, but I think there’s a bug which means that the configuration isn’t saved properly. If you change the 1/0 to ON/OFF, then save, then change it back to 1/0 and save again it should all work (and remove the transformationPatterns from the configuration: you don’t need the MAP anymore)

2 Likes

Thank you. Your advice was correct, and it does look like a minor bug.
Looking at my Thing, Configure Channel… there was a 1 & 0.

I updated this configuration to ON & OFF

clicked SAVE and retested the Transformation:MAP function.
Inbound MQTT topic messages with payload of “1” & “0” are now being transformed to “ON” & “OFF”.

All is now working as expected.

Thank you!

I have never had to use a transform or map.
Glad it worked.

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