MQTT – setup and use
-
I have about 15 sonoff devices running Tasmota and ever since I flashed my first one years ago I planned to use MQTT but never convinced myself to get started as it works really good with Lua http calls and later the virtual http plugin and internal Tasmota rules for sensor reporting.
Now that I moved to openLuup and it has MQTT capabilities I really want to get it going but don't know how/where to start.
Anyone up for a short getting started with openLuup MQTT and Tasmota? That would be very much appreciated!Just wanted to say big thanks to all for the great work!
I've read all the progress with the broker and Tasmota bridge with joy and now managed to switch my Sonoffs from rules and Virtual HTTP Devices completely to MQTT using homebridge-mqttthing and Virtual Sensor plugin. -
Just wanted to say big thanks to all for the great work!
I've read all the progress with the broker and Tasmota bridge with joy and now managed to switch my Sonoffs from rules and Virtual HTTP Devices completely to MQTT using homebridge-mqttthing and Virtual Sensor plugin.Excellent news. Yes, I am using homebridge-mqttthing too, for my few-remaining Zwave devices bridged to openLuup from Vera. The Homebridge-Shelly accessory is also very functional.
All this means that the Apple Home app is my primary UI (well, actually secondary, since Siri on the HomePod takes care of most things.)
-
Awesome to see the MQTT implementation. Only if I could get myself the motivation to migrate to homebridge and get everything (Z-way/openLuup/HomeAssistant/Homebridge) to talk through MQTT instead of http as they are at the moment... It seems to be a lot of work...
For me too, the Apple Home app has become my primary (yet rarely used) UI.
-
Excellent news. Yes, I am using homebridge-mqttthing too, for my few-remaining Zwave devices bridged to openLuup from Vera. The Homebridge-Shelly accessory is also very functional.
All this means that the Apple Home app is my primary UI (well, actually secondary, since Siri on the HomePod takes care of most things.)
@akbooer said in MQTT – setup and use:
for my few-remaining Zwave devices bridged to openLuup from Vera
I'm trying to get rid of the old Vera plugin for Homebridge.
What topics do I put in mqttthing to get/set bridged Vera devices?
I got the "getOn" to reflect the status when I had luup.attr_set ("openLuup.MQTT.PublishVariableUpdates", true) in the Lua Startup Code, is that necessery for this purpose?
Do I need to write a handler for this?
I tried a generic handler but never got it to work.
Do you have an example of a handler if it's required? -
@akbooer said in MQTT – setup and use:
for my few-remaining Zwave devices bridged to openLuup from Vera
I'm trying to get rid of the old Vera plugin for Homebridge.
What topics do I put in mqttthing to get/set bridged Vera devices?
I got the "getOn" to reflect the status when I had luup.attr_set ("openLuup.MQTT.PublishVariableUpdates", true) in the Lua Startup Code, is that necessery for this purpose?
Do I need to write a handler for this?
I tried a generic handler but never got it to work.
Do you have an example of a handler if it's required?@crille said in MQTT – setup and use:
What topics do I put in mqttthing to get/set bridged Vera devices?
Depends what you want to get/set. Currently, I'm just using this for on/off switches, so using the mqttthing type
Light bulb - on/off
. I'm sure you can be more sophisticated, but I haven't tried it.As an example, I'll use a Vera-attached Zwave switch (device #30186 – it's actually a Fibaro relay, but it could be anything)
The first thing you need to ensure is that you have set the openLuup MQTT server to publish variable updates, using this line in Lua Startup:
luup.attr_set ("openLuup.MQTT.PublishVariableUpdates", true) -- publish variable updates
So, then, in order to reflect the relevant variable in the mqttthing you need in MQTT Topics :
- Get on –
openLuup/update/30186/SwitchPower1/Status
and in order to control it:
- Set on –
relay/30186
The relay command above is just a convenient openLuup shortcut to turn devices on/off which works both in MQTT and as an HTTP request.
That should be all for basic control.
- Get on –
-
@crille said in MQTT – setup and use:
What topics do I put in mqttthing to get/set bridged Vera devices?
Depends what you want to get/set. Currently, I'm just using this for on/off switches, so using the mqttthing type
Light bulb - on/off
. I'm sure you can be more sophisticated, but I haven't tried it.As an example, I'll use a Vera-attached Zwave switch (device #30186 – it's actually a Fibaro relay, but it could be anything)
The first thing you need to ensure is that you have set the openLuup MQTT server to publish variable updates, using this line in Lua Startup:
luup.attr_set ("openLuup.MQTT.PublishVariableUpdates", true) -- publish variable updates
So, then, in order to reflect the relevant variable in the mqttthing you need in MQTT Topics :
- Get on –
openLuup/update/30186/SwitchPower1/Status
and in order to control it:
- Set on –
relay/30186
The relay command above is just a convenient openLuup shortcut to turn devices on/off which works both in MQTT and as an HTTP request.
That should be all for basic control.
- Get on –
-
OK, latest development version (21.4.28c) has HTTP and MQTT requests to change a dimmer:
for device #51 to brightness level 42:
HTTP:
http://openLuupIP:3480/light/51?brightness=42
MQTT:
- topic:
light/51
- message:
42
There's been some fairly drastic internal refactoring of the openLuup API, but you shouldn't notice anything changed...
- topic:
-
OK, latest development version (21.4.28c) has HTTP and MQTT requests to change a dimmer:
for device #51 to brightness level 42:
HTTP:
http://openLuupIP:3480/light/51?brightness=42
MQTT:
- topic:
light/51
- message:
42
There's been some fairly drastic internal refactoring of the openLuup API, but you shouldn't notice anything changed...
@akbooer Wow, that was fast! Thanks, works like a charm.
May I bother you with my next issue? Every time I restart Homebridge my sensor values and current state of bridged devices are lost to mqttthing and shows 0 or OFF until there is an update from the device. Is there a way to retain the values from openLuup/update? - topic:
-
-
In my own broker I have a Vera/VeraID/update message causing an update from the bridge on demand. I find it useful when subscribing from my windows app, so I get all the updates. It’s similar to what Shelly or tasmota is doing. Maybe it’s easier to implement than retained messages.
-
In my own broker I have a Vera/VeraID/update message causing an update from the bridge on demand. I find it useful when subscribing from my windows app, so I get all the updates. It’s similar to what Shelly or tasmota is doing. Maybe it’s easier to implement than retained messages.
Thanks for that! I think the challenge in this case is that we are somewhat constrained by what the mqttthing is able to handle. It has some configurability, but I’m not sure whether we can use this approach. We will see.
-
Thanks for that! I think the challenge in this case is that we are somewhat constrained by what the mqttthing is able to handle. It has some configurability, but I’m not sure whether we can use this approach. We will see.
-
I have a Shelly plug and a Tasmota sensor.
I installed the latest OpenLuup version (21.4.28c)
I have the Shelly and Tasmota bridges that appear automatically, but I don't have the child devices.
Error message in the logs:2021-04-29 15: 02: 20.795 openLuup.context_switch :: ERROR: [dev # 75] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 20.795 openLuup.mqtt :: ERROR publishing application message for mqtt: tele / piscine / SENSOR: ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.216 openLuup.context_switch :: ERROR: [dev # 76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.217 openLuup.mqtt :: ERROR publishing application message for mqtt: shellies / shellyplug-s-20E453 / relay / 0 / power: ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.219 openLuup.context_switch :: ERROR: [dev # 76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.219 openLuup.mqtt :: ERROR publishing application message for mqtt: shellies / shellyplug-s-20E453 / relay / 0 / energy: ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.221 openLuup.context_switch :: ERROR: [dev # 76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.221 openLuup.mqtt :: ERROR publishing application message for mqtt: shellies / shellyplug-s-20E453 / relay / 0: ./openLuup/api.lua:148: attempt to index field '? ' (a nil value) 2021-04-29 15: 02: 21.223 openLuup.context_switch :: ERROR: [dev # 76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.223 openLuup.mqtt :: ERROR publishing application message for mqtt: shellies / shellyplug-s-20E453 / temperature: ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.225 openLuup.context_switch :: ERROR: [dev # 76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.225 openLuup.mqtt :: ERROR publishing application message for mqtt: shellies / shellyplug-s-20E453 / temperature_f: ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.227 openLuup.context_switch :: ERROR: [dev # 76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 15: 02: 21.227 openLuup.mqtt :: ERROR publishing application message for mqtt: shellies / shellyplug-s-20E453 / overtemperature: ./openLuup/api.lua:148: attempt to index field '?' (a nil value)
-
MQTT setting :
luup.attr_set ("openLuup.MQTT.Port", 1885) luup.attr_set ("openLuup.MQTT.Username", "*******") luup.attr_set ("openLuup.MQTT.Password", "*******") luup.attr_set ("openLuup.MQTT.PublishDeviceStatus", "0") luup.attr_set ("openLuup.MQTT.PublishVariableUpdates", true) -- publish every variable update luup.attr_set ("openLuup.MQTT.PublishDeviceStatus", 2) -- publish a single device status every N seconds (0 = never)
Devices 75 et 76
21 2021-04-29 14:56:51.444 75 Done 0.000 21 plugin: Tasmota OK 22 2021-04-29 14:56:51.444 76 Done 0.000 22 plugin: Shelly OK
Context after StartLuup
2021-04-29 16:53:44.403 openLuup.mqtt:: shellyplug-s-20E453 SUBSCRIBE to shellies/command tcp{client}: 0x184a658 2021-04-29 16:53:44.404 openLuup.mqtt:: shellyplug-s-20E453 SUBSCRIBE to shellies/shellyplug-s-20E453/command tcp{client}: 0x184a658 2021-04-29 16:53:44.404 openLuup.mqtt:: shellyplug-s-20E453 SUBSCRIBE to shellies/shellyplug-s-20E453/relay/0/command tcp{client}: 0x184a658 2021-04-29 16:53:44.404 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.404 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/online : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.405 luup.shelly:76: New Shelly announced: shellyplug-s-20E453 2021-04-29 16:53:44.405 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.405 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/announce : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.405 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.405 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/announce : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.406 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.406 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/relay/0/power : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.406 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.406 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/relay/0/energy : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.406 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.406 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/relay/0 : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.407 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.407 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/temperature : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.407 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.407 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/temperature_f : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.407 openLuup.context_switch:: ERROR: [dev #76] ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.407 openLuup.mqtt:: ERROR publishing application message for mqtt:shellies/shellyplug-s-20E453/overtemperature : ./openLuup/api.lua:148: attempt to index field '?' (a nil value) 2021-04-29 16:53:44.661 openLuup.server:: request completed (515424 bytes, 33 chunks, 272 ms) tcp{client}: 0x22f6cf8
-
Thanks – that shows exactly what I needed to see. The first incoming message from the Shelly is not an announcement, so the device doesn't yet exist. I knew this happened, but thought I had handled the condition. A recent change has made it appear again. I'll work on it...
-
Okay
Thank you for your work that I am with interest -
Okay
Thank you for your work that I am with interestCan you tell me what Shelly devices you are using here? Thanks.
-
Could you try the latest development version (21.4.29b) and see if that fixes the issue? Thanks.