itavero/homebridge-z2m

[Bug] Min brightness ignored - Lonsonho QS-Zigbee-D02-TRIAC-L

mrmaximas opened this issue · 17 comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

As you know, for this device in zigbee2mqtt you can set a minimum brightness such as 80 out of 255, this means that when you set the brightness in homebridge-z2m to minimum (1%) the dimmer should set the brightness to 80, but it doesn't, homebridge-z2m sets the brightness to 3. Below is the log of zigbee2mqtt when reducing the brightness from 100 to 1% in homekit.

Related devices

No response

Related Devices

No response

Steps To Reproduce

No response

Expected behavior

No response

Device entry

Info 2023-12-01 10:51:18MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":255,"linkquality":138,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:18MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":254,"linkquality":138,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:18MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":255,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:18MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":254,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":251,"linkquality":149,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":252,"linkquality":145,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":91,"linkquality":149,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":91,"linkquality":138,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":43,"linkquality":138,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":43,"linkquality":138,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":25,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:21MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":25,"linkquality":145,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":18,"linkquality":145,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":18,"linkquality":149,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":13,"linkquality":149,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":13,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":10,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":10,"linkquality":145,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":8,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:22MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":8,"linkquality":145,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:23MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":8,"linkquality":149,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:23MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":8,"linkquality":149,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:23MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":5,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:23MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":5,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:23MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":3,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'
Info 2023-12-01 10:51:23MQTT publish: topic 'zigbee2mqtt/0xa4c138b5bb325444', payload '{"brightness":3,"linkquality":142,"max_brightness":255,"min_brightness":80,"state":"ON"}'

Status update

No response

Messages from this plugin

No response

This plugin

1.10.0

Homebridge

Up to Date

Zigbee2MQTT

Up to Date

Homebridge Config UI X (if applicable)

Up to Date

@itavero сan you please tell me how to solve this problem?
At the same time I see in the code on this page mention of the parameters I need, I don't understand if this is relevant to my task.
https://github.com/itavero/homebridge-z2m/blob/master/src/converters/light.ts
private handleSetBrightness(value: CharacteristicValue, callback: CharacteristicSetCallback): void {
if (this.brightnessExpose !== undefined) {
const data = {};
if (value <= 0) {
data[this.brightnessExpose.property] = this.brightnessExpose.value_min;
} else if (value >= 100) {
data[this.brightnessExpose.property] = this.brightnessExpose.value_max;
} else {
data[this.brightnessExpose.property] = Math.round(
this.brightnessExpose.value_min + ((value as number) / 100) * (this.brightnessExpose.value_max - this.brightnessExpose.value_min)
);
}
this.accessory.queueDataForSetAction(data);
callback(null);
} else {
callback(new Error('brightness not supported'));
}
}

I believe this is a problem either in the accessory itself or in Zigbee2MQTT.
As far as I know, external systems should not have to do anything with this minimum brightness.

Can you add a link to the particular device you are talking about, either in the homebridge-z2m or Zigbee2MQTT docs?

It's not this one, is it? Because I don't see the minimum brightness you mentioned.

I speak about another variant https://www.zigbee2mqtt.io/devices/QS-Zigbee-D02-TRIAC-L_1.html#lonsonho-qs-zigbee-d02-triac-l_1
This is z2m log where i set brightness from 100 to 1% in homekit, then this going to z2m via homebridge-z2m
The plugin sends a command to mqtt to set the brightness without considering the minimum brightness, although the plugin can see the minimum brightness.
2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":249,"linkquality":94,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":250,"linkquality":94,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":236,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":237,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":229,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":230,"linkquality":102,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":216,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:08MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":217,"linkquality":102,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":203,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":204,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":191,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":192,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":168,"linkquality":102,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":169,"linkquality":94,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":152,"linkquality":105,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:09MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":152,"linkquality":105,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":109,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":109,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":61,"linkquality":102,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":61,"linkquality":102,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":23,"linkquality":102,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":23,"linkquality":94,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":3,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:10MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":3,"linkquality":102,"max_brightness":255,"min_brightness":40,"state":"ON"}' Info 2023-12-30 14:24:11MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":3,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"OFF"}' Info 2023-12-30 14:24:11MQTT publish: topic 'zigbee2mqtt/Hall Main', payload '{"brightness":3,"linkquality":98,"max_brightness":255,"min_brightness":40,"state":"OFF"}'

My logic is - if a minimum brightness parameter present, then plugin should have sent a brightness 40, not 3 when homekit set it to 1%. I guess that also applies to maximum brightness, so 1% is minimum brightness, 100% is maximum.

if a minimum brightness parameter present

As far as I know, there's no "minimum brightness parameter". Can you link to the documentation about this? I don't see it on the device page.

For example. I set min 40 max 200, this is expose ofn this device in my mosquitto
{"brightness":137,"linkquality":102,"max_brightness":200,"min_brightness":40,"state":"ON"}
https://www.zigbee2mqtt.io/devices/QS-Zigbee-D02-TRIAC-L_1.html#light

I set min 40 max 200

Where do you set this? Where is this documented?

this is expose ofn this device in my mosquitto

This is not the exposes information. This is the device state.

If you really want to, you can copy the actual exposes information of the device into the plugin configuration and change the range of the brightness property to whatever you prefer.

See the plugin configuration docs.

If you really want to, you can copy the actual exposes information of the device into the plugin configuration and change the range of the brightness property to whatever you prefer.

See the plugin configuration docs.

Unfortunately I need help in solving this problem. My qualification is not enough to do it myself.

Screenshot 2023-12-30 at 14 56 00

Okay, so this seems to be a property of the device. Strange that it is not listed in the documentation.
Anyway, the device should solve this itself.

I'm pretty sure if you change the brightness from the front end, it will also just send 0-255.

Unfortunately I need help in solving this problem. My qualification is not enough to do it myself.

First, find your device in the list published to the zigbee2mqtt/bridge/devices MQTT topic by Zigbee2MQTT.

Within the entry for the device, you will find an object named definition. This object contains another object named exposes. You'll need to copy this entire exposes object.

In this copied JSON, search for the entry that defines the brightness (should be of type numeric and adjust/add the value_min/value_max). There's an example in the Zigbee2MQTT docs.

In the homebridge-z2m plugin configuration, add an entry to the devices array with the id set to the IEEE address of the device and the exposes set to object you copied and adjusted before.
For example on the structure of the plugin configuration, please see the documentation.

Note that you'll need at least v1.10.0 of homebridge-z2m, which is currently newer that what @latest will install.

I'm pretty sure if you change the brightness from the front end, it will also just send 0-255.
yes. of course. this problem needs to be solve on the plugin side

First, find your device in the list published to the zigbee2mqtt/bridge/devices MQTT topic by Zigbee2MQTT.

