Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tinytuya2mqtt heads up #136

Closed
mafrosis opened this issue May 23, 2022 · 3 comments
Closed

Tinytuya2mqtt heads up #136

mafrosis opened this issue May 23, 2022 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@mafrosis
Copy link
Contributor

I made this on the weekend: https://github.com/mafrosis/tinytuya2mqtt

Basically I didn't really get on well with localtuya for a variety of reasons, and figured this decoupled approach might be more palatable. I'll run it in for a few weeks in my home automation setup and fix any bugs that come up.

Although the code is very coupled to my set up (using 2 tuya fans), the bones of the code are there to extend this to support more different devices.

@jasonacox
Copy link
Owner

I love this @mafrosis ! I have been thinking about building a TinyTuya service that constantly monitors the network for UDP discovery traffic (does Tuya device IP/DI mapping to known keys from devices.json) and takes/sends events on devices as requested. Fronting this with mqtt is perfect. I am very interested to see how your project develops. I may start less device focused and build a core service out of TinyTuya first, but I think it would easily fit within your project and goals.

I know the maintainers of localtuya and we originally discussed combining efforts. We both focus on making "local access" to Tuya devices as the goals. However, their mission is to deliver a tightly integrated Home Assistant library where my mission, like pytuya, is to deliver a common, easy to use API for Tuya devices for all projects. We still trade some discoveries and the communities do overlap, but our goals are slightly different.

I may have some time this weekend to look at this more. Thanks for raising this.

@mafrosis
Copy link
Contributor Author

Using UDP discovery is a really interesting idea. Happy to try something out on my network when you have some code available.

The localtuya project was where I started, but I found it unreliable in retrieving device status (my fans were always "unavailable" in Home Assistant). The tight coupling makes it quite hard to debug, and the GH issues for that project are full of people with similar problems. Enter tinytuya.... A few lines of code later and I had reliable control of my fans/lights..

The idea for my little script was use MQTT autodiscovery as a "bridge" between HA and tinytuya. That means you don't need the tight-coupling of localtuya to get the tight integration with HA. Your project's API can develop independently of HA and the interface between the devices and HA is also completely uncoupled via MQTT - which makes it very easy to debug problems.

Anyway, it works for me today, but the success/future of tinytuya2mqtt depends on if anyone else wants to help extend the discovery / device capabilities.

@jasonacox
Copy link
Owner

@mafrosis I have a start on a TinyTuya API server. It has a continuous thread monitoring for Tuya discovery UDP packets to map ID to IP. It also offers up a way to poll or set devices via API calls. Could this help with your bridge?

@geNAZt mentioned an HA bridge too in #143 about adding new devices - take a look at @mafrosis project too.

@jasonacox jasonacox added the documentation Improvements or additions to documentation label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants