MySensors --> MQTT --> OpenHab 2.5

  • I'm in the process of setting up my first install, so please bear with me, I'm strill trying to get my head around all this!

    I've got my first sensor node and an MQTT gateway, successfully publishing messages to Mosquitto. Now I need to setup OpenHAB to subscribe to those messages. From what I've read, I get the impression there are two options:

    I gather there have been efforts to get the MySensors binding officially incorporated into OpenHAB, but it looks like this hasn't been completed yet, so it seems that the MySensors binding is a much more "manual" to set up.

    Would both options work? What are the advantages/disadvantages of choosing one method versus the other?

    Any thoughts/recommendations?

  • Hero Member

    Hey @P72endragon!

    The right binding depends on the way you like to configure the things and nodes in Openhab. If you're using the text files for configuration the better choice may be the MQTT binding. The hardest part will be the initial configuration but from there it is copy and paste. Don't forget to use static node ids here.

    If you like to setup your configuration via PaperUI the binding may be the better choice, because the binding will discover new things in the MySensors network and you're able to link them to items with a few clicks.

  • Hi TimO,

    To be honest, I don't really mind which way I do it (PaperUI/text files). I have noted warnings about not mixing both together though! ;). A lot of the examples and forum posts I've seen use text files, so I'm tempted to go that route

    I've been having a play with it and I seem to have got OpenHAB to auto-discover my temperature sensor (it's displaying it in the inbox) and in the OpenHab log I can see the temperature readings:

    22:13:38.837 [DEBUG] [protocol.mqtt.MySensorsMqttConnection] - Message topic part: 1/0/1/0/0
    22:13:38.843 [DEBUG] [protocol.mqtt.MySensorsMqttConnection] - Converted MQTT message to MySensors Serial format. Sending on to bridge: 1;0;1;0;0;16.1
    22:13:38.858 [DEBUG] [orsAbstractConnection$MySensorsReader] - Message from gateway received: 1;0;1;0;0;16.1
    22:13:38.863 [DEBUG] [ors.internal.gateway.MySensorsGateway] - Node 1 found in gateway
    22:13:38.867 [DEBUG] [ors.internal.gateway.MySensorsGateway] - Child 0 found in node 1
    22:13:38.872 [DEBUG] [sensors.handler.MySensorsThingHandler] - Updating channel: temp(V_TEMP) value to: 16.1
    22:13:38.880 [DEBUG] [sensors.handler.MySensorsThingHandler] - Setting last update for node/child 1/0 to 2020-04-28T22:13:38.000+0100

    I'm still trying to get my head around Things, Items and Channels to get OpenHab to actually display this information, so I don't think I'm far away.

    Having said that, like I say, I'm always tempted with text file configs...
    If I go that route, do you happen to have any links to point me in the right direction?
    Where do I set the static node ID's - do they need to go in the sketches for each sensor node, or just in the .things/.items files?
    I think I need to find a good example of how to write the .things/.items files etc...

  • Hero Member

    The node id is set in the sketches via MY_NODE_ID define.
    I'm using the MQTT binding a lot, but not for MySensors. I'm using the MySensors binding with my ethernet gateway. So I can't give you a working example, but it should be possible. Stick to the MQTT binding documentation and the documentation of the MQTT gateway on the MySensors site.
    I myself use PaperUI to get familiar with new bindings and things and then copy for example the channelname from the ui in the text files to reduce typos. I don't have had any problems mixing both ways of configuration. Just be sure to only have one definition left at the end, either in UI or in text files.

  • Let me offer my thoughts and recommendations:

    For myself I have been using MQTT as the connection method for a number of years.

    Doing that, you must have an MQTT broker as the "middle-man" to receive MQTT messages from the MySensors MQTT gateway and then relaying them to OH, which then uses the MQTT binding. Then you do not use the MySensors binding to OH at all.

    The advantage is that you can have a number of sources/sensors feeding information to the MQTT broker. In my case I have three geographical sites with MySensors nodes, each with an MySensors MQTT gateway, feeding the broker. Actually at one of the sites there is also a Sonoff switch that also reports status and gets commands via MQTT. (I am using the Espurna SW on the Sonoff).

    Then my OH installation subscribes to the broker via the OH MQTT binding.
    To dive deeper into details, because of this geographical set-up, I am using a commercial MQTT broker, which is accessible over the internet from all three sites. If you only operate one site, then you are better off using e.g. Mosquitto inside your firewall.

    As far as I understand the OH MQTT binding does not offer auto-discovery unless you use the Homie naming convention. Check the OH documentation please.

    For MySensors nodes I use the MySensors notation so a typical message looks like: mqttgw1/28/3/1/0/0 23.2 for say, a node-ID 28 and child-ID 3 that reports a temperature of 23.2 °C

    When I started using MQTT and the 1.0 binding I made all definitions in the .items text file but when I converted to MQTT 2.0 I have made all the definitions in the PaperUI. It is either/or depending on your preferences but I think the general recommendation in the OH community is to use the PaperUI.

    If you stick with text files I strongly recommend that you use Visual Studio Code and the OpenHAB extension to VS. Then you get syntax checking and nice colours to all keywords.

    As far as I understand, the MySensors OH-binding uses the ethernet or serial MySensors GW. Probably the set-up is simpler in the beginning but offers less flexibility in the long run. I could never have achieved my set-up above using just a serial connection.

  • I second this. I went the mqtt route as well. Auto discovery is cool, but i wanted some additional control. My openhab 2.5 I don't use the UI at all. I just all flat files. This is a preference for me. I also use the VSCode extension for openhab and it works BEAUTIFULLY!

  • Thank you for your comments, it sounds like it's worth trying to get the native OH MQTT working (I don't mind not having auto-discovery - I won't be adding things so regular, once I get it figured out I'm OK with adding things manually).

    I've managed to setup PaperUI sufficiently to get the temperature from my sensor to display on PaperUI's control screen (although I'm not sure I understand quite how it works yet, still a little unclear on Items, Channels, etc)

    @CrankyCoder : I don't suppose you'd mind sharing some snippets of your config files (or point me at some good examples) to get me started - maybe showing a broker and something like a temperature sensor?

  • @P72endragon
    I also use MQTT instead of the binding. Major reason: when I started, it wasn't out and I had the serialGW connected. Once realized I want the controller in a different place, I switched to MQTT and never regret. I feel I have more control with the text files than I have with the UI-driven way.

    First of all, I highly recommend you download MQTT-spy or similar, this will help a lot in figuring out the right notation in OpenHAB. It will just listen to the traffic and log it. You could also use it to send test messages etc.

    Gateway configuration

    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "hefti-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "hefti-in"
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "hefti-1"

    Node configuration (temperature sensor)

    #define CHILD_ID_TEMP 1
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    present(CHILD_ID_TEMP, S_TEMP);

    OH example.items

    Number  roofTemp01              "Temperature roof [%.1f °C]" <temperature> (Temperature, Outdoor) {mqtt="<[mosquitto:hefti-out/101/1/1/0/0:state:default]"}

    MQTT spy of a recent message:
    That is basically it. Depending on how you want to display the result (sitemap, PaperUI etc). As you see, the item is displayed in Temperature and Outdoor but you could also specify it directly in the sitemap but I guess this is going too far here.
    Hope that helped.

  • That's great, thank you, I'll have a play and see how far I can get... (yeah, I've already been using MQTT Explorer to understand the message structure)

  • Not sure how you are making out @P72endragon, I just came across this thread and noticed something I wanted to point out to you (and others):

    @parachutesj said in MySensors --> MQTT --> OpenHab 2.5:

    OH example.items
    Number roofTemp01 "Temperature roof [%.1f °C]" <temperature> (Temperature, Outdoor) {mqtt="<[mosquitto:hefti-out/101/1/1/0/0:state:default]"}

    This looks to me like MQTT v1 binding (and you will find a lot of examples like this on the Internet, unfortunately). The v2 binding looks a bit different (and you will find less examples of). I can post some working ones if anyone is interested.

  • @TRS-80 true, MQTT v1. The updated binding sucks IMHO
    EDIT: I should have been more specific. The MQTT binding was not migrated to 2.x for a long time and over time I got a lot of connected things via MQTT. Once 2.x was released it wasn't really stable in the beginning and later it was just not worth to do the upgrade IMHO. Once OH 3.x comes out and we have to adapt again, I might think about a migration but until then, I am happy with MQTT 1

  • @parachutesj said in MySensors --> MQTT --> OpenHab 2.5:

    The updated binding sucks IMHO

    I guess if it sucks, it is largely because there are very few (good, working) examples of it around the net, but very many v1 examples.

    I am not necessarily disagreeing with you, but in my case the only suck was the initial setup, now that I have got over that hump it has worked flawless. It might even be more organized (maybe it is growing on me)? 🙂

    But I did not work with MQTT v1 a lot, I was on MySensors Binding + Serial gateway before. Which would always drop out and other problems, totally unreliable. It could have been that I was on old version of Armbian and therefore stuck with old version of OpenHAB so maybe not a fair assessment, although I read of others with a lot of problems, too.

    Anyway, now I am starting over from scratch with more powerful SBC (ODROID-XU4 instead of Cubietruck), latest Stable Armbian and OpenHAB, with MQTT v2 binding, an Ethernet (MQTT) gateway and armed with new insights into radio propagation and testing methods... And with putting all that together now it has been rock solid so far! Although admittedly only a few nodes, and only for maybe few weeks so far...

    So, fingers crossed! 😄

    Are you perchance using MySensors binding with MQTT v2, or just straight MQTT v2 without the MySensors binding? I would love your feedback in my other thread in either case.

  • @TRS-80 sorry should have been more specific and edited my post above. I don't know if it still sucks but in the beginning it wasn't working very well and I didn't want to change all my configuration just to have exactly the same. Still a question of time.
    So I stick with MQTT 1 without MySensors binding - same, just what you have started with, stick with it until there is a real need.

  • @TRS-80 said in MySensors --> MQTT --> OpenHab 2.5:

    Not sure how you are making out @P72endragon

    I got as far as making my proof-of-concept work. I've put the software side of things on hold for the time being while I do some hardware work. Once I get back to the software, I'll take another look at the binding version.

    Thanks for the additional information 🙂

  • @P72endragon said in MySensors --> MQTT --> OpenHab 2.5:

    Thanks for the additional information

    Well since you replied I took another scan over the thread. 😉

    @P72endragon said in MySensors --> MQTT --> OpenHab 2.5:

    native OH MQTT

    I have been fairly involved over at OpenHAB forums (on and off; and I read a great deal in general) and the consensus amongst those in the know (last time I checked) seemed to be to use independent, outside MQTT broker.

    Personally I subscribe to "Unix philosophy" and since going the MQTT route have always run Mosquitto, but it was nice to see others confirming what I had suspected all along (that OpenHAB was trying to "do too much" with their built-in broker).

    @P72endragon said in MySensors --> MQTT --> OpenHab 2.5:

    I don't mind not having auto-discovery
    (although I'm not sure I understand quite how it works yet, still a little unclear on Items, Channels, etc)

    Getting your head around theOpenHAB concepts is one thing. Just try to imagine what it would take if you were designing a system from the ground up to abstract away a bunch of different incompatible systems into one unified control system, and you will be well on your way to understanding it. Thankfully their docs are very good and their forums are very active, including lots of examples.

    But main thing I wanted to touch on was config in text files vs. PaperUI. If you don't care about auto-discovery I can highly recommend the former. IMO, the PaperUI hides too much stuff from you, and I don't like that. All entries in there actually go into some internal database which you cannot edit (other than through PaperUI) and exists in parallell to your text files (which you can have in addition).

    So, what happens 2 years from now when you go to upgrade or install on a new system? Yeah good luck remembering what you did in PaperUI that you now need to re-do, in addition to all your text files which you already have. I read a lot of forum threads along such lines, and/or broken stuff after upgrades, etc...

    So for me, this time around, I spent the extra time doing complete text file configuration from scratch. And now I have a completely reproducible set of text files that I keep in version control and backed up. I could wipe the system and re-install no problem.

    As another upside, you really get to know the ins and outs of the system that way.

    In closing I will say that my MySensors Ethernet/MQTT gateway -> OpenHAB has been working flawless, and so to me appears to be the way to go. Come on in, the water is fine! 😄

    I actually even run the Mosquitto broker on a separate box from OpenHAB, it was designed from the ground up to be a network based architecture, so it really doesn't matter. In fact I don't even use MySensors binding in OpenHAB at all. Once you get over initial config (which is the challenging part) I believe it is actually the much better way to go. Which is another reason why I wanted to post this, as there is too much conflicting, old, and bad information out there on the Internet about this subject.

    That way no more relying on an outside party (MySensors binding developer(s)) for anything. They seem to me a bit overwhelmed (at least in the past). Not knocking them in the least, in fact I applaud their efforts. However personally I decided to remove that dependency from my system and it has proven to be a good decision.

    I would love to hear back from someone who is happy with their MySensors 2.5.x binding in OpenHAB. So if that is you, please speak up (and tell us your secrets! 🙂 )! I personally haven't seen any of those posts though, unfortunately...

    Anyway, post back whenever you get to that point, and I will be happy to share some up to date config snippets (or anyone else reading along). I was going to post mine but I just looked at them and realized they need some cleaning up first. Sorry!

  • Hi, sorry for the delay in replying, I got caught up on other things...

    I (think?) I'm using the MQTT2 binding in OH. In the PaperUI --> Add-ons --> Bindings, the only one showing as installed is "MQTT Binding (binding-mqtt - 2.5.4)".

    I'm running separate Docker containers for MySensors Gateway, Mosquitto and OpenHab.

    Since people seem to be using text files for configuration successfully, I'm going that route too (version control, scripted/automated builds, etc). These are the configuration files I've got so far (sanitised as appropriate):

    $ cat openhab/conf/things/mysensors.things
    Bridge mqtt:broker:Mosquitto "Mosquitto"
        Thing topic nodePrototype1 "Prototype Node" @ "Portable" {
                Type number : temp "Temperature" [ stateTopic="mysensors-out/1/0/1/0/0", unit="°C" ]
    $ cat openhab/conf/items/mysensors.items
    Number Prototype_Temp "Temperature" <temperature> {channel="mqtt:topic:Mosquitto:nodePrototype1:temp"}

    OH is successfully displaying the temperature in PaperUI, but I haven't tried to do anything with it yet...

Log in to reply

Suggested Topics

  • 22
  • 10
  • 1
  • 19
  • 3
  • 132