OH3: transform MQTT 1|0 to switch ON|OFF creating WARN message

  • openhabian 3.3.0 on rPi4

I have a MQTT thing with a channel (switch) linked to an item (switch) and use a map to transform 0|1 to ON|OFF

However, I get a warning, and the switch does not work.

2022-11-08 22:48:53.192 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '1' from channel 'mqtt:topic:mosquitto:modbus_spp:solar_hybrid_control_8' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.1

the onoff.map contains

0=OFF
1=ON

Any hints appreciated.

profiles operate on links. That’s to say, on the link between channel and Item.

Your error message comes from the channel, which being a switch type channel, is trying to convert the MQTT payload into standard ON/OFF long before the update gets to the profile,

If you wanted to do it this for an experiment or something, use a string type MQTT channel so that it doesn’t care what the payload is.

The more conventional approach is to use the “mini-mapping” built in the MQTT channel for on= and off= arguments, and not use a profile at all.

Or failing that use the transformation feature built into the MQTT channel to use your MAP, again not using a profile at all.

1 Like

Thanks
 since I posted this I changed the channel to a number type.
This at least ‘flicked’ the switch
 but produces and Err in the sitemap.

image

Switch 1 and 8 have been changed to number, the others are still switch.

I’ll come back after trying your suggestions.


OK, changing the channel to a string type produces the desired result.

Sure, but its a weird bodge. Don’t use a profile, there are better ways to represent some incoming MQTT payload as a Switch.

Alright
 :slight_smile:

Does this work with channel switch, item switch and transformation pattern 0=OFF,1=ON?

I am getting a transformation error:

and the thing went offline

further digging resulted in this:

  - id: solar_hybrid_control_8
    channelTypeUID: mqtt:switch
    label: Solar Hybrid Control 8
    description: null
    configuration:
      stateTopic: ArgyleCourt/Shed/Modbus/Data/8058
      transformationPattern: MAP:0=OFF,1=ON

however, the switches are no longer updated.

? Could be related to this:


meaning I revert back to the doggy transformation.

@rossko57 is saying to do this:

Get rid of the MAP transformation pattern. Get rid of the profile on the link.

Just make it a Switch Channel and fill in the Custom On/Open Value and the Custom Off/Closed Value parameters.

It’ll look like this in the code tab.

  - id: garagedoor1_opener
    channelTypeUID: mqtt:switch
    label: Large garage door opener
    description: ""
    configuration:
      commandTopic: sensor_reporter/cerberos/garagedoor1/cmd
      off: OFF
      on: ON
2 Likes

In Max’s case, he wants off=0 on=1 I think.

The MQTT channel’s built in on/off mini-map allows for simple mapping (e.g payload text “banana” to openHAB ON)

The MQTT channel’s transformationPattern= allows specifying a more complex transform or even combination of transforms.

3 Likes

Yes, I got it backwards.

I also had to look it up to see if an inline map like @Max_G tried to use was supported.

I know that the JavaScript transform supports inline liker that now but I can’t find anything that says MAP does. I just wanted to point that out for future readers of this thread. As of this writing MAP:0=OFF,1=ON won’t work (unless this is something added but not yet documented.

1 Like

Thanks, guys.

What I figured
 :slight_smile:
I got there based on other post you specified REGEX or JSON; I thought this is equivalent to transformation that can be selected.
image

Also figured I had to put a zero and 1 in there.

The below works.

You can use the MAP transform there. But you have to supply the name of the file in the transform folder. You can’t define the map inline like that. It has to be in the file.

So it’d be MAP:onoff.map to apply the map transform using the onoff.map file.

I went with the previous solution.
I wasn’t clear the transform works for both in and outgoing messages.
(And it was late at night; getting lost around that time is not uncommon :slight_smile: )

Also apologise for claiming:

I meant to say: I got there based on other posts which specified 



As always: thank you for your reasoned posts, which help understanding the ‘why’.