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

TuyaMCU Update 1/3 #9769

Merged
merged 2 commits into from
Nov 8, 2020
Merged

TuyaMCU Update 1/3 #9769

merged 2 commits into from
Nov 8, 2020

Conversation

effelle
Copy link
Contributor

@effelle effelle commented Nov 7, 2020

Changelog

  • New functions and commands for enum management
  • New command for RGB management
  • Removed functions from TUYA_MCU_FUNC_FAN3 to TUYA_MCU_FUNC_FAN6
  • Removed the buttons for the Fan Controller in WebUI because they were not well implemented. A new interface with sliders and snap points will be eventually merged on update 3
  • Updated optional /stat topic
  • Some minor code rework

Enums management:

Tasmota has now more control over the Type 4 enum. Up to four can be added, with a range from 0 to 9 .

Functions:

  • 61 TUYA_MCU_FUNC_ENUM1
  • 62 TUYA_MCU_FUNC_ENUM2
  • 63 TUYA_MCU_FUNC_ENUM3
  • 64 TUYA_MCU_FUNC_ENUM4

New commands for enums:

After an enum is configured, use EnumList to  declare the range it must respect, please note 0 is always the first item in range.

Usage: TuyaEnumlist [1|2|3|4],[0|1|2|3|4|5|6|7|8|9]
Example: configure Enum 1 with a range from 0 to 8.

21:14:52 CMD: tuyaenumlist 1,8
21:14:52 MQT: stat/TuyaMCU/RESULT = {"TuyaEnumList":{"Enum1":8,"Enum2":9,"Enum4":1}}

Warning: Entering a value greater than 9 will return an error.
Tip: TuyaEnumList without payload will return the configuration of all the enums enabled in the list.

To update an enum use the command TuyaEnum:
Usage TuyaEnum [1|2|3|4],[value in EnumList range]
Example: update Enum 2 to 4.

21:14:12 CMD: tuyaenum2 4
21:14:12 MQT: stat/TuyaMCU/RESULT = {"TuyaEnum2":4}

Warning: Entering a value not in range will return an error.
Tip: TuyaEnum without payload will return the state of all the enums configured.

RGB color management:

 TuyaMCU uses two types of RGB Hex format where the most recent is 0HUE0SAT0BRI0 (type 1) and the older being RRGGBBFFFF6464 (type 2).
Depending on the MCU code both can be case sensitive.
After enabling the RGB function check the TuyaReceived information and use TuyaRGB to configure and store the correct (or the closest) format:

  • TuyaRGB 0:  Type 1 - 12 characters uppercase - Example: 00DF00DC0244 (default)
  • TuyaRGB 1:  Type 1 - 12 characters lowercase - Example: 008003e8037a
  • TuyaRGB 2:  Type 2 - 14 characters uppercase - Example: 00FF00FFFF6464
  • TuyaRGB 3:  Type 2 - 14 characters lowercase - Example: 00e420ffff6464

Tip: TuyaRGB without payload will return the actual configured format.

Warning: Tuya left to the manufacturer the ability to personalize the payload for custom product, Tasmota can't comply with all possible protocols for color. If your device doesn't work there isn't much else to do.

Optional State topic:

The togglable topic (Tuyasend9) was updated to a more meaningful one.
Before:

20:45:22 MQT: stat/TuyaMCU/TUYASEND1 = 1,1

After:

21:51:34 MQT: stat/TuyaMCU/DPTYPE1ID1 = 1

Related issue (if applicable): fixes somehow #9737

Checklist:

  • The pull request is done against the latest dev branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR.
  • The code change is tested and works on Tasmota core ESP8266 V.2.7.4.7
  • The code change is tested and works on core ESP32 V.1.12.4
  • I accept the CLA.

patch: https://patch-diff.githubusercontent.com/raw/arendst/Tasmota/pull/9769.patch
diff: https://patch-diff.githubusercontent.com/raw/arendst/Tasmota/pull/9769.diff

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@arendst arendst merged commit 32d6e61 into arendst:development Nov 8, 2020
@arendst
Copy link
Owner

arendst commented Nov 8, 2020

Is there any reason not to use a name like TuyaEnum and TuyaEnumList instead of Enum and EnumList?

The current naming could interfere with other commands.

If it's no issue I'll change it to TuyaEnum and TuyaEnuumList like:

#define D_PRFX_TUYA "Tuya"
#define D_CMND_TUYA_MCU "MCU"
#define D_CMND_TUYA_MCU_SEND_STATE "Send"
#define D_CMND_TUYARGB "RGB"
#define D_CMND_ENUM "Enum"
#define D_CMND_ENUM_LIST "EnumList"

const char kTuyaCommand[] PROGMEM = D_PRFX_TUYA "|"  // Prefix
  D_CMND_TUYA_MCU "|" D_CMND_TUYA_MCU_SEND_STATE "|" D_CMND_TUYARGB "|" D_CMND_ENUM "|" D_CMND_ENUM_LIST;

@effelle
Copy link
Contributor Author

effelle commented Nov 8, 2020

Make sense, please update it.

@arendst
Copy link
Owner

arendst commented Nov 8, 2020

Tnx. WOrking on it now.

arendst added a commit that referenced this pull request Nov 8, 2020
Add commands ``TuyaRGB``, ``TuyaEnum`` and ``TuyaEnumList`` (#9769)
@effelle
Copy link
Contributor Author

effelle commented Nov 8, 2020

I think I need to change also the json, and using one string Enum instead of D_CMND on the lists to avoid something like

 {"TuyaEnumList":{"TuyaEnum1":8,"TuyaEnum2":9,"TuyaEnum3":7, "TuyaEnum4":3}}

What do you think?

Edit:
No need to, they are fine:

13:13:47 MQT: stat/tasmota_49A3BC/RESULT = {"TuyaEnum":{"Enum1":0,"Enum2":0,"Enum4":0}}
13:15:40 MQT: stat/tasmota_49A3BC/RESULT = {"TuyaEnumList":{"Enum1":8,"Enum2":9,"Enum4":3}}

@effelle
Copy link
Contributor Author

effelle commented Nov 8, 2020

PR description updated with the new syntax.

@effelle effelle mentioned this pull request Nov 8, 2020
6 tasks
@arendst
Copy link
Owner

arendst commented Nov 8, 2020

Thx. Yes I couldn't test the enum commands by lack of Tuya hardware but I expected it not to be a problem as you noticed too.

I think it's about time I get tuya based hardware too ;-)

@effelle
Copy link
Contributor Author

effelle commented Nov 8, 2020

You don't need to buy a device to play with a tuyaMCU, all the code was made using an emulator. ;-)

@arendst
Copy link
Owner

arendst commented Nov 8, 2020

I love it!

@blakadder
Copy link
Collaborator

no worries, i'll test it :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants