Connect MySensors to OpenHab with MQTT gateway on a Raspberry Pi



  • I am working on creating a network of arduino sensors using MySensors which will be controlled/monitored using OpenHab. I have two Arduinos working as nodes and a Raspberry Pi acting as an MQTT gateway. So far I have one Arduino with a button connected to it. When I push the button, I see a message sent in the node's log and I see a message received in the gateway's log, so all is well there. I also have OpenHab setup on my Raspberry Pi and I was able to make a basic sitemap that shows whether or not my phone is online. I also have Mosquitto correctly installed. The problem is, I don't know where to go next. How do I get communication between MySensors and OpenHab?


  • Hero Member

    If you want to use the binding have a look here: https://github.com/tobof/openhab2-addons/wiki



  • As mentioned there is an OpenHab binding you can take a look at.

    I started using OpenHab long before this binding was available so my setup is to use the OpenHab MQTT binding.

    Technically it is quite simple, you seem to have all what is needed. OpenHab and Mosquitto can run on the RPi and a MySensors MQTT gateway sends the sensor messages to Mosquitto over your network. The Mosquitto passes all messages on to OpenHab.

    Now my gateway is based on WiFi using a Wemos Mini or other ESP based board. I have also used an Ethernet MQTT gateway without any problems.

    At the OpenHab side you need to create Items which listen to the MQTT messages and then the OpeHab rules can act on these messages and display results using the OpenHab sitemaps.

    There is a lot of info available about how to set all this up so Google plus MySensors and OpenHab docs/forums will give you the details needed.

    This rough description outlines one "manual" way of connecting to OpenHab. Also the serial gateway can be used but I think MQTT is the best option. I presume that the mentioned binding can simplify things but I have no experience of that approach.



  • I am also using almost the same setup as @mbj above. The main difference being that I am using an external cloud MQTT broker, not Mosquitto locally. The reason for that is that I actually have two MySensorsMQTT GWs running in two different geographical locations and I don't want to expose a local Mosquitto server inside my network. They publish their messages on two different topics in the cloud service and OpenHAB subscribes to both. One GW is ESP-based and connects over WiFi. The other is Arduino-based and connects over Ethernet.

    The OpenHAB MQTT binding can subscribe to two different MQTT streams.

    I have found that it is very helpful to have an MQTT test tool available so that you can test both the publishing and the subscription functions on either side. I am using MQTT.fx very good and free of charge!

    But then, as @mbj said; I also started long before the other binding was available.

    So, @mtnbikerjoshua if you want to follow this path, the next thing to do is to have your MQTT GW publish the topics to your Mosquitto server. Then using the OpenHAB binding, Openhab shall subscribe to the same topics. This is when it is so nice to have the test tool. You can test one half of the connection at a time. If you have not done this, you should read up on the MQTT protocol. There is plenty of stuff to read on the net.



  • I'm using the OH2 2.2 MQTT binding, but it's not discovering anything when I scan in Paper UI. Any tips?
    My setup: RPi W, Dietpi stretch, Mosquitto, mysgw 2.2.

    I manually added the thing for the MQTT gw because it was not discovered after following the instructions in that thread.

    My next step is to build one sensor for extra testing. But I'm having problems with "simple password". I configured mysgw without them to sort out problems.
    To reconfigure mysgw I have to run the "./configure" command and "make", but do I also have to do "make install"? And do I have to re-start & enable the service?

    Thanks!



  • As far as I understand the MQTT binding for OH is still version 1.x and does not support discovery of items via PaperUI. I have added all items via the .items file.

    On the other question I cannot offer any support, sorry.



  • @bgunnarb I thought this was 2.2: https://forum.mysensors.org/topic/8201/openhab-2-2-binding-mqtt-support

    Are you using the older binding? I'm doing battle with signing at the moment, so that could be holding up the function of OH2 as well.



  • @masmat Yes. I am using the old 1.x binding. I have not tried the 2.x version.



  • @masmat Also I use the "native" OpenHab MQTT binding (my version is 1.11.0) and it works really well with OpenHab 2.2 but , as @bgunnarb says, it is a manual procedure to define the items.

    I have not tested the MySensors OpenHab binding because I have a number of sensors of own design which I guess will need quite a bit of redesign to fit into this picture, if at all possible without modification of the binding.

    I have not tried the Pi as a gateway so cannot comment on your second question, unfortunately. As the Arduinos and ESP work well as gateways and my Pi already serves OpenHab and Mosquitto I will keep it that way.



  • @mbj I think I finally solved the GW problem (signing password too short!).
    Now I'm starting to deal with OH2. I'm seeing this in the log:

    2018-04-03 00:10:59.717 [DEBUG] [rotocol.mqtt.MySensorsMqttConnection] - MQTT message received. Topic: mysensors-out/99/0/1/0/1, Message: 15.0
    2018-04-03 00:10:59.747 [DEBUG] [rotocol.mqtt.MySensorsMqttConnection] - Message topic part: 99/0/1/0/1
    2018-04-03 00:10:59.758 [DEBUG] [rotocol.mqtt.MySensorsMqttConnection] - Converted MQTT message to MySensors Serial format. Sending on to bridge: 99;0;1;0;1;15.0
    2018-04-03 00:10:59.768 [DEBUG] [rsAbstractConnection$MySensorsReader] - Message from gateway received: 99;0;1;0;1;15.0
    2018-04-03 00:10:59.777 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Node 99 found in gateway
    2018-04-03 00:10:59.785 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Child 0 not present in node 99
    

    I have one node sending temp & hum data (DHT11: child 0 hum, child 1 temp). OH2 wont autodiscover. Does this mean it must be added manually?
    I hope there's an autodiscover if I'm going to build a network....


Log in to reply
 

Suggested Topics

  • 22
  • 5
  • 135
  • 1
  • 7
  • 132

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts