Why are device exposes only partially supported?

I’m trying to understand how things work in Gladys. So I’m connecting this motion and luminance sensor to Gladys: TuYa ZG-204ZL control via MQTT | Zigbee2MQTT

According to the z2m docs it exposes occupancy, illuminance, battery, sensitivity, keep_time and linkquality.

In Gladys however it only has the features motion (binary), battery and signal strenght. In scenes it has the additional option “Execute only when threshold is passed (and not at every value sent by the device)”

I think occupancy and motion are related, as are battery and battery, linkquality and signal strenght, and maybe sensitivity and treshold.

That makes that illuminance and keep_time aren’t used. I think scenes offer a workaround for keep_time, but illuminance might come in handy. In the mqtt integration there also is a luminosity sensor so Gladys knows the concept.

Question 1: what is the reason that some exposes properties aren’t reflected in the devices features?
Question 2: I’ve been searching in the code if it is difficult to add things if I would want to. But I couldn’t find where motionsensors and luminosity are referenced. Could you give me some directions?

In Gladys we have a “core” where we defined many types of features (ex: motion sensor, temperature sensor, thermostat, …)

Then, we have many “integrations” like Zigbee2mqtt, and in those integrations all the developer work is to do the mapping between the third-party features and Gladys core.

In the device you mentioned, indeed for now the developer who worked on this integration only integrated 3 features of your device: motion, battery & signal strength.

To add the remaining features, you can submit a PR modifying the Zigbee2mqtt integration, located in this folder.

This file is probably where it’s happening for your device:

Here is an example of a PR adding PM2.5 compatibility:

What I suggest you do if you want to help:

  • Fork the Gladys repo on Github and create a branch
  • Modify the numericType.js file
  • Build a Docker image of your PR (I can help you with that if needed)
  • Test if it works fine on your setup
  • Submit a PR

I’ll be happy to help you on all the step if something is not clear!

Ah, that’s clear.
Gladys doesn’t get devices out of z2m but individual sensors. And every sensor can (of course) be used in multiple devices.

In z2m is defined what kind of exposition the sensor has (binary, composite, enum, numeric). And that way we know in what file in the /server/services/zigbee2mqtt/exposes-folder to work.

At least in numericType.js the syntax is:

    temperature: { // z2m expose
      feature: {
        category: DEVICE_FEATURE_CATEGORIES.TEMPERATURE_SENSOR, // device category (what the device does, like sensoring temperature) defined in /server/utils/constants.js somewhere after line 325
        type: DEVICE_FEATURE_TYPES.SENSOR.DECIMAL, // device type (what kind of device it is and the feature that is defined, like a sensor with decimals) defined in /server/utils/constants.js somewhere after line 373
        unit: DEVICE_FEATURE_UNITS.CELSIUS, // optional: the unit of the feature, like Celcius, defined in /server/utils/constants.js somewhere after line 525
        min: -100, // optional: minimum value
        max: 150, // optional: maximum value

If the feature requires a frontend icon, it is set in /front/src/utils/consts.js somwhere after line 100. Although I’m not sure yet where the icon-names are defined.

Am I missing something crucial or is this about it?

The best way to understand Gladys data model is to see this modelisation:

We have a “Device” (a physical object), and each device has several “features” (temperature sensor, humidity sensor, …)

We use https://feathericons.com/

It’s pretty much it! :smiley:

Depending of what you modify, you may have to add some translations.

For example, yesterday I added support for more features to IKEA Tradfri buttons, and I had to write some translations for each “action” :

Thanks for the clarification and the link to the Data model. I think I missed it while reading up.

I indeed noticed the Styrbar-addition. Two days ago I added one, but it didn’t function as expected. Today I was looking into enumType.js file and found the expected features. And they seem to work well. Thanks for that too.

1 Like