(Last Updated: July 28, 2020)

MQTT Plugin



  • I am looking at making openLuup to act as an MQTT client for a variety of applications. I may write a plugin for it myself based on either of these two libraries:

    Still have to learn the details of how it would work. If people have ideas, feel free to post here!





  • Thanks, I also found this older plugin and am looking at how to implement it...



  • You were looking at this stuff nearly a year ago... what's taking so long? 😉



  • Only if you knew!! ha! Back then it was to integrate other zwave platforms I think... Guess what distracted me... 😛
    Now I am looking at getting events from watsor for object detections from my IP cameras. My memory is getting more and more challenged... I have to learn a bit about how mqtt works. I actually had setup a broker way back then.



  • Well.. this plugin only serves to subscribe vera variables and post them into an mqtt broker. It does not get the messages from it and report them into openLuup. It is the opposite of what I am trying to do...



  • Ah well, it’s good, at least, to know what is out there, and whether or not it fits your needs. (Not, in this case.)



  • Indeed it could have been good base for a new plugin though but I am leaning towards starting from scratch. The code is quite aged...



  • making progress 🙂

    Screen Shot 2020-07-21 at 16.06.31.png



  • I write one by myself (in c#) to use Tasmota, Shelly and similar devices.

    I think MQTT is very useful in order to integrate external things.
    I like the idea of a full bridge, to send updates from openluup to a broker, and act as a broker. It’s fantastic for near time updates.



  • @therealdb

    I will have a simple sensor plugin ready to share in the next few days I think. It will subscribe to an MQTT topic of your choice and respond to the payload change by tripping/untripping the sensor.
    Sending updates from openLuup has existed for quite some time now as the plugin above subscribes and publishes topics generated from openLuup variables. A full bridge should probably do both...
    I will be using the pure lua mqtt library on luarocks as it appears to be maintained unlike all the other approaches I looked at.



  • I use them a lot for temperature, humidity, luminosity and binary inputs, but I also have one near the pool that’s turning on the lights and provide pool temperature. It was too far for Zwave, but it’s ok for WiFi (I have an outdoor access point anyway). That’s why I started developing my virtual devices, after all.



  • So I am running into a lua problem with creating this plugin:

    Threading or the lack thereof. I can probably try to use a co routine but I am seeing that opening an MQTT listener client hangs up openluup as it would just occupy the main thread I guess. How should I spawn a listening thread without blocking openLuup?



  • @rafale77 Have you seen this mqtt plugin? i have been using it to subscribe to topics for some time. Maybe it has some hints as to your issue.



  • Maybe you know, maybe you don't. I use this explore to view real time events and topic updates on my broker:

    Very handy to discover topics, see updates etc.



  • Thank you,

    It is actually a forked version of the plugin @akbooer shared as well and...

    "This plugin provides the ability to publish out any user defined variable to an MQTT Broker."

    Which again is not what I am trying to do. I am trying to get a client to subscribe and read messages. Not to publish which involves for the plugin to be constantly connected to the broker and listen.



  • @rafale77 It does allow you to subscribe.

    You can subscribe to a topic by creating a child device :

    Add a new device and choose a type (e.g. "D_BinaryLight1.xml" or "D_TemperatureSensor1.xml").
    Reload LUUP engine.
    Change the attribut "id_parent" with the id of the MQTT plugin device.
    Reload LUUP engine and refresh your browser.
    You should see variables "mqttTarget" and "mqttTopic" in your newly created device.
    Set the topic you want to subcribe to and the target (format: service,variable=(formula in LUA)).
    Reload LUUP engine.
    If the payload of the received message is in JSON, the plugin will try to decode it and put it in the variable "payload" in the context of the LUA formula.



  • I will look into it. Thanks... I am so close with my own plugin though...



  • I thought it might help with writing your plugin. Looking forward to see what you come up with.



  • Well I learned something from it. My problem with opening the listening client was not due to cpu threading but because it was blocking the socket. Unless I want to proceed with a polling strategy, this particular library is not going to work... Ohh well, back to square one with a different library.


Log in to reply