TinyTuya Server #312
Replies: 7 comments 16 replies
-
A while back I ended up writing my own server-like program as I went in a bit of a different direction than the current server. It reads in a list of devices, opens persistent connections to all of them, and then monitors for updates. When an update is received it both forwards it on to connected clients and checks it against a list of device/actions and triggers other actions if the requirements are met. The client connections are currently a plain TCP socket it sends JSON over as the program it's talking to handles the WebSockets, but I am considering having it handle WebSockets natively as well (I use https://github.com/dpallot/simple-websocket-server to add WebSockets to things). I plan on releasing it once it's ready, but there are a few things which need to be finished and/or cleaned up first. |
Beta Was this translation helpful? Give feedback.
-
Hey, I love the idea of this server. I recently created a MQTT<->TinyTuya Bridge for a specific device (pool heat pump) using my own server script. This can be easily modified to communicate with server.py directly via HTTP instead of using tinytuya functions. This would be a seperate server process for the MQTT stuff, so developement can be seperated between server.py and the MQTT bridge. If there's interest, I can provide the modified script as a proof of concept. Let me know what you are thinking about that. What I would like to have in the server.py, too:
For the last two bullets we have to think about handling of unique names and maybe forbidden letters (space, special signs etc.). |
Beta Was this translation helpful? Give feedback.
-
Love it. Does your multiserver do the MQTT stuff or should I make a pull request for a seperate mqtt.py server which communicates with server.py via the API? |
Beta Was this translation helpful? Give feedback.
-
As a first step I added ability to use {DeviceName} instead of {DeviceID} in API calls, see PR #352 Next step will be to have DPS ID to Code (Name) mapping like e.g. IO Broker and FHEM uses with tinytuya. |
Beta Was this translation helpful? Give feedback.
-
This seems like a good place to discuss. I was about to start building a tool that takes devices and publishes them on MQTT. This server idea is good in that it exposes everything as a default via API (and potentially MQTT). I'm new to tinytuya so may be missing key concepts Some thoughts:
This leads me to what I wanted to do: I wanted to write an MQTT service that publishes the devices using the Homie convention to MQTT. This allows any device to being published to that topic to be autodiscovered by OpenHAB or anything else that uses that convention. Home Assistant also appears to have something similar called MQTT Discovery. It would have been good if they supported the standard though (though there may be some work and dsicussion in that regard). Below is an example of how Homie looks. You can see that the DP ID mappings etc. would be very useful in populating this quickly. One should then be able to quickly scan a network and publish all devices where the mappings are available easily as well all in one go in which case these devices will just pop up in any tool supporting the Homie convention and then be seamlessly added to those tools. You can see configured types as well as reporting whether a topic is "settable" that allows updates to be sent to the topic. One could also publish the raw DP IDs as well as a minimum in case mappings aren't available.
The Home Assistant version does similar things but uses json encoded config topics. Does one fetch these mappings for any device from the Tuya cloud or do we need to build up a database/dataset of these mappings per the README? |
Beta Was this translation helpful? Give feedback.
-
And until @uzlonewolf Server implementation is finished, you can use the MQTT Gateway here: https://github.com/jasonacox/tinytuya/tree/master/server/mqtt |
Beta Was this translation helpful? Give feedback.
-
I think we need to reorganise how the device mappings are fetched from the cloud. There are two lists returned from the cloud with mappings. We need to know which are writeable and/or readable to enable better automation of any API, or MQTT server that uses these mappings automatically. |
Beta Was this translation helpful? Give feedback.
-
I updated the server.py UI to make it easier to see the devices and control them. It is basic but useful for testing.
Future Enhancements?
I would like to improve the UI to make it more intuitive to control the devices. A nicer look would be good too.
python -m tinytuya server
type execution.Would love to hear from the community:
Beta Was this translation helpful? Give feedback.
All reactions