Mqtt, binding, things and transformation

I’m using openhab 2.5 and the new bindings.

Hi, I’m very new to openhab but i love it. I’m trying to configure my mqtt bindings using files, (if i can’t user paper UI for everything i prefere to use the files for what I can).
I already configure mosquitto and it;s working with my sonoff switches. Now I’m trying to configure my Sonoff RF433 Bridge (all my sonoff use tasmota).
I have one problem and one question
The question first, can I separate my bridge and my things in diferent files? If yes how i mustr rewrite my mqtt things?

Now the problem, the first two things are sensor, one pir the orther door (contact). When activate the send one command (alfa numeric) The ones in the OPEN option. But openhab complains about this value.

[WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '698489' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.698489

I read a lot, buty i’m not sure how to proced.

Finally i left here my mqtt.thing with my configuration. I copy from other post, so there may be some wrong or not necesari, any advice on how to tune it I’ll apreciate.

mqtt.things

Bridge mqtt:broker:MosquittoMqttBroker “Mosquitto MQTT Broker (mio2)” @ “MQTT” [

host=“localhost”,

secure=false,

port=1883,

qos=0,

retain=false,

clientid=“Oh2Mqtt2Thing”,

//certificate="",

//certificatepin=false,

//publickey="",

//publickeypin=false,

keep_alive_time=30000,

reconnect_time=60000,

//lastwill_message="",

//lastwill_qos=1,

//lastwill_topic="",

username=“openhabian”,

password=“password”

]

{

// sonoff Bridge

Thing mqtt:topic:sonoffBridge “Sonoff Bridge” @ “MQTT” {

Channels:

      Type contact : movimiento "movimientoVestibulo" [ 

      stateTopic="tele/bridge/RESULT",

      transformationPattern="JSONPATH:$.RfReceived.Data",

        OPEN="EDAC6E",

        CLOSED=""

      ]

Type contact : puerta01 "Apertura de Puera 01" [ 

      stateTopic="tele/bridge/RESULT",

      transformationPattern="JSONPATH:$.RfReceived.Data",

        OPEN="698489",

        CLOSED=""

      ]

}

// Sonoff siberiaLed

Thing mqtt:topic:siberiaLed "siberiaLed" @ "MQTT"  {

  Channels:

      Type switch : switch "Power Switch" [ 

        stateTopic="stat/siberiaLed/POWER", 

        commandTopic="cmnd/siberiaLed/POWER",

        //retained=false,

        //postCommand="",

        //transformationPattern="JSONPATH:$.POWER", 

        //formatBeforePublish="%s",

        on="ON",

        off="OFF"

      ]

      Type string : state01 "Switch State 01" [ 

       stateTopic="stat/siberiaLed/POWER",

        on="ON",

        off="OFF"

                  ]

      

      Type string : state03 "Switch State 03" [ 

        stateTopic="stat/siberiaLed/RESULT",

        transformationPattern="JSONPATH:$.POWER",

        on="ON",

        off="OFF"

      ]

    

      Type string : wifi-ap "Wifi AP" [ 

        stateTopic="tele/siberiaLed/STATE",

        transformationPattern="JSONPATH:$.Wifi.AP"

      ]

      Type string : wifi-ssid "Wifi SSID" [ 

        stateTopic="tele/siberiaLed/STATE",

        transformationPattern="JSONPATH:$.Wifi.SSId"

      ]

      Type string : wifi-channel "Wifi Channel" [ 

        stateTopic="tele/siberiaLed/STATE",

        transformationPattern="JSONPATH:$.Wifi.Channel"

      ]

      Type string : wifi-rssi "Wifi RSSI" [ 

        stateTopic="tele/siberiaLed/STATE",

        transformationPattern="JSONPATH:$.Wifi.RSSI"

      ]

      Type string : uptime "Uptime" [ 

        stateTopic="tele/siberiaLed/STATE",

        transformationPattern="JSONPATH:$.Uptime"

      ]

      Type string : time "Time" [ 

        stateTopic="tele/siberiaLed/STATE",

        transformationPattern="JSONPATH:$.Time"

      ]

      Type string : devicestate "Device State" [ 

        stateTopic="tele/siberiaLed/LWT"

      ]

}

}

Thanks.

PD: After this i will contionue with rules to retuen somo thing like stanby status to the sensor, but I’m, still reading it. Any advice is welcome.

Please use How to use code fences.

I don’t use .things file and I don’t recommend their use so I can’t help with specifics. But the error is pretty clear. You are attempting to send 698489 as a command to a Contact Type Item/Channel. A Contact:

  • cannot receive commands
  • can only receive NULL, UNDEF, OPEN, and CLOSED as updates.

So you either have a Channel that needs to be defined to support Numbers or you need to create a transformation to convert that number to OPEN or CLOSED.

We-ell, “command” is a bit of a misnomer in this context.
I’m guessing you have an inbound MQTT payload ‘698489’ that you need to turn into OPEN or CLOSE, suitable for a contact channel state update.

See the binding docs, in particular the use of on= off= parameters for Contact channels

I tried
imagen
imagen
imagen

With this tranformation rule:
imagen

I every case the log answer is alway the same:

[WARN ] [hab.binding.mqtt.generic.ChannelState] - Command '698489' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.698489
[WARN ] [hab.binding.mqtt.generic.ChannelState] - Command '698489' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.698489

I create a map file with:

698489=OPEN
EDAC6E=OPEN

But again the same answer.
Is this working as espect?
I’m doing something wrong?

PD: Also tried without the “OPEN=”

You set the “custom on/open” value in PaperUI to just the value.
698489

If you were to define Things in files instead, you would use on="1234" format. But you don’t.

But … now you’ve revealed you’ve extracted the 698489 from JSON? So there is already a transformation at work?
I’m really not sure what order the various transformation options are applied in.
You would need the JSONPATH to pass its results to the on/off custom value part.

Sorry thtat was the first option
imagen

The same answer

Also tried with 2 diferent sensor with the same error.

The help you get is based on the info you give.

Okay, so your JSONPATH appears to be extracting the 698489 okay, because that’s all the message complains about.
So let’s assume the “on/off” stuff is in the wrong place in the chain for this job, and does not operate on “Incoming transformations” output. Abandon that and remove your settins.

The alternative is to chain your JSONPATH to a further transform, as described in the MQTT docs.
I’d use a MAP transform, as you’ve already made a file for that. That’s an installable service too, if you hav not used it before.

Yes I already install, what i haven’t do was any link, I only create the file mqtt.map . Do i need to configure something else?

Yes. The system has no idea that you want to do anything in particular with a random file.

You’d want to chain a MAP transform after your JSONPATH transform, as described in the MQTT binding docs.

I’m sorry i must be missing something, i can’t see it. The map transformation is made after i extract the value with the jasonpath in the channel configuration or in another place? The .item file?

Transformations can be chained by separating them with the mathematical intersection character “∩”.

It’s also documented in PaperUI

Applies transformations to an incoming MQTT topic value. A transformation example for a received JSON would be “JSONPATH:$.device.status.temperature” for a json {device: {status: { temperature: 23.2 }}}. You can chain transformations by separating them with the intersection character ∩.

So, as it says, insert ∩ after your JSONPATH transformation and add a MAP transformation config which consists of the keyword “MAP” and the name of the map file to use.

1 Like

Thanks it works, something odd, when the mapping start working the mqtt stop show in the logs. Is this normal?

One question more if you can i have this line in my mqtt.item

Contact verstibuloPir_contact "Pir Verstibulo" {channel="mqtt:topic:a8d8c0e5:pirVestibulo", expire="10s,state=CLOSED"}

The item works but the expire option doesn’t do anything.

We cannot see over your shoulder. If you’d like comment, post the mysterious log.

Expire is not an option, it is an installable binding. That’s a hint - have you installed expire binding?

Thanks you. Now it working. although I observe strange behavior. I have to sensor to this, both use the same mqtt channel but with different codes. If i put both codes in the same MAP and equal them to OPEN, when one is activate the other is activate also. I create 2 diferent map so whn one is activate the other gives an error in the log that the code is not recognized:

2020-04-06 08:22:10.458 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '698489' with the file 'pir.map' : Target value not found in map for '698489'

2020-04-06 08:22:10.462 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.

It is working and that is the important thing, but since I am a little obsessive, is there something I have to do so that all the sensors are not activated just because I use the same mqtt channel?

I suppose what would be helpful for giving any useful advice is seeing what your channel definition(s) look like now, and what your map file(s) look like now.
You might need to explain what you would like to happen with your “different codes”.

I think you are re-inventing this wheel

1 Like

Yes yes yes, that was the post. In factr i read it what at that time i think my problem was another, and the solution was in a diferent way. Thanks

How to get this symbol by Keyboard? Is it a common symbol in US?

No, it’s not common at all. I’m sure there is some key combo one can type to bring it up (like the degree symbol which is another similar annoyance for those on a US keyboard) or one can use the Symbol Map (if it still exists on Windows). I’m personally very unhappy with the choice of this symbol but I’m not a dev so don’t have much weight to complain.

As yet another reason why I push creating Things in PaperUI, I usually just copy the symbol from the instructions under the transformation field in the form and paste it in place. If I were to use .things files, I would probably copy and paste the symbol into a comment so I can copy/paste in that file.

1 Like

Just as I did for the question :smile: