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

Configuration of new 8ch switch #6545

Merged
merged 14 commits into from
Dec 8, 2023
55 changes: 55 additions & 0 deletions src/devices/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5800,6 +5800,61 @@ const definitions: Definition[] = [
],
},
},
{
fingerprint: [
{modelID: 'TS0601', manufacturerName: '_TZE204_adlblwab'},
],
model: 'TS0601_switch_8_2',
vendor: 'TuYa',
description: '8 gang switch',
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
exposes: [
tuya.exposes.switch().withEndpoint('l1'),
tuya.exposes.switch().withEndpoint('l2'),
tuya.exposes.switch().withEndpoint('l3'),
tuya.exposes.switch().withEndpoint('l4'),
tuya.exposes.switch().withEndpoint('l5'),
tuya.exposes.switch().withEndpoint('l6'),
tuya.exposes.switch().withEndpoint('l7'),
tuya.exposes.switch().withEndpoint('l8'),
tuya.exposes.countdown().withEndpoint('l1'),
tuya.exposes.countdown().withEndpoint('l2'),
tuya.exposes.countdown().withEndpoint('l3'),
tuya.exposes.countdown().withEndpoint('l4'),
tuya.exposes.countdown().withEndpoint('l5'),
tuya.exposes.countdown().withEndpoint('l6'),
tuya.exposes.countdown().withEndpoint('l7'),
tuya.exposes.countdown().withEndpoint('l8'),
e.power_on_behavior().withAccess(ea.STATE_SET),
],
endpoint: (device) => {
return {'l1': 1, 'l2': 1, 'l3': 1, 'l4': 1, 'l5': 1, 'l6': 1, 'l7': 1, 'l8': 1};
},
meta: {
multiEndpoint: true,
tuyaDatapoints: [
[1, 'state_l1', tuya.valueConverter.onOffWithDelay],
[2, 'state_l2', tuya.valueConverter.onOffWithDelay],
[3, 'state_l3', tuya.valueConverter.onOffWithDelay],
[4, 'state_l4', tuya.valueConverter.onOffWithDelay],
[5, 'state_l5', tuya.valueConverter.onOffWithDelay],
[6, 'state_l6', tuya.valueConverter.onOffWithDelay],
[7, 'state_l7', tuya.valueConverter.onOffWithDelay],
[8, 'state_l8', tuya.valueConverter.onOffWithDelay],
[9, 'countdown_l1', tuya.valueConverter.countdown],
[10, 'countdown_l2', tuya.valueConverter.countdown],
[11, 'countdown_l3', tuya.valueConverter.countdown],
[12, 'countdown_l4', tuya.valueConverter.countdown],
[13, 'countdown_l5', tuya.valueConverter.countdown],
[14, 'countdown_l6', tuya.valueConverter.countdown],
[15, 'countdown_l7', tuya.valueConverter.countdown],
[16, 'countdown_l8', tuya.valueConverter.countdown],
[27, 'power_on_behavior', tuya.valueConverter.powerOnBehaviorEnum],
],
},
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE204_dqolcpcp']),
model: 'TS0601_switch_12',
Expand Down
7 changes: 7 additions & 0 deletions src/lib/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ export const valueConverter = {
trueFalseEnum0: valueConverterBasic.trueFalse(new Enum(0)),
trueFalseEnum1: valueConverterBasic.trueFalse(new Enum(1)),
onOff: valueConverterBasic.lookup({'ON': true, 'OFF': false}),
onOffWithDelay: {
to: async (value: string) => {
await utils.sleep(200);
Copy link
Contributor Author

@bszczepanik bszczepanik Nov 26, 2023

Choose a reason for hiding this comment

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

I put delay here, but that caused that all requests are delayed and send all togheter after 200 ms. It should look like utils.sleep(transitiont * 200) but I don't know how proper declare transition

Copy link
Owner

Choose a reason for hiding this comment

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

What do you mean with transitiont?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I will change switch in Z2M for more then one entity at one time, I want to set some number like 0, 1, 2, 3 for each. I will get delay time such 0 * 200 ms, 1 * 200 ms, 2 * 200 ms and so on.

Copy link
Owner

Choose a reason for hiding this comment

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

If you change to: async (value: string) => { to to: async (value: string, meta) => {, you can get the message with meta.message, from that you can count the number of state_ and create the timeout based on that.

return value === 'ON' ? true : false;
},
from: (value: boolean) => value ? 'ON' : 'OFF',
},
powerOnBehavior: valueConverterBasic.lookup({'off': 0, 'on': 1, 'previous': 2}),
powerOnBehaviorEnum: valueConverterBasic.lookup({'off': new Enum(0), 'on': new Enum(1), 'previous': new Enum(2)}),
switchType: valueConverterBasic.lookup({'momentary': new Enum(0), 'toggle': new Enum(1), 'state': new Enum(2)}),
Expand Down