{ "date_code": "", "definition": { "description": "1 channel dimmer", "exposes": [ { "features": [ { "access": 7, "description": "On/off state of this light", "label": "State", "name": "state", "property": "state", "type": "binary", "value_off": "OFF", "value_on": "ON", "value_toggle": "TOGGLE" }, { "access": 7, "description": "Brightness of this light", "label": "Brightness", "name": "brightness", "property": "brightness", "type": "numeric", "value_max": 254, "value_min": 0 }, { "access": 7, "description": "Minimum light brightness", "label": "Min brightness", "name": "min_brightness", "property": "min_brightness", "type": "numeric", "value_max": 255, "value_min": 1 }, { "access": 7, "description": "Maximum light brightness", "label": "Max brightness", "name": "max_brightness", "property": "max_brightness", "type": "numeric", "value_max": 255, "value_min": 1 } ], "type": "light" }, { "access": 7, "description": "Type of light attached to the device", "label": "Light type", "name": "light_type", "property": "light_type", "type": "enum", "values": [ "led", "incandescent", "halogen" ] }, { "access": 7, "description": "Controls the behavior when the device is powered on after power loss", "label": "Power-on behavior", "name": "power_on_behavior", "property": "power_on_behavior", "type": "enum", "values": [ "off", "previous", "on" ] }, { "access": 1, "description": "Link quality (signal strength)", "label": "Linkquality", "name": "linkquality", "property": "linkquality", "type": "numeric", "unit": "lqi", "value_max": 255, "value_min": 0 } ], "icon": " ", "model": "QS-Zigbee-D02-TRIAC-L_1", "options": [ { "access": 2, "description": "State actions will also be published as 'action' when true (default false).", "label": "State action", "name": "state_action", "property": "state_action", "type": "binary", "value_off": false, "value_on": true } ], "supports_ota": true, "vendor": "Lonsonho" }, "disabled": false, "endpoints": { "1": { "bindings": [ { "cluster": "genLevelCtrl", "target": { "endpoint": 1, "ieee_address": "0x00124b002a1aa3c4", "type": "endpoint" } }, { "cluster": "genOnOff", "target": { "endpoint": 1, "ieee_address": "0x00124b002a1aa3c4", "type": "endpoint" } } ], "clusters": { "input": [ "genGroups", "genScenes", "genOnOff", "genLevelCtrl", "lightingColorCtrl", "manuSpecificTuya", "genBasic" ], "output": [ "genOta", "genTime" ] }, "configured_reportings": [ { "attribute": "onOff", "cluster": "genOnOff", "maximum_report_interval": 3600, "minimum_report_interval": 0, "reportable_change": 0 } ], "scenes": [] }, "2": { "bindings": [], "clusters": { "input": [ "genGroups", "genScenes", "genOnOff", "genLevelCtrl", "lightingColorCtrl", "manuSpecificTuya" ], "output": [] }, "configured_reportings": [], "scenes": [] }, "242": { "bindings": [], "clusters": { "input": [], "output": [ "greenPower" ] }, "configured_reportings": [], "scenes": [] } }, "friendly_name": "Kitchen Main", "ieee_address": "0xa4c138b5bb325444", "interview_completed": true, "interviewing": false, "manufacturer": "_TZ3210_weaqkhab", "model_id": "TS110E", "network_address": 12627, "power_source": "Mains (single phase)", "supported": true, "type": "Router" }

Note that you'll need at least v1.10.0 of homebridge-z2m, which is currently newer that what @latest will install.

Installed: v1.11.0-beta.2

@itavero my plugin section in hb config here:
{
"mqtt": {
"base_topic": "zigbee2mqtt",
"server": "mqtt://1.2.3.4:1883",
"reject_unauthorized": false,
"keepalive": 60,
"version": 4,
"disable_qos": false
},
"log": {
"mqtt_publish": "debug"
},
"defaults": {
"exclude": false
},
"exclude_grouped_devices": true,
"devices": [
{
"id": "0x187a3efffe358554",
"exclude": true
},
{
"id": "0xa4c138b5bb325444",
"exclude": false
}
],
"_bridge": {
"username": "0E:7A:DD:3D:DA:BA",
"port": 53072
},
"platform": "zigbee2mqtt"
}
What i have to add for "id": "0xa4c138b5bb325444"? Please help me.

@itavero it's works!
my device section in plugin config now is:
{
"id": "0xa4c138b5bb325444",
"exclude": false,
"exposes": [
{
"features": [
{
"access": 7,
"label": "State",
"name": "state",
"property": "state",
"type": "binary",
"value_off": "OFF",
"value_on": "ON",
"value_toggle": "TOGGLE"
},
{
"access": 7,
"label": "Brightness",
"name": "brightness",
"property": "brightness",
"type": "numeric",
"value_max": 250,
"value_min": 90
}
],
"type": "light"
}
]
}

Thanks, now my 1-100% in homekit is 92-251 in z2m.