[SOLVED] Help ! : MQTT2 (OH24) MAP SonOff

Hello World,

I’ve upgraded my OH23 to OH24, I can’t find how to MAP State in MQTT Thing.

In OH23 I’ve :

Switch	Bathroom_Fan_Reachable		"Controleur SDB: reachable"																						(gReachable)
									{ mqtt="<[broker:tele/sonoff-SW01/LWT:state:MAP(reachable.map)]" }

Where reachable.map :

Online=ON
Offline=OFF
Connecté=ON
Déconnecté=OFF

In OH24 I’ve :

mqtt.things

Bridge mqtt:broker:mosquitto "Mosquitto MQTT Broker" @ "MQTT" [ host="localhost", port=1883, clientid="OpenHab2", secure=false, keep_alive_time=30000, reconnect_time=60000 ]
{
	// Module Sonoff Basic
	Thing mqtt:topic:sonoffsw01 "Sonoff Basic SW01" @ "MQTT" {
		Channels:
			Type switch : reachable		"Reachable"					[ stateTopic="tele/sonoff-SW01/LWT", ?????????????? ]
	}
}

mqtt.items

Switch sonoff_SW01_DeviceState "Device State" (gReachable) { channel="mqtt:topic:sonoffsw01:reachable" }

How can I use a MAP with Thing as In OH23 ?

Thanks in advance

Olivier

Have you read the documentation for the MQTT binding? (Including the large section about transformations?)

Yes, here but I haven’t find anything about use of map files in thing/chanels.

Or I haven’t understand it

According to the docs, this should work:

Bridge mqtt:broker:mosquitto "Mosquitto MQTT Broker" @ "MQTT" [ host="localhost", port=1883, clientid="OpenHab2", secure=false, keep_alive_time=30000, reconnect_time=60000 ]
{
    // Module Sonoff Basic
    Thing mqtt:topic:sonoffsw01 "Sonoff Basic SW01" @ "MQTT" {
        Channels:
            Type switch : reachable "Reachable" [
                stateTopic="tele/sonoff-SW01/LWT",
                transformationPattern="MAP:reachable.map"
            ]
    }
}

OR

You could use a profile:
Leave the MQTT thing unchanged and your item should be:

Switch sonoff_SW01_DeviceState "Device State" (gReachable) { channel="mqtt:topic:sonoffsw01:reachable" [profile="transform:MAP", function="reachable.map"] }
4 Likes

Thank you for your helpful answer

it works the Device State switch is active, but an error is generated with both of solution.
The topic LWT of sonoff return “Connecté” remaped to ON

Here is the error :

java.lang.RuntimeException: {“error”:“partial write: field type conflict: input field “value” on measurement “sonoff_SW01_DeviceState” is type float, already exists as type string dropped=1”}

Sorry mistmatch read it is an error from influxdb.

You may have had the item as a Number item when you created it and influx created a Float record for it.
Now you’re a bit stuck.
you’ll either remove it from the persistence.
or rename the item
or edit the influxdb and remove the table for this item. It will be recreated fresh by the binding when required

I use influxDBStudio I’ve droped the mesurement

1 Like

I’ve been success to double transform with JSONPATH and MAP transform with the “∩” character…
Because my value returned whiting my json is always an device RF data and a switch need an ON/OFF value. :roll_eyes:

Exemple for my SonOffRFBridge mqtt Thing:

transformationPattern="JSONPATH:$.RfReceived.Data∩MAP:sonoffRFBridge.map"

Note that there’s no space around de “∩” special character…
But to make an contact type it is not working as look like contact type discard my “ON/OFF” values. So I make it a switch type…

Contact is OPEN or CLOSED, though I do the same as you: just use a Switch type instead.