GithubHelp home page GithubHelp logo

msillano / tuyadaemon Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 3.0 35.52 MB

A generic IOT framework, open for all user node-red devices and for any advanced custom logic, with some unique features: rich in interfaces (MQTT, REST, DB), OO oriented plus the ability to integrate ALL Tuya devices without hacking.

License: GNU General Public License v3.0

tuya-device node-red tuya-automations tuya-cloud smartlife flow sensors wifi vocal-interface mqtt

tuyadaemon's Introduction

TuyaDAEMON's primary objective is not merely controlling some devices or providing a unique user interface. Instead, it focuses on seamlessly integrating the entire Tuya ecosystem into node-red, thereby establishing a new level of abstraction encompassing the Tuya cloud, any IOT device of every brand, any custom device, REST, MQTT, DB, and extended automation logic. TuyaDAEMON serves as an open framework for advanced custom IoT development.

Tuya ecosystem:(source Tuya)

TuyaDAEMON is a powerful and versatile IoT development framework that can be used to create a wide variety of projects. It is easy to use for beginners, but also has powerful features that appeal to experienced developers.

Advanced features that make tuyaDAEMON unique

TuyaDAEMON has some unique features that make it stand out from the competition. These features include:

  1. Open, modular, full documented: expressly designed for every customization need.
  2. TuyaDAEMON is borns to work with any Tuya device without hacking, but it is also open to all devices, custom or from other firms. This makes it a more flexible framework than some of its competitors (see 'study cases' on wiki).
  3. ObjectOriented approach that makes it easy to create complex projects.
  4. Powerful control meta-language (command chains) with an expressive power (Turing complete) not found in other IOT environments, usually limited to "IF ... THEN" automation (see also here).
  5. Meta-tools for device test, maintenance, and documentation activities.
  6. Applications and programmer's notes repository.

If you are looking for an IoT development framework that is powerful, versatile, and easy to use, then TuyaDAEMON is a good option to consider.

All the details of the communication with devices are resolved by tuyaDAEMON, using 4 bidirectional communication channels transparently to the user:

LOW LEVEL MQTT (see tuya DEAMON core + CORE_devices)

Using node-red-contrib-tuya-smart-device you can exchange local MQTT communications with many Tuya devices. You receive notifications of device status changes regardless of the cause: Tuya-cloud, smartlife app, or voice control. And vice versa, the commands sent by tuyaDAEMON are executed by the devices, and all the app interfaces are kept updated in real-time.

HIGH LEVEL TRIGGER (see tuyaTRIGGER + MIRROR_devices)

The TRIGGERs do not connect to individual devices, but create a direct and bidirectional connection with Tuya-cloud events and 'automation', allowing complete control from anywhere of both the smartlife logic and the devices not handled by LOW-LEVEL MQTT channel. In the cases where a device relies on cloud servers (see Tuya info) user can define 'mirror' devices: see 'Smoke detector' case-study) to access the features of the device.

Example: Using a “Smart Home Infrared Universal Remote Controller” device you have replicas of the various remote controls on your smartphone, even better than those I had developed in 2016 (see remoteDB). Very well: thanks to Tuya I can now control 2 televisions, a monitor, an air conditioner, a DVB tuner, and a TV top box from my smartphone! There are some limitations: voice commands cannot be used, moreover, since the device does not use the MQTT protocol, it cannot be controlled at the LOW LEVEL. However, Tuya-cloud resources can be used to create a 'scene' with the sequence of commands needed to tune a TV channel, e.g. "Rai 3 HD", on the living room television. As the icon, I will use the RAI3 logo, as the name: 'tune RAI three'. Now I can use the voice command: "Hey Google, run tune Rai three"! A "mirror" device standardizes this behavior in tuyaDEAMON, using TRIGGERS to execute commands. I can now create Node-RED automation, which, if I am at home, automatically turns on the television and tunes in RAI 3 when my favorite TV series is on the air!

              tuyastatus: object
                    living.tv: object
                         tvchannel: "RAI3 HD"
                         comment: "available: 'RAI1 HD’,’RAI2 HD’,’RAI3 HD’..."

LOW LEVEL OpenAPI (see device core_OPENAPI)

Since Ver 2.2.4, this new optional communication channel for Tuya Cloud can be used only in essential cases, to minimize the TuyaDAEMON's dependences on the evolution and strategy of Tuya Cloud. Doing complete access at all APIs, via REST, can be used for reading the device's status, for sending instructions to devices, and for accessing some non-basic aspects of device control (e.g., spaces (home), groups, automation) not manageable via TRIGGER + Automation.

CUSTOM CHANNEL (see system and 'fake' devices)

Simple node-red flows constitute the interfaces to HD and SW resources, allowing the insertion of external devices, not Tuya-compatible, into the system. A very useful two-tier model, consisting of a first-level represented by tuyaDAEMON processor, which standardizes the various sources and devices, to provide all data and commands in a homogeneous way to the higher application level (see TuyaDAEMON application model).

Custom channels are implemented additively with specialized flows, to implement 'fake' devices.

In many cases, the required interface is a simple protocol adapter, like in case of MQTT devices or in case of PM detector, a device that uses USB-COM interface.

In the case of the '433 MHZ sensor gateway', the module includes a specialized adapter for each device, such as the weather station which uses 3 sensors (temperature, wind, rain).

Since version 2.0 the generalized OO perspective, in a distributed environement, adds more power to tuyaDAEMON. It is easy to finalize the tuyaDAEMON resources in integrated projects, OO-oriented, with UI and many base devices: see as an example the device watering_sys, a terrace watering timer with UI, fuzzy control from wheater, build using 3 tuya devices.

From version 2.0 tuyaDAEMON is a complete framework for advanced custom IOT projects.


node-red interfaces

TuyaDAEMON has a high-level interface for custom node-red logic and applications: in reading, the data of all devices are available in an RT updated global object (´tuyastatus´), with a device:capability:value hierarchy and names were chosen by the user. Example:

              tuyastatus: object
                   humidifier: object
                       _connected: true
                       spray: "OFF"
                       output: "small"

In writing, the commands for state change requests to all devices take the form of a node-red message:

              payload: object
                    device: "humidifier"
                    property: "spray"
                    value: "ON"

REST interfaces

To make easier the interoperability with external applications, tuyaDEAMON offers also (Since ver. 2.0) a fast REST asynchronous interface with an immediate JSON response: Examples:

  • SET: http://localhost:1984/tuyaDAEMON?device=tuya_bridge&property=relay&value=OFF
    • answer: {"device":"tuya_bridge","property":"switch","status":"sent"}
  • GET: http://localhost:1984/tuyaDAEMON?device=tuya_bridge&property=relay
    • answer: {"device":"tuya_bridge","property":"relay","value":"ON"}
  • SCHEMA: http://localhost:1984/tuyaDAEMON?device=tuya_bridge.
    • answer: {"device":"tuya_bridge","schema":{"_connected":true,"_t":1616865119,"trigger (reserved)":0,"relay":"ON","restart status":"memory"}}
  • LIST devices: http://localhost:1984/tuyaDAEMON.
    • answer: {"list":["Zigbee Gateway","Smart IR 1","HAL@home","BLE MESH(SIG)Gateway","tuya_bridge","Temperature living", "Door sensor","USB siren","PIR sensor"]}
  • ERROR: {"status":"ERROR: not found the property (switch) in 'tuya_bridge'"}
  • ERROR: {"status":"ERROR: not found the device 'tuya_trigger'"}

note: all devices accept 'GET' and 'SCHEMA' requests via fast REST: the data comes from the 'global.tuyastatus' structure.

A second debug REST interface is synchronous and dedicated to development applications. See, as an example, tuyaDAEMON.toolkit, a PHP application to help users manage devices.

MQTT interface

But with version 2.1 I added to tuyaDAEMON a MQTT broker and a MQTT interface, both for events and commands. This was done thinking to UI. On PC (and portables), node-red offers good interfaces, but is required some development time. SmartLife UI is good, you will continue to use it for many maintenance operations, but becomes fast too big to be very friendly. Interfaces can be done in HTML/js/php but also, in this case, the development is not for all (see example). Using MQTT it is easy to find ready UI:

  • For PC and Mac I use the client 'mqtt-explorer', which shows all data, locals, and remotes, also with charts, and allows to send any command (use example). Ready, car does not require customization. A good tool for developers, it can be the general purpose UI for tyuaDAEMON.
  • For Android, as portable UI (but also on PC with a simulator), I found very good and customizable, but still simple, the client 'IOT MQTT panel', with a nice look and JSON handling. The look is equivalent to node-red.dashboard, I used it to make some specialized UI. Any UI is a file JSON that can be exported and imported. As an example see here the node-red and IOT MQTT panel implementations of the same interface, side by side.

The MQTT topics structure is simple:

tuyaDAEMON/<remote_name>/<device_name>|' '/events|commands[/<property_name>]

The 'value' ( '', string or json) is the message.

Compare it to tuyaDAEMON standard commands.

So:

  • tuyaDAEMON/DEVPC/tuya_bridge/commands/relay + 'ON' is a local SET
  • tuyaDAEMON/ANDROID/tuya_bridge/commands + '' is a remote GET SCHEMA
  • tuyaDAEMON/ANDROID/ /commands + '' is a remote LIST (a space is required as undefined device)

Really minimal.

DataBase interface

TuyaDEAMON automatically logs user-select messages and measurements on one or more DB tables ('messages'), a useful option for control, analysis, and statistics. Since ver. 2.0:



Devices interfaces

  • Tuya device low level, via 'tuyapi' driver: see CORE
  • Tuya device hi level, via 'TRIGGER': see smoke_alarm.
  • Tuya Cloud and OpenAPI access: see core_OPENAPI device.
  • Custom 'SW only' device, i.e. feature modules: see system
  • MQTT devices, using custom driver nodes: see PDMtimer
  • Custom devices using ESP-10 (ESP8266): see watchdog
  • USB-serial devices, using custom adapter: see PM_detector
  • 433 MHz sensors, using custom 433 gateway: see Weather station

Examples:

  • YAWT (Yet Another Watering Timer), 8 zones watering, using REST and a WEB map interface, see here.

New: TuyaDEAMON-applications repository.


Version 2.0

With version 2.0 tuyaDAEMON reaches 2 milestones: the ability to use and create custom devices in a hierarchical OO perspective, and the ability to create distributed TuyaDAEMON network.

Last version 2.2.4


This project is a work-in-progress: it is provided "as is", without warranties of any kind, implicit or explicit.
English is not my first language. I apologize for any mistakes.

Acknowledgment

A heartfelt thanks to all the people who contributed with observations and advice.

tuyadaemon's People

Contributors

msillano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tuyadaemon's Issues

ver 2.2.1, js errors

Some function nodes show errors: wrong variable definition (missed let, const, etc.).
But the old-style code works without problems, it is required a revision for all function nodes.
Building ver. 2.2.2 recheck all functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.