Mqtt motion sensor help

Hi guys,

I’m trying to update my old MQTT items to the new MQTT binding, I have both running at the moment and am struggling to get it all working.

old mqtt items

Contact	Kitchen_PIR	      "Kitchen Motion"     <motion>     (SecuritySystem)        {mqtt="<[mosquitto:comfort2/input2:state:MAP(openclosed.map)]"}

new items

Contact	Kitchen_PIR	      "Kitchen Motion"     <motion>   { channel="mqtt:topic:mosquitto:comfort2:input2" }

new things

    Thing topic comfort2 "Kitchen PIR" @ "MQTT" {
    Channels:
        Type switch : input2       "Kitchen Motion"      [stateTopic="comfor2/input2", transformationPattern="MAP:openclosed.map"]
    }
}


I know I’m close but I can’t get it working, although it all works fine in the old MQTT config

Any help is much appreciated
thanks

Make sure you have the broker defined.

Thing mqtt:topic:comfort2 "Kitchen PIR" (mqtt:broker:xxxx) {
        Channels:
            Type switch : input2 "Kitchen Motion" [ stateTopic="comfort2/input2", transformationPattern="MAP:openclosed.map" ]
    }


Contact	Kitchen_PIR	      "Kitchen Motion"     <motion>   { channel="mqtt:topic:comfort2:input2" }

i already have the bridge defined in my sonoff things

Bridge mqtt:broker:mosquitto "mosquitto" @ "MQTT" [ host="xxxxx", port=1883, secure=false, retain=false, username="xxxxx", password="xxxx", qos=0, keep_alive_time=30000, reconnect_time=60000 ]
{

should they be in separate files or all together?

As you can tell I dont quite get it even though its working with my sonoffs but there’s a lot more information on here for sonoff

Check in Paper ui things if you have the MQTT broker from OH2 active and disabile it.
Regards
Lorenzo

It’s easier with all MQTT in one file, as you can nest topic Things in your broker Bridge { }
You can put topic Things in other files, but would then need to make clear what Bridge they belong to - like @SpaceGlider showed .

Your stateTopic starts with " comfor" instead of “comfort2”.

1 Like

Thanks for your heads up.

Problem solved, I was missing :state in my things file

Thing mqtt:topic:comfort2 "Kitchen PIR" (mqtt:broker:mosquitto) {
    Channels:
        Type contact : input2       "Kitchen PIR"                [stateTopic="comfort2/input2:state", transformationPattern="MAP:openclosed.map"]
	}

You don’t need it, this is not version 1 binding. You just set stateTopic= to the actual topic you want to listen to.

Note when editing things files, not all bindings are that clever at picking up small changes. If in doubt, restart the binding after you have finished editing to your satisfaction.

1 Like