Skip to content

Commit

Permalink
Merge pull request #63 from vinodsr/feature/add-dyanamic-timeout #pub…
Browse files Browse the repository at this point in the history
…lish

Add control commands to the node
  • Loading branch information
vinodsr authored May 30, 2021
2 parents dfacff3 + d09bfdb commit 8679ffd
Show file tree
Hide file tree
Showing 9 changed files with 887 additions and 347 deletions.
22 changes: 16 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Changelog

## 4.1.0

- Added CONTROL commands as input (CONNECT, DISCONNECT, RECONNECT)
- Seperate output node for device status and client status
- Dynamically set the find and retry timeout (Not saved permanently in the config)
- Disable auto connect on start

## 4.0.2

- Added support for both data and dp-refresh event [#54](https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/54)

## 4.0.1

- Renamed data event to dp-refresh (Tuya 7.1 changes)

## 4.0.0

- Update to Tuya 7.1.0. Closes [#51](https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/51)

## 3.1.0
Expand All @@ -34,23 +43,24 @@ Fixes [#39](https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues
Fixes [#33](https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/33)

- Tuya api library updated to 6.1.1
- No more null data payload on json undefined error. :)

- No more null data payload on json undefined error. :)

## 1.2.1

Fixes [#25](https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/25)

## 1.2.0
* Added a generic SET node which can be controller with message.payload. One node to set command for many devices. Thanks to formatBCE for the suggestion.

- Added a generic SET node which can be controller with message.payload. One node to set command for many devices. Thanks to formatBCE for the suggestion.

## 1.1.4
* Bug fixes

- Bug fixes

## 1.1.3

* Added more extensive retry logic. Previously on find error, the logic hangs
- Added more extensive retry logic. Previously on find error, the logic hangs

## 1.1.0

* Initial Version
- Initial Version
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
![Build and Publish package](https://github.com/vinodsr/node-red-contrib-tuya-smart-device/workflows/Build%20and%20Publish%20package/badge.svg)
![License](https://img.shields.io/github/license/vinodsr/node-red-contrib-tuya-smart-device)


A node-red module which helps you to connect to any tuya device.

![image](./img/sample.png)

# Table of contents

- [Getting Started](#getting-started)
- [Setup](#setup)
- [Input Format](#input-format)
- [Output Format](#output-format)
- [Input Format](#input-format)
- [Output Format](#output-format)
- [License](#license)
- [Contributing](#contributing)


# Getting Started

Instructions for getting the device id is available [here](https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md)

You will get the device id and the key once you run the wizard program as per the instructiions

Get more details about latest version changes in the [CHANGELOG.md](./changelog.md)

# Setup

[(Back to top)](#table-of-contents)

The node takes one input and one output. Once you drop the node into the flow, you need to use the deviceid and devicekey that you got from the getting started step.
The node takes one input and one output. Once you drop the node into the flow, you need to use the deviceid and devicekey that you got from the getting started step.

Once you setup the node, you can then use input to send any command to the device as per the tuya standards.

Expand All @@ -45,6 +45,10 @@ Once you setup the node, you can then use input to send any command to the devic

![image](./img/output.png)

# Examples

You can refer the [example flow](./examples/latest.json) to get started

# License

[(Back to top)](#table-of-contents)
Expand Down
243 changes: 243 additions & 0 deletions examples/latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
[
{
"id": "b2e04683.825318",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "e63245d0.e6cdc8",
"type": "tuya-smart-device",
"z": "b2e04683.825318",
"deviceName": "Tv Light",
"disableAutoStart": true,
"deviceId": "",
"deviceKey": "",
"deviceIp": "",
"retryTimeout": "1001",
"findTimeout": "2000",
"tuyaVersion": "3.1",
"eventMode": "event-both",
"x": 680,
"y": 360,
"wires": [["ff4bd686.53ae18"], ["15d22ba6.824b84"]]
},
{
"id": "c016131.e98faf",
"type": "function",
"z": "b2e04683.825318",
"name": "",
"func": "msg.payload ={\n //dps : 1,\n dps: 20,\n set : msg.payload\n}\n\n/*\n\n */\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 510,
"y": 360,
"wires": [["e63245d0.e6cdc8"]]
},
{
"id": "993c8470.01a278",
"type": "inject",
"z": "b2e04683.825318",
"name": "Turn On",
"props": [{ "p": "payload" }, { "p": "topic", "vt": "str" }],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 310,
"y": 320,
"wires": [["c016131.e98faf"]]
},
{
"id": "6403cde.251ab34",
"type": "inject",
"z": "b2e04683.825318",
"name": "Turn Off",
"props": [{ "p": "payload" }, { "p": "topic", "vt": "str" }],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "false",
"payloadType": "bool",
"x": 310,
"y": 400,
"wires": [["c016131.e98faf"]]
},
{
"id": "e4cfcdc.9520a3",
"type": "tuya-smart-device-generic",
"z": "b2e04683.825318",
"name": "",
"x": 660,
"y": 540,
"wires": [["1e77cd28.a8c303"]]
},
{
"id": "81a451cc.919f9",
"type": "function",
"z": "b2e04683.825318",
"name": "",
"func": "msg.payload ={\n \"deviceVirtualId\": \"\",\n //deviceIp: \"192.168.1.71\",\n \"deviceKey\": \"\",\n \"deviceName\": \"PM\",\n \"operation\": \"SET\", // optional default : SET\n \"payload\": {\n \"dps\": 20,\n \"set\": msg.payload\n },\n // \"version\":\"3.2\"\n \n }\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 450,
"y": 540,
"wires": [["e4cfcdc.9520a3"]]
},
{
"id": "dc28dca8.674c1",
"type": "inject",
"z": "b2e04683.825318",
"name": "ON",
"props": [{ "p": "payload" }, { "p": "topic", "vt": "str" }],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 240,
"y": 580,
"wires": [["81a451cc.919f9"]]
},
{
"id": "1e77cd28.a8c303",
"type": "debug",
"z": "b2e04683.825318",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 940,
"y": 540,
"wires": []
},
{
"id": "4295327a.09bf3c",
"type": "inject",
"z": "b2e04683.825318",
"name": "OFF",
"props": [{ "p": "payload" }, { "p": "topic", "vt": "str" }],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "false",
"payloadType": "bool",
"x": 240,
"y": 500,
"wires": [["81a451cc.919f9"]]
},
{
"id": "8f69fe68.9e4ce",
"type": "catch",
"z": "b2e04683.825318",
"name": "",
"scope": null,
"uncaught": false,
"x": 640,
"y": 140,
"wires": [["3764c769.6e1298"]]
},
{
"id": "3764c769.6e1298",
"type": "debug",
"z": "b2e04683.825318",
"name": "On Error",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 870,
"y": 140,
"wires": []
},
{
"id": "ff4bd686.53ae18",
"type": "debug",
"z": "b2e04683.825318",
"name": "Device Data",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 300,
"wires": []
},
{
"id": "15d22ba6.824b84",
"type": "debug",
"z": "b2e04683.825318",
"name": "Node State",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 400,
"wires": []
},
{
"id": "47ea1d2a.7d85f4",
"type": "inject",
"z": "b2e04683.825318",
"name": "RECONNECT ACTION",
"props": [{ "p": "payload" }, { "p": "topic", "vt": "str" }],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"operation\":\"CONTROL\",\"action\":\"RECONNECT\"}",
"payloadType": "json",
"x": 330,
"y": 220,
"wires": [["e63245d0.e6cdc8"]]
},
{
"id": "1991e72.c15c719",
"type": "inject",
"z": "b2e04683.825318",
"name": "DISCONNECT ACTION",
"props": [{ "p": "payload" }, { "p": "topic", "vt": "str" }],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"operation\":\"CONTROL\",\"action\":\"DISCONNECT\"}",
"payloadType": "json",
"x": 330,
"y": 160,
"wires": [["e63245d0.e6cdc8"]]
}
]
Binary file modified img/input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-tuya-smart-device",
"version": "4.0.2",
"version": "4.1.0",
"description": "A node-red module to interact with the tuya smart devices",
"repository": "https://github.com/vinodsr/node-red-contrib-tuya-smart-device",
"main": "index.js",
Expand All @@ -21,4 +21,4 @@
"dependencies": {
"tuyapi": "7.1.0"
}
}
}
Loading

0 comments on commit 8679ffd

Please sign in to comment.