hongtat / tasmota-connect

Add your Tasmota devices as SmartThings devices
GNU General Public License v3.0
86 stars 171 forks source link

No support for MQTT management or discovery #22

Open shevett opened 3 years ago

shevett commented 3 years ago

I have been rolling Tasmota devices into my home network for a bit now, and was pleased to see that tasmota-connect allowed me to add a tasmota device to Smartthings. However, the code as it stands now does not support MQTT management of Tasmota devices. This is a serious limitation.

As it stands now, to add a new device, you use the app on the phone to add the devices fixed IP address, login information, and device type. This has a number of drawbacks:

Fortunately, Tasmota supports using MQTT for device management. This is not the 'bridge' model that is used by some interfaces to control devices via MQTT commands. Tasmota uses the pub/sub model to collect, query, and control devices via MQTT topics.

As noted here: https://tasmota.github.io/docs/MQTT/ "MQTT is the main protocol for controlling Tasmota devices"

For Tasmota-connect to scale properly, it needs to have MQTT support added. This would make management of devices infinitely easier, and would not require tremendous changes.

There are several examples on the net of using MQTT via Groovy to communicate with Tasmota devices. As a first easy-to-define function, I'd suggest looking at using the HomeAssistant discovery model to query MQTT to list Tasmota devices. Any devices that come back from that query get added to the device list in Tasmota connect. This would go a LONG way to making management easier.

Once discovery mode is enabled, command and control can shift from direct socket connect to the Tasmota device to sending / receiving commands via MQTT. This can be done after the discovery mode is implemented. Once this is complete, direct connect to the Tasmota devices will not be necessary from the smartthings hub. See https://tasmota.github.io/docs/Home-Assistant/ for details on how to use the Tasmota Integration in MQTT to discover devices.

Would this feature be possible to implement? Without it, I think tasmota-connect will not scale well.

hongtat commented 3 years ago

Hello,

To add support for MQTT, it requires user to install a MQTT broker.

The purpose of this software is to provide a pure integration between Tasmota & SmartThings, i.e. the user doesn't have to install additional hardware or software. And for this to work correctly, it requires the Tasmota devices and SmartThings hub to be assigned with static IP addresses.

If you prefer MQTT based solutions, I believe there are a few alternatives.

shevett commented 3 years ago

I think it would still be worthwhile to put the possibility in of using an MQTT broker. You have 90% of the code there, it would be a matter of just adding the MQTT library, login credentials and address of the broker, and then subscribing to the topic. In the client, just look for the discovery information from the devices, and you have an auto-populated list of tasmota devices.

If there is another smartthings app that does this already, I'll use that, but I don't know of one off the top of my head. Got a pointer?

hongtat commented 3 years ago

I believe there is still no MQTT client in SmartThings.

MQTT based apps require a MQTT bridge, similar to this. App that does auto-discovery would require modification to Tasmota firmware.

Or you could also write custom firmware to communicate directly with ST platform over MQTT. Link

Home automation (ST, HASS, Hubitat, etc) communities have more information/ideas on how to integrate Tasmota.

shevett commented 3 years ago

App that does auto-discovery would require modification to Tasmota firmware.

This is incorrect. Tasmota discovery is handled via the HomeAssistant discovery tools - SetOption19 0

https://tasmota.github.io/docs/Home-Assistant/ :

Once you configure the Home Assistant integration every new Tasmota device with SetOption19 0 set, will be discovered automatically.

I need to research some more what the state of the MQTT tools are, I am not sure the bridge is needed to get a discovery response from the app (since it's a synchronous query to MQTT - not a triggered event). I'll followup when I have more information.

hongtat commented 3 years ago

Because there is no MQTT client in SmartThings, ST smartapps which communicate over MQTT require a bridge (a MQTT client hosted outside of ST hub) to translate the messages between MQTT device/broker and ST.

ST/Hubitat-Tasmota smartapps that do Tasmota discovery use custom Tasmota firmware, and they use HTTP/TCP to communicate with the hub, they do not use MQTT.