TuyaDAEMON project
A two-way bridge between Tuya-cloud and node-red for custom extensions of Tuya ecosystem.
TuyaDAEMON isolates your custom node-red flows from all details of tuya/node-red data and commands exchanges:
allows bidirectional exchanges to/from all tuya devices and Tuya automations.decodes and transforms incominig Tuya data to standard units.manages all codifications and checks before sending your commands to Tuya cloud.updates the global.tuyastatus
structure (device:property:value) with status messages from all Tuya devices.logs all events in the mySQL 'tuyathome:messages'
tableuses frendly names for all devices and properties, in any language
If you are interested in the reasons behind the tuyaDAEMON's project choices, you can read why-tuyaDEAMON - In italiano: perché-tuyaDAEMON. note: To make links work, download the pdf file and use your viewer.
INPUTOnly one public entry point, for user commands (SET/GET/SCHEMA/MULTIPLE), the 'IN commands link' node (see). Command example (SET), it uses only frendly names:
{ "device":"USB siren",
"property":"alarm",
"value":"ON" }
OUTPUTnone: a client flow CAN get device data polling the global.tuyastatus
structure, RT updated or CAN get historical data from the messages
DB table.
User can define:
TUYA TRIGGERS from smartlife scene/event/alarm to fire custom node-red flowsRED TRIGGERS from node-red to fire smartlife automations.
Many internal I/O connections are available for private use and for tuyaDAEMON extensions.
IMPLEMENTATIONTo interact with Tuya devices I chose node-red-contrib-tuya-smart-device
, which uses tuyapi, the most interesting software on tuya<=>node-red integration that I have found. They do their job well, but there are some limitations:
- The capabilities of the Tuya communication are very variable for different devices: e.g. I have found very few devices that respond to
schema
request, and found cases where the data exchanges are not MQTT (e.g. infrared universal control). - Some devices are unreachables: TuyAPI does not support some sensors due to the fact that they only connect to the network when their state changes. Usually are WiFi devices battery-powered (see note).
- Tuya devices can update their own firmware version via OTA: for the user, this is an investment guarantee, but it can introduce problems when the software (
tuyapi
andtuya-smart-device
) is not updated: some device messages can't be decoded (see issue#17). - Tuyapi sometimes finds an error message from devices:
"json obj data unvalid"
: the source of this is not clear (see issue#246), but the best interpretation is "the required operation is not available". - Tuyapi throws some errors at the moment not caught by tuya-smart-device:
"Error: Error from socket"
and"find () timeout. Is the device turned on and the correct ID or IP?"
(see issue#35). Because now a tuya-smart-device can't be disabled, these useless messages can be very frequent. In normal use, some devices can stay disconnected long time, such as power sockets or power strips used only on request.
To manage such a rapidly changing environment, I choose to use a data structure in tuyaDAEMON to describe individual devices and single datapoint capabilities, so that all operations that are actually not managed or bogous can be intercepted and not sent to the device, giving stable and reliable operations with no surprises. And if the evolution of the SW offers us new features, it is easy to update the behavior of tuyaDAEMON.
A smart workaround, implemented in tuyaTRIGGER module, allows the bidirectional event communication also with all devices unreachables by tuyapi
(WiFi sensors, IR controls etc.). The TuyaDAEMON user is guaranteed that in all cases all tuya devices will be integrated.
TuyaDAEMON is very sperimental, the CORE module MUST be modified by user for every new device.
Any effort is made to make it modular, small, easy to modify and fully documented. All contributions and criticisms are welcome.
In tuyaDAEMON we have now four modules:
The start of tuya automations from node-red.The ability to fire node-red flows from smartlife, enabling node-red remote and vocal control.The management RT of 'mirror' devices
for all devices not caught by tuyapi.
- tuyaDEAMON CORE: the main flow, for communication with many tuya
'real' devices
, and also with devices using a gateway ('virtual' devices
) e.g. Zigbee sensors. - tuyaTRIGGER modulegive us some important features:
- This module, optional, uses a smart trick on a partially dedicated HW device.
- Connection module: add to all real device the new property 'connected' to report RT the device status. Optional.
- System module: Offerts a
'fake' device
(_system) with some useful RT properties: Alarms in case of WiFi, Lan or AC power down, list of unconned devices etc. Optional, requires the 'Connection module'. - Extra flow: "siren mirror", a
'mirror' device
study case. - Extra flow: "test devices" with some examples of device tests
- Extra flow: "tuyapiTRIGGER-minimal", to add remote and voice control to node-red. Use it alone, not for home automation.
In addition to usual configuration requirements for the nodes mySQL
and tuya-smart-device
:
you can edit it directly using the 'alldevices' config node.you can export it to the file alldevices.json
for backup or to edit it using external editors (e.g. Notepad++ and 'JSON Viewer' plugin) and back with copy-paste.Soon an application can produce an 'alldevice'
scheletron starting from a DB of tuya device definitions.For detailed definitions see global alldevices comment node debug
nodes can control the debug pad content: enabling/disabling them the user can modulate the visible information.filters
can reduce the info and the DB writing charge.see 'Debug pad options' comment node.
- CORE includes
global.alldevices
, a big JSON structure with all required information onreal/virtual/fake
devices, that control the CORE behavior on device/dps basis. Any new device must be added to it. To update/modify/edit this structure: - To reduce the workload in the production environment:
updated: see https://github.com/msillano/tuyaDAEMON/tree/main/tuyaDAEMON
versions
tuyaDAEMON version 2.0 (13/05/2021)
- General revision: core added OO and remote extensions, added 'share'. Refactoring '_system'., Updated wiki
- more custom devices (watering_sys, PM_detector etc.)
tuyaDAEMON version 1.0 (15/01/2021)
- node-red-contrib-tuya-smart-device 2.0.0
- tuyapi ver. 6.1.1
Initial version
Comments
Please log in or sign up to comment.