Button value differs between Gladys and Zigbee2MQTT

Hello,

I have a question about how a Xiaomi Zigbee button works.
Zigbee2MQTT indicates the following possible states: single, double, triple, quadruple, hold, release, many

During my tests, these states are indeed shown on the Zigbee2MQTT page.

Yet in Gladys, I can only have the values: 1 (click), 2 (double click), 5 (long press)
Is this configurable somewhere?

Thanks

PS: Sorry for spamming the forum with all my (beginner) questions but I’ve regained some motivation :slight_smile:

Not configurable; however, having the button template would help us add the missing actions.

The model: Xiaomi WXKG01LM control via MQTT | Zigbee2MQTT

How are they configured? Via files?

good evening @Hizo
I have five buttons of this model and I use them 1 (click) « single », 2 (double click) « double » and 5 (a long press) « hold » and when I release it gives « release ». I had never noticed that when you clicked 3 times it gave « triple », for 4 « quadruple » and more than 4 times it gave « many ». Very interesting for controlling my lights.
But for now Gladys only knows the following three states,
single 1
double 2
hold 5
All that’s left is to make a feature request :wink:

Yes, that would be very convenient for me too :slight_smile:

But it is true that I would be interested to know how the hardware setup is done…

at what level ?create a scene with the button?

For your information, there is this issue on GitHub Button click user friendly by atrovato · Pull Request #1642 · GladysAssistant/Gladys · GitHub which aims to convert the 1, 2, 5 into text so that it’s more understandable! :wink:

@Psoy : I didn’t understand what your questions refer to.

do you want to know how to manage them in a scene or do you want to know how it works under the hood of Gladys?
For the first I can

I was talking about the second case :slight_smile:

Here you will find an overview of how it’s coded , I think :wink:

1 Like

So I looked into the thing a bit more,

so the files to modify would be:
server/services/zigbee2mqtt/exposes/enumType.js

 addMapping('action', BUTTON_STATUS.CLICK, 'single');
 addMapping('action', BUTTON_STATUS.DOUBLE_CLICK, 'double');
 addMapping('action', BUTTON_STATUS.TRIPLE_CLICK, 'triple');
 addMapping('action', BUTTON_STATUS.QUADRUPLE_CLICK, 'quadruple');
 addMapping('action', BUTTON_STATUS.MANY_CLICK, 'many');
 addMapping('action', BUTTON_STATUS.HOLD_CLICK, 'hold');
 addMapping('action', BUTTON_STATUS.LONG_CLICK, 'long');

and the file server/test/services/zigbee2mqtt/exposes/actionEnumType.test.js

const { assert } = require('chai');

const enumType = require('../../../../services/zigbee2mqtt/exposes/enumType');
const { BUTTON_STATUS } = require('../../../../utils/constants');

describe('zigbee2mqtt action enumType', () =\u003e {
  const expose = {
    name: 'action',
    values: ['single', 'long', 'short', 'double', 'triple', 'quadruple', 'many', 'hold'],
  };

  [
    { enumValue: 'single', intValue: BUTTON_STATUS.CLICK },
    { enumValue: 'double', intValue: BUTTON_STATUS.DOUBLE_CLICK },
    { enumValue: 'triple', intValue: BUTTON_STATUS.TRIPLE_CLICK },
    { enumValue: 'quadruple', intValue: BUTTON_STATUS.QUADRUPLE_CLICK },
    { enumValue: 'many', intValue: BUTTON_STATUS.MANY_CLICK },
    { enumValue: 'hold', intValue: BUTTON_STATUS.HOLD_CLICK },
    { enumValue: 'long', intValue: BUTTON_STATUS.LONG_CLICK },
  ].forEach((mapping) =\u003e {
    const { enumValue, intValue } = mapping;

    it(`should write ${enumValue} value as ${intValue} value`, () =\u003e {
      const result = enumType.writeValue(expose, intValue);
      assert.equal(result, enumValue);
    });

    it(`should read ${intValue} value as ${enumValue}`, () =\u003e {
      const result = enumType.readValue(expose, enumValue);
      assert.equal(result, intValue);
    });
  });

  it('should write undefined value on missing enum', () =\u003e {
    const missingEnumExpose = {
      values: ['single', 'short', 'double', 'triple', 'quadruple', 'many'],
    };
    const result = enumType.writeValue(missingEnumExpose, BUTTON_STATUS.LONG_CLICK);
    assert.equal(result, undefined);
  });

  it('should write undefined value', () =\u003e {
    const result = enumType.writeValue(expose, 7);
    assert.equal(result, undefined);
  });

  it('should read enum value', () =\u003e {
    const result = enumType.readValue(expose, 'unknown');
    assert.equal(result, undefined);
  });

  it('should have multiple indexes', () =\u003e {
    const result = enumType.getFeatureIndexes(['1_single', '1_double', '2_single']);
    assert.deepEqual(result, [1, 2]);
  });

  it('should have no indexes', () =\u003e {
    const result = enumType.getFeatureIndexes(['single', 'double']);
    assert.deepEqual(result, []);
  });
});

Should we also touch enumType.getFeatureIndexes([‹ single ›, ‹ double ›]);?

And I also noticed that when you hold the button down, it shows long and when you release it afterwards it shows release.
Yet another state :stuck_out_tongue:

If a pro could confirm what I did, that would be great — either to propose the work or to learn what else should be done.
Thanks :slight_smile:

Hi @Hizo :slight_smile:

Can you explain to me what you want to do?

Because I went back through the discussion, and if you’re talking about the user-friendly button click, that’s a project that has already been implemented and deployed ( Button click user friendly by atrovato · Pull Request #1642 · GladysAssistant/Gladys · GitHub )


This development was deployed in Gladys Assistant 4.18 :

No no, I want to add multiple possible states to the buttons.

My Xiaomi WXKG01LM button](Xiaomi WXKG01LM control via MQTT | Zigbee2MQTT) also accepts the actions :

'triple', 'quadruple', 'many',

so I wanted to understand how to propose an improvement to the code.

Ok, I’m not a Zigbee expert but indeed what you propose seems good :slight_smile:

A short post by @AlexTrovato that explains how to add a Zigbee feature: