MQTT Plugin
-
@rafale77 said in MQTT Plugin:
The fundamental problem is that setting up an MQTT client to listen to the broker blocks the luasocket and therefore openLuup.
The two libraries use different approaches to the problem.This just sounds like a lack of understanding on behalf of the module authors, ...or possibly me. I can’t believe that it could possibly be so difficult.
These are the two libraries you referenced st the start?
-
@akbooer
Or it could very well be that I missed something but looking at reports from github, I am not the only one observing it. These library work very well for publishing to the broker. They don't work unless you want to dedicate an instance of lua to be the listener...
@therealdb
This could potentially be the base for a bridge to so many things for openLuup!! -
@rafale77 I have a simple version almost ready. I'll debug later today or tomorrow, and put on GitHub. Here's an excerpt of the config:
{ "MQTT": { "Username": "vera", "Password": "openluup", "Port": 1883 }, "Devices": [ { "Name": "Pool", "ClientID": "sonoff-pool", "TopicName": "tele/tasmota/SENSOR", "TopicPath": "AM2301.Temperature", "DeviceID": 12, "Service": "urn:upnp-org:serviceId:TemperatureSensor1", "Variable": "CurrentTemperature" }, { "Name": "DeHumidifier", "ClientID": "tasmota-dehum", "TopicName": "stat/sonoff/POWER", "TopicValue": "ON", "DeviceID": 12, "Service": "urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "Variable": "ModeTarget", "Value": "HeatOn" }, { "Name": "DeHumidifier", "ClientID": "tasmota-dehum", "TopicName": "stat/sonoff/POWER", "TopicValue": "OFF", "DeviceID": 12, "Service": "urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "Variable": "ModeTarget", "Value": "Off" } ] }
I think it's more than enough to understand how the things will gonna work
-
@rafale77 hey Rafale,
I went down the very same road a while back and threw in towel because the polling by the MQTT plugin created CPU drags that stopped openLuup from functioning "reliably". The instability was also in part because I use two other must-have plugins that rely on polling, and I imagine that the combination of the three was creating a scenario that caused intermittent failures. And I too ended up implementing MQTT in Home Assistant and then using RealDB's virtual HTTP plugin to send commands to my WiFi devices--albeit not knowing the status of the devices in openLuup after the send.
I'm looking at RigPapa's socket proxy and WebSocket plugins to see if I can transform my polling plugins to Async. The MQTT plugin is too complex for me to convert though, so if you take a crack at it, and are successful, I would very much appreciate you publishing your results, as MQTT is becoming a must for me.
-
I was also thinking about using a proxy for this but it is really adding a layer of complication. For MQTT it might be work it though, I think @therealdb 's solution is likely a better approach... basically also kind of a proxy written in C to act as the client and seems to be very lightweight.
-
I had a brief health problem in the latest days that put me completely KO, but I'm recovering. Code is almost done, I just need some time to test it under load and write some doc. I hope to finish it later today.
-
here we are: https://github.com/dbochicchio/luup-mqtt
Try it and let me know. It should be easy to acquire .NET Core SDK and build the app. It's very minimal, fast and should be easy to understand. Right now it's only updating variables (with virtual device I think it's more tha enough), but I could add other actions if needed.
-
Thank you! I will be testing it shortly now that I am done with my object recognition component and fixed a couple of network issues.
-
Hi Guys,
Was on the Lobo beta using Owntracks that Rigpapa was running but he killed it to focus on other projects. I have MQTT broker (Mosquitto) running on my rpi but can't figure out how to get MQTT data into a virtual switch on Vera. Did you ever get this working? Are there compiled files anywhere I can load on my Vera or openluup device?Roger
-
I'm using it exactly for OwnTracks (well, a forked version based on this). I could publish compiled binaries for sure if you are interested.
Since OwnTracks is publishing raw data, you'll need something (ie: some code in a scene) in order to really parse the lat/lon/accuracy and update a virtual sensor.
-
Thanks, that would be great.
-
@therealdb I finally decided to try and setup MQTT for my Tasmota and Shelly devices.
After having built the bridge i.a.w. the instructions I have copied it to my Ubuntu PC that also is running OpenLuup. I put all the files in a folder in "Home" and given permissionssudo chmod -R a+rwx /path/to/folder
.
(I built the files on my Win 10 PC in an Ubuntu WSL including-r linux-x64
.)The Tasmota test device I use says "MQT: Connected" in the console so it seems that it connects to the bridge when it starts. I also set up MQTT Explorer and it also connects to the bridge and shows the topics from the Tasmota device.
Despite this no temp value is set for the virtual sensor in OpenLuup I use for the test.
I have double checked the topic name, the topic path and the OpenLuup information and it seems correct.appsettings.json:
{ "MQTT": { "Username": "luup", "Password": "openluup", "Port": 1883 }, "Luup": { "ipAddress": "127.0.0.1", "port": 3480 }, "Devices": [ { "ClientID": "tasmota_test", "TopicName": "tele/tasmota_test/SENSOR", "TopicPath": "AM2301.Temperature", "DeviceID": 216, "Service": "urn:upnp-org:serviceId:TemperatureSensor1", "Variable": "CurrentTemperature" } ], /* remove comment when you're OK with less logs "Serilog": { "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Fatal", "System": "Fatal" } } } */ }
Sensor topic on Tasmota console is posted when Tasmota posts the data:
13:58:05 MQT: tele/tasmota_test/SENSOR = {"Time":"2021-01-28T13:58:05","AM2301":{"Temperature":23.5,"Humidity":37.3,"DewPoint":8.1},"TempUnit":"C"}
The log file says:
2021-01-28 12:51:57.992 +01:00 [INF] [MQTTServer] Broker is starting on port 1883... 2021-01-28 12:59:21.709 +01:00 [INF] [MQTTServer] Broker is starting on port 1883... 2021-01-28 13:55:27.236 +01:00 [INF] [MQTTServer] Broker is starting on port 1883... 2021-01-28 13:57:48.402 +01:00 [INF] [MQTTServer] Broker is starting on port 1883...
Any ideas on what could be wrong? I have most likely missed something obvious.
//ArcherS
-
Sorry, nothing to suggest. I took a look at the MQTT code and while ago and it's rather poorly written.
FYI, though, I am in the process of writing a Shelly bridge for openLuup, which will have its own MQTT server and be able to automatically create configured devices for any Shellys that use it.
Turns out that it's rather easier to write a minimal MQTT server than it is an MQTT client.
-
Just to clarify, what I installed was the stand alone MQTT Bridge from @therealdb and not the old MQTT plugin. Perhaps it was a bit confusing of me to post it here...
I agree that MQTT in some form for sure is a great addition to OpenLuup and Shelly/Tasmota devices.
Automatically adding devices sounds promising!//ArcherS
-
It uses the paho/mqtt library and utilities (albeit updated to v3.) I thought of using that as a base, but after inspection, started from scratch.
Yup, the only config would be to point the Shelly device at the server.
-
@ArcherS I did some tests. here's what I got:
[09:08:32 VRB] [MQTTServer] Message Received... [sonoff-pool] - tele/tasmota/SENSOR - {"Time":"2020-07-26T08:21:19","DS18B20":{"Id":"02131D86D0AA","Temperature":25.3},"TSL2561":{"Illuminance":0.049},"SR04":{"Distance":45.421},"TempUnit":"C"} [09:08:36 VRB] [MQTTServer] Processed message: got 25.3 [09:08:36 VRB] Matched value [09:08:37 VRB] [LuupWrapper] Calling Uri: http://127.0.0.1:3480/data_request?id=variableset&output_format=json&DeviceNum=501&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value=25.3&RunAsync=1 2 [09:08:37 VRB] [MQTTServer] Message Received... [dbdomoticz] - owntracks/update/daniele - {"t":"c","tst":1611145530,"acc":65,"_type":"transition","event":"enter","lon":xx.615871,"topic":"owntracks\/DB\/daniele\/event","lat":xxx.995452999999998,"wtst":1610963724,"tid":"DB","desc":"Home"}
So, you should see at least the commands being reported. Check for permissions for the deamon and look at the console logs of your device. Maybe there's something (username? password? that's not correct.
EDIT: I just pushed a new release updated to .NET 5. Just get the new SDK, the build procedure is the same.
-
@therealdb the permissions etc look right, also username password are correct, I get "connected" in the Tasmota console, so it seems to connect.
Is your log above from the MqttBridge logfile? If so I cannot see it, it only says:
2021-01-28 12:51:57.992 +01:00 [INF] [MQTTServer] Broker is starting on port 1883...
I think i will try to build it again. When looking in github I cannot see any updates to the files for some reason.
//ArcherS
-
@archers crazy days at work. push is in progress.
yes, this was from my own logs (where I attached owntracks as well - via a mqtt realy I have to test things around that's pushing mqtt messages from my prod system to my test ones).
-
ArcherSreplied to therealdb on Jan 29, 2021, 2:12 PM last edited by ArcherS Jan 29, 2021, 9:15 AM
@therealdb I tried to buid again from the new files, but I cannot get the Luup.MqttBridge to run the way it did before the update.
Unclear what is wrong, I think I did everything in the same was as before. I noticed that the icon on the Luup.MqttBridge file is different when looking at it in Ubuntu "Files".//ArcherS