The best way to connect to OpenHAB


  • Hero Member

    In parallel with trying to get the radio library to work with my hardware, I started trying to connect this up to my openHAB installation. I will be connecting the Arduino gateway unit directly to a computer through USB, so a solution has to be able to talk to it through the serial port. As far as I can see there are two options for me:

    1. Use one of the MQTT gateway libraries available (which one?).
    2. Use the place and gateway Web server implementation created for openHAB implementation posted by someone a few months ago.

    Are there any other options I have missed and should be looking at?

    I already have a mqtt broker running on my server, so there is no overhead there. However, it seems a bit like overkill to put a mqtt client, a broker, and the mqtt binding between the serial gateway and openhab. Also, I'm not quite sure what kind of management functionality this offers as far as assigning IDs and so on.

    What do you guys suggest I do?


  • Code Contributor

    @kolaf Imo : mqttgateway (arduino + nrf24 + ethernet) (runs as a broker) and openhab mqtt client on a server πŸ™‚


  • Hero Member

    @Damme Thanks, but hardly surprising from you, I believe πŸ˜‰

    The problem is that I really don't want to hassle with connecting an ethernet shield when I can just plug the thing into my USB port. I'm more of a software guy than a hardware guy, so the less soldering, the better.


  • Mod

    @kolaf said:

    hassle with connecting an ethernet shield

    Take the Arduino UNO in one hand, the Ethernet shield in the other and plug them together. Done!

    1.jpg

    It's really that hard πŸ˜‰
    Even a software guy (like me) can do it!


  • Hero Member

    Hehe, but what about the radio? You need to connect that, too.


  • Mod

    @kolaf you need to connect the radio anyway, right πŸ˜‰


  • Hero Member

    @Yveaux I saw that earlier and it is one of the options I have been considering. But why do you use an ethernet gateway instead of a serial?


  • Hero Member

    @Yveaux said:

    @kolaf you need to connect the radio anyway, right πŸ˜‰

    Not if you're lazy like me and buy moteinos or anarduinos where everything comes in one nice, compact package πŸ™‚


  • Mod

    @kolaf my gateway is located downstairs an my server is in the attic. They're only connected using Ethernet, so for me it is the most logic solution.


  • Hero Member

    The anarduino with RF 69HW combined as up to only $15 which seems to me to be a reasonable price. Of course you need some headers as well, and an antenna, but still...


  • Mod

    @kolaf touchΓ©


  • Hero Member

    @Yveaux makes sense. Can your gateway speak the serial protocol?


  • Mod

    @kolaf said:

    @Yveaux makes sense. Can your gateway speak the serial protocol?

    It currently connects using sockets, but the protocol is identical, so it shouldn't be hard to use a serial connection.



  • For testing basic functions there exists another (rather crude) way - the serial binding offerd by OpenHAB. Adding :

       String Arduino   "Arduino [%s]"    {serial="COM6"}
    

    to an "items" file will do the trick. Accordingly a "rules" file should be expanded by something like :

       rule SplitMessage
       when 
    Item Arduino changed
      then
     <do some relevant processing>
    

    Using MySensors 1.4b (proMini, Uno, Mega.Leonardo) and OpenHab 1.5 (Windows 7 Notebook) produced very reliable results with SerialGateway connected via USB.

    You have to compile the sketches with Baudrate set to 9600 because OpenHAB deals only with this Baudrate (mentioned somewhere in the OpenHAB Documentation).

    So in Mysensors.h replace :

    #define BAUD_RATE 115200
    with
    #define BAUD_RATE 9600
    

    Because OpenHAB is not prepared to distribute NODE_IDs, you should hardcode this NODE-IDs. This decreases flexibility, but it is acceptable to some degree.

    This approach works well for reading sensordata as for writing to actuators. Currently I am using eigth Nodes (including Repeater) with serveral children (e.g. multiple DS18B20, multiple Door contacts, Motionsensor, DHT22 etc). Until now I havenΒ΄t enconterd serious problems.


  • Hero Member

    @tboha Thanks, that was very helpful. Do you have some more details for the mystical "do some processing"?

    @Yveaux how do you use the mqtt binding to talk to the sensors? I have looked into it, and must admit I have no idea on how to achieve this. It's apparent that you need some kind of transformation, but my understanding ends there. Specifically, I would like to implement a toggle switch, a switch that toggles a light every time it is activated instead of having a specific on and off state.


  • Mod

    @hek or @marceltrapman can you please split this topic starting at the openhab/mqtt examples into something like "OpenHAB & MQTT examples" please?
    Thanks!


  • Mod

    @Yveaux said:

    @marceltrapman can you please split this topic starting at the openhab/mqtt examples into something like "OpenHAB & MQTT examples" please?
    Starting from which post do you suggest the split?


  • Mod

    @marceltrapman said:

    @Yveaux said:

    @marceltrapman can you please split this topic starting at the openhab/mqtt examples into something like "OpenHAB & MQTT examples" please?
    Starting from which post do you suggest the split?

    Can you also join to an existing topic? In that case I'll create one -- that will make a clearer topic than just start in the middle of a discussion.


  • Hero Member

    For the record there is also this initiative where a smart guy has created a Python Web application to interface between the serial connection and openhab. He has even built in the functionality for handling node IDs.

    https://github.com/wbcode/ham

    It seems like there are three quite usable options for interfacing with openhab:

    1. The MQTT gateway
    2. Using the serial binding in openhab
    3. Using the python openhab gateway.

    The serial binding seems the best option for quick prototyping with its low implementation cost (no additional software) and high flexibility. One of the two other options seems to be a better long-term choice since they will be easier to manage on the configuration size as the network grows, I think. I like the concept behind the python gateway, but using the httpbinding to communicate with it seems a bit cumbersome. Ideally I would like to see this incorporated as an openhab binding, but I do not think it is possible to do the node ID assignment this way since the binding should be stateless.

    This leaves the MQTT solution which leverages technology that seems to grow in popularity. An additional benefit is that the author of the software is still around the forums as opposed to the case with the python gateway. The downside is that the item configurations seems a bit complex (at least to me), it is much easier to understand the serial binding or HTTP binding usage.

    It is a tough choice.


  • Mod

    @hek made me a forum moderator, so now I did the split myself πŸ˜‰
    Moved the topics regarding specific MQTT & Openhab usage to http://forum.mysensors.org/topic/302/openhab-mqtt-tips-hints
    There we can post some OpenHAB code and stuff, and this thread continues to discuss different ways to connect to OpenHAB.
    Still have to clean up the new thread a little, though...



  • Hi!

    Im a slow starter , but I been following the develompent here and over at http://www.byggahus.se/forum/villalarm-hemautomation/ for some time now but just recently I bought some z-wave things to play with and it's working quite ok now in OpenHab (windows 7).

    I have a question about using OpenHab as controller for mysensors that I want to double check before I dive in πŸ™‚

    1. Can I use Arduino Nano + Radio module as a gateway to OpenHab attached as usb ?

    2. Will it power over usb ?

    3. If so does that limit me to use the serial bindning or is MQTT still an option ?



  • Hi!
    I used an Arduino Nano (clone) as serial gateway to OpenHab, it worked without problems. Meanwhile I changed to an UNO-clone because the Nano fit better into its new task.

    Power over USB was not an issue, it worked flawless.

    The last question is a little bit ambiguous -
    Scenario A - switching between serial binding or MQTT (over serial/USB) does not require much work (depending on your installation). You even don't have to change a plug. I did this several times and it is a little bit annoying -but it works.

    Scenario B:
    Serial binding and MQTT binding of the same gateway in parallel - I haven't tried this, but you will probably run into trouble.

    Serial binding of the gateway and MQTT binding of a part of the messages of the MySensors network through a specialized node is not that difficult. It requires some strategy on programming the individual nodes (e.g. send this messages also to node xy which delivers these messages to a MQTT broker). The connection between this node and MQTT is serial/USB
    It doesn't make much sense to use serial binding and MQTT binding from the same source to the same target, but it makes sense (at least for me) when the target is different. (e.g. switching and feedback via OpenHab, collecting sensor information via specialized programs).

    If you see MQTT-binding as synonym for an Ethernet connection - I tried MQTT over Ethernet a long time ago and it didn't perform to my needs. There are new programs but i haven't tested until now. Switching between serial and Ethernet connection will probably cause the same amount of work mentioned above.



  • @tboha
    Thanks for clearing that out.

    I am not planning to run them in parallel but I do want a setup that allows me to switch controller(software) in the future and thats why I thought that MQTT was to prefer as it would allow me to easily switch but if I understand you correctly it is easy to change between MQTT and serial binding ?



  • @JimmyH : Yes, it is easy to swap bindings as well as controller. Easy - but it requires some labour. This labour is not complex, it just has to be done. In my specific setup it takes approximately 1-2 minutes per device.

    If you are using the serial binding in OpenHab it is tempting to perform some processing within the nested case statements (like I did). Retrospectively this was a really bad idea.

    I think it is a better idea to limit the use of these statements to dispatch the incoming data to the chosen Items - and nothing more.

    I had a hard time to get used to the functions of OpenHab ".rules" but at last it was worth the effort. Transfer every processing step into separate rules - it will make things easy.

    In an ideal scenario to switch between serial and MQTT (either serial or over Ethernet) you pull your USB-plug, activate your broker and you are done.

    Due to laziness and little other reasons I'm stuck with an inhomogeneous system resulting in the work mentioned in the beginning - it is tedious but i leads to the desired results.


Log in to reply
 

Suggested Topics

  • 22
  • 4
  • 132
  • 5
  • 10
  • 3

64
Online

11.4k
Users

11.1k
Topics

112.7k
Posts