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

Add support for TuYa Smart Switch with backlight ( 2, 3, 4, 6 gang configurations) #5935

Merged
merged 24 commits into from
Jul 9, 2023

Conversation

Qianli-Ma
Copy link
Contributor

Power on behavior is still work in progress.
tuya.exposes.switch().withEndpoint('master_switch'), requires #18157 to work.

Qianli-Ma and others added 12 commits June 19, 2023 01:41
Added Terncy CL001 support
Fixed linting issues
added support for tuya G3 smart 4 gang switch with 2 scene controller
Changed model name
fix typo
Adds support for tuya 4gang + 2 scene switch with backlight.
Power on behavior is still WIP.
master_switch requires Koenkk/zigbee2mqtt#18157 to work
fixed linting errors
@Qianli-Ma Qianli-Ma changed the title Add support for TuYa Smart Switch (4 gang + 2 scene) with neutral wire' Add support for TuYa Smart Switch (4 gang + 2 scene) with neutral wire Jul 1, 2023
tuya.exposes.countdown().withEndpoint('l4'),
tuya.exposes.countdown().withEndpoint('l5'),
tuya.exposes.countdown().withEndpoint('l6'),
tuya.exposes.switch().withEndpoint('master_switch'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you remove tuya.exposes.switch().withEndpoint('master_switch'), here and change [13, 'state_master', tuya.valueConverter.onOff], to [13, 'state', tuya.valueConverter.onOff],, does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing tuya.exposes.switch().withEndpoint('master_switch'), no longer exposes the master switch in the frontend.
However, publishing {"state": "ON"} and {"state": "OFF"} does the trick.

Copy link
Owner

@Koenkk Koenkk Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant changing tuya.exposes.switch().withEndpoint('master_switch') to tuya.exposes.switch()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to tuya.exposes.switch() works as properly.
But I can't seem to add an discription with tuya.exposes.switch().withDescription('All Switches'),

Moved _TZE200_wunufsil to an individual device with switch countdown timer, power on behavior, backlight control, and master switch functions.
Changed model name to reflect 2 gang control
_TZE200_0j5jma9b :
  fixed description
  fixed master switch
_TZE200_wunufsil:
  removed extra endpoints
Added TS0601_3gang switch with backlight
Fixed duplicate _TZE200_vhy3iakz (new code supports countdown, backlight mode, and main switch)  and changed some formatting
fix duplicates and format
Changed _TZE200_k6jhsr0q to support additional features
@Qianli-Ma Qianli-Ma changed the title Add support for TuYa Smart Switch (4 gang + 2 scene) with neutral wire Add support for TuYa Smart Switch with backlight (1, 2, 3, 4, 6 gang configurations) Jul 2, 2023
@Qianli-Ma
Copy link
Contributor Author

I've updated the code to support 1,2,3,4,6 gang smart switches with backlight (have tested it with my switches).
However, I'm not sure how to change the name of the main switch into something else, such as All Switches.
Power on behavior and backlight mode works as expected.

@Qianli-Ma Qianli-Ma changed the title Add support for TuYa Smart Switch with backlight (1, 2, 3, 4, 6 gang configurations) Add support for TuYa Smart Switch with backlight ( 2, 3, 4, 6 gang configurations) Jul 3, 2023
{
zigbeeModel: ['TS0601_4_gang'],
fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_k6jhsr0q'}],
model: 'Tuya 4 Gang Smart Switch with Backlight',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all added definitions, can you add the actual model number here? (which is listed on the product site/device itself)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you made some updates, please remove zigbeeModel: ['ZS-TYG3-SM-41Z'], and use it as model (e.g. model: 'ZS-TYG3-SM-41Z',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Koenkk
Copy link
Owner

Koenkk commented Jul 4, 2023

Note to self; after this merge Koenkk/zigbee2mqtt.io#2114

Update device names per request
Updated model names
[9, 'countdown_l3', tuya.valueConverter.countdown],
[10, 'countdown_l4', tuya.valueConverter.countdown],
[13, 'state', tuya.valueConverter.onOff],
[14, 'power_on_behavior', tuya.valueConverterBasic.lookup({'off': tuya.enum(0), 'on': tuya.enum(1), 'memory': tuya.enum(2)})],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing;

Can you try: [14, 'power_on_behavior', tuya.valueConverter.powerOnBehavior], here and instead of e.power_on_behavior(['off', 'on', 'memory']).withAccess(ea.STATE_SET), use e.power_on_behavior() and see if that works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm it works.

There is one issue with my implementation, the refresh for backlight_mode throws out the following error:
error 2023-07-06 18:00:32: No converter available for 'get' 'backlight_mode' ()
image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get is not supported for datapoints, use tuya.exposes.backlightModeOffOn().setAccess(ea.STATE_SET)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get is not supported for datapoints, use tuya.exposes.backlightModeOffOn().setAccess(ea.STATE_SET)

Following error is thrown when I try to use tuya.exposes.backlightModeOffOn().setAccess(ea.STATE_SET)

node:assert:399
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Does not have any features
    at Binary.setAccess (E:\zigbee2mqtt\zigbee2mqtt\node_modules\zigbee-herdsman-converters\src\lib\exposes.ts:62:15)
    at E:\zigbee2mqtt\zigbee2mqtt\data\extension\externally-loaded.js:27:43
    at Script.runInContext (node:vm:141:12)
    at Script.runInNewContext (node:vm:146:17)
    at Object.runInNewContext (node:vm:300:38)
    at loadModuleFromText (E:\zigbee2mqtt\zigbee2mqtt\lib\util\utils.ts:151:8)
    at loadModuleFromFile (E:\zigbee2mqtt\zigbee2mqtt\lib\util\utils.ts:158:12)
    at Object.getExternalConvertersDefinitions (E:\zigbee2mqtt\zigbee2mqtt\lib\util\utils.ts:168:25)
    at getExternalConvertersDefinitions.next (<anonymous>)
    at new ExternalConverters (E:\zigbee2mqtt\zigbee2mqtt\lib\extension\externalConverters.ts:12:20)

I belive this is caused by Binary class constructor does not have features initialized, however I don't know how to use my local copy of zigbee-herdsman-converters to test out this theory.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, it should be tuya.exposes.backlightModeOffOn().withAccess(ea.STATE_SET)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm it works.

There is one issue with my implementation, the refresh for backlight_mode throws out the following error: error 2023-07-06 18:00:32: No converter available for 'get' 'backlight_mode' () image

Upon futher testing, e.power_on_behavior() and [14, 'power_on_behavior', tuya.valueConverter.powerOnBehavior] does not work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, it should be tuya.exposes.backlightModeOffOn().withAccess(ea.STATE_SET)

This works

Qianli-Ma and others added 3 commits July 7, 2023 18:39
Fixed power on behavior
Fixed backlightModeOffOn get
@Koenkk Koenkk merged commit fa5e2b9 into Koenkk:master Jul 9, 2023
@Koenkk
Copy link
Owner

Koenkk commented Jul 9, 2023

thanks!

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.

2 participants