SOLVED! Sonoff Rf Bridge Sensor Setup Help!


(Rhys Hughes) #1

Im at my witts end with trying to fingure this out. copied a solution and altered to suit my situation but still not working. rf code is received by Sonoff bridge and is sending an mqtt message which appears on my iOS mqtttool app but nothing happens in openHAB. Not a single log input shows regarding the items.please advise!!!

things file,

Type contact : FrontDoor   "Front Door"          [ stateTopic="tele/Sonoff_Bridge/RESULT", transformationPattern="JS:FrontDoor.js"]
Type contact : RearDoor "Rear Door"        [ stateTopic="tele/Sonoff_Bridge/RESULT", transformationPattern="JS:RearDoor.js"]
}```

items file,

Contact Sonoff_Bridge_Front_Door  "Front Door: [%s]"            <frontdoor>           { channel="mqtt:topic:Sonoff_Bridge:FrontDoor" }
Contact Sonoff_Bridge_Rear_Door  "Rear Door: [%s]"            <door>           { channel="mqtt:topic:Sonoff_Bridge:RearDoor" }

sitemap,

Frame label="Security"   {
               Text item=Sonoff_Bridge_Front_Door
               Text item=Sonoff_Bridge_Rear_Door
         }

transform file

(function(jsonString) {
    var data = JSON.parse(jsonString);
    var door = data.RfReceived.Data;
    if (door === null) door = UNDEF;
    if (door == '2BC00A') door = 'OPEN';
    if (door == '2BC00E') door = 'CLOSED';
    return door;
})(input

anybody?

(Rich Koshak) #2

You did not post your full .things file, or if you did it is improperly formed.

Do you have a Bridge defined? Does the Bridge show as online in PaperUI?


(Vincent Regaud) #3

Why don’t you delete that things file and create your thing with the paperUI?


(Rhys Hughes) #4

That is the first 2 lines in the things file all that is missing is the { at the start and no I don’t have the bridge defined as a thing?


(Rhys Hughes) #5

When I’ve tried to a the bridge as a thing via Paper UI it asks me to choose a binding and the only binding available to choose is the WiFiled binding


(Rich Koshak) #6

You must have a Broker Thing defined. This will act as the Bridge and represents OH’s connection to the MQTT broker.

Then you do not have the MQTT binding installed. You can’t do MQTT without the MQTT binding.

I strongly agree with Vincent, you would be better off working through PaperUI. And in the future, if you don’t see something in PaperUI you expect, like there was no ability to create MQTT Things, you should stop there and look for why, because that indicates that there is a problem.


(Rhys Hughes) #7

I am already using mqtt to control other Sonoff devices succefully with the version 1 binding. Does this mean I will need to install version 2? Also include legacy 1.x binding is checked


(Rich Koshak) #8

Then you either need to configure your Item using the MQTT 1.x syntax (no Things) or you need to install the 2.4 version and configure it appropriately. The two can live side by side. See the MQTT 2.4 docs and search the forum for many examples and tutorials.


(Rhys Hughes) #9

Ok so I’ve installed the 2.0 binding and have set up the bridge as a thing in the Paper UI linked it to the broker and added 2 channels Front_Door_Sensor and Rear_Door_Sensor they both have the mqtt topic incoming set to tele/Sonoff_Bridge/RESULT. Would you be able to point me in the right direction as to how I need to update my items sitemap and transform files?


(Rich Koshak) #10

Since your Items are in .items files, I recommend the Text File Linking section.


(Rhys Hughes) #11

Ok I’ve changed my items to have the channel Id of the relevant sensor. But how do I link the .js file to the channel? Can I just put /etc/openhab2/transform/FrontDoor.js in the incoming value transformation field?

These are my new items
Contact Sonoff_Bridge_Front_Door "Front Door [%s]" <frontdoor> { channel="mqtt:topic:bc732646:1" } Contact Sonoff_Bridge_Rear_Door "Rear Door: [%s]"<door>{ channel="mqtt:topic:bc732646:2" }


(Rich Koshak) #12

Is this a transform on the data coming in or going out.

If you want to transform the data coming from the topic, you put the transform on the Channel config.

You will have to click on “Show more” to see the field in PaperUI.

I don’t think the binding supports outgoing transforms at this time.


(Rhys Hughes) #13

It’s a transform for the data coming in. I have 2 transform files FrontDoor.js and RearDoor.js so in the incoming value transformation field I’ve put JS:FrontDoor.js not to see if it works!