zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

[Feature request]: Don't debounce first message

Open klada opened this issue 3 years ago • 10 comments

Is your feature request related to a problem? Please describe

The Busch-Jaeger RB01 and RM01 devices send duplicte events on button presses:

info  2022-06-09 20:10:26: MQTT publish: topic 'zigbee2mqtt/sw_bj', payload '{"action":"on_row_1","linkquality":10}'
info  2022-06-09 20:10:26: MQTT publish: topic 'zigbee2mqtt/sw_bj', payload '{"action":"on_row_1","linkquality":3}'
info  2022-06-09 20:10:29: MQTT publish: topic 'zigbee2mqtt/sw_bj', payload '{"action":"off_row_1","linkquality":61}'
info  2022-06-09 20:10:29: MQTT publish: topic 'zigbee2mqtt/sw_bj', payload '{"action":"off_row_1","linkquality":61}'
info  2022-06-09 20:10:31: MQTT publish: topic 'zigbee2mqtt/sw_bj', payload '{"action":"on_row_1","linkquality":58}'
info  2022-06-09 20:10:31: MQTT publish: topic 'zigbee2mqtt/sw_bj', payload '{"action":"on_row_1","linkquality":58}'

This can be worked around by debounce and debounce_ignore. However this introduces a little lag, because right now debounce seems to queue messages for the entire debounce interval until it publishes a message.

Describe the solution you'd like

It would be nice if we could get a better control on when to debounce. In this context an additional attribute debounce_leading_edge=true|false would be very helpful.

debounce_leading_edge=false would be the default and current behavior (debounce first and then publish message)

debounce_leading_edge=true would be the new behavior where a message would be published instantly and only further incoming messages of the same type are held back.

I think #10253 points out the things which would need to be changed.

Describe alternatives you've considered

Right now I am using a fairly small debounce interval to work around the duplicate events, but this (obviously) introduces a lag.

Additional context

There have been several requests for this feature and issues which could possibly be solved by this: #3677, #8139

klada avatar Jun 09 '22 18:06 klada

Yes, I asked some time ago for the same. Very interested.

McGiverGim avatar Jun 09 '22 22:06 McGiverGim

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Jul 10 '22 00:07 github-actions[bot]

Bump

netweaver1970 avatar Jul 10 '22 15:07 netweaver1970

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Aug 25 '22 00:08 github-actions[bot]

bump

netweaver1970 avatar Aug 25 '22 10:08 netweaver1970

yes, this idea interesting for me, too

london89 avatar Sep 21 '22 09:09 london89

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Oct 22 '22 00:10 github-actions[bot]

bump

klada avatar Oct 22 '22 08:10 klada

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Nov 23 '22 00:11 github-actions[bot]

unstale

klada avatar Nov 23 '22 20:11 klada

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Dec 25 '22 00:12 github-actions[bot]

bump

klada avatar Dec 25 '22 09:12 klada

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Jan 26 '23 00:01 github-actions[bot]

bump

klada avatar Jan 28 '23 11:01 klada

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Mar 01 '23 00:03 github-actions[bot]

bump

klada avatar Mar 01 '23 19:03 klada

I am also missing this feature. May a debounce function switch that makes it switch between "wait for x time after first message" and "ignore for x time after first message" would be a good compromise?

vandalon avatar Mar 24 '23 07:03 vandalon

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Apr 24 '23 00:04 github-actions[bot]

bump

klada avatar Apr 25 '23 17:04 klada

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar May 27 '23 00:05 github-actions[bot]

bump

@Koenkk Is it possible to disable the stale bot for some issues so we can stop playing this bump game?

klada avatar May 29 '23 20:05 klada

Is this the same problems as I have in this issue? https://github.com/Koenkk/zigbee2mqtt/issues/19454 @Koenkk do you have time to take a look at this, so debounce on leading edge would be available in z2m?

copystring avatar Nov 20 '23 21:11 copystring

Could you try to locally change https://github.com/Koenkk/zigbee2mqtt/blob/311ea070b167ddc6d8de1f8922aed0d8b38025d7/lib/extension/receive.ts#L41

to

 }, time * 1000, {immediate: true}),

Run npm run build and see if that fixes the issue?

Koenkk avatar Nov 21 '23 19:11 Koenkk

No luck:

npm run build

> [email protected] build
> tsc && node index.js writehash

lib/extension/receive.ts:41:33 - error TS2345: Argument of type '{ immediate: boolean; }' is not assignable to parameter of type 'boolean'.

41                 }, time * 1000, {immediate: true}),
                                   ~~~~~~~~~~~~~~~~~


Found 1 error in lib/extension/receive.ts:41

copystring avatar Nov 21 '23 20:11 copystring

}, time * 1000, true), is the correct code and fixed the issue for me.

copystring avatar Nov 21 '23 20:11 copystring

@Koenkk looking closer, this has not solved my issue, but I got more details. For testing, I turned off and on my light switch via the frontend:

OFF via frontend:

Info 2023-11-22 08:55:32MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:55:31+01:00","linkquality":153,"power_on_behavior":"previous","state":"ON","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Info 2023-11-22 08:55:32MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:55:31+01:00","linkquality":153,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Info 2023-11-22 08:55:32MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:55:32+01:00","linkquality":153,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'

ON via frontend:

Info 2023-11-22 08:55:34MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:55:34+01:00","linkquality":149,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Info 2023-11-22 08:55:34MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:55:34+01:00","linkquality":149,"power_on_behavior":"previous","state":"ON","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Info 2023-11-22 08:55:36MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:55:36+01:00","linkquality":149,"power_on_behavior":"previous","state":"ON","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'

OFF without frontend directly on the physical light switch:

Info 2023-11-22 08:56:07MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:56:07+01:00","linkquality":149,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'

ON without frontend directly on the physical light switch:

Info 2023-11-22 08:56:11MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T08:56:10+01:00","linkquality":149,"power_on_behavior":"previous","state":"ON","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'

copystring avatar Nov 22 '23 08:11 copystring

Could you provide the debug log of this?

See https://www.zigbee2mqtt.io/guide/usage/debug.html on how to enable debug logging.

Koenkk avatar Nov 22 '23 18:11 Koenkk

Debug 2023-11-22 19:41:12Received MQTT message on 'zigbee2mqtt/LichtschalterHobbyraum/set' with data '{"state":"OFF"}'
Debug 2023-11-22 19:41:12Publishing 'set' 'state' to 'LichtschalterHobbyraum'
Info  2023-11-22 19:41:13MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T19:41:13+01:00","linkquality":76,"power_on_behavior":"previous","state":"ON","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Info  2023-11-22 19:41:13MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T19:41:13+01:00","linkquality":76,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Debug 2023-11-22 19:41:13Received Zigbee message from 'LichtschalterHobbyraum', type 'attributeReport', cluster 'genOnOff', data '{"onOff":0}' from endpoint 1 with groupID 0
Info  2023-11-22 19:41:13MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T19:41:13+01:00","linkquality":80,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Debug 2023-11-22 19:41:13Received MQTT message on 'zigbee2mqtt/LichtschalterHobbyraum/set' with data '{"state":"ON"}'
Debug 2023-11-22 19:41:13Publishing 'set' 'state' to 'LichtschalterHobbyraum'
Info  2023-11-22 19:41:13MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T19:41:13+01:00","linkquality":76,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Info  2023-11-22 19:41:13MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T19:41:13+01:00","linkquality":76,"power_on_behavior":"previous","state":"ON","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Debug 2023-11-22 19:41:14Received Zigbee message from 'LichtschalterHobbyraum', type 'attributeReport', cluster 'genOnOff', data '{"onOff":1}' from endpoint 1 with groupID 0

Debug 2023-11-22 19:41:26Received Zigbee message from 'LichtschalterHobbyraum', type 'attributeReport', cluster 'genOnOff', data '{"onOff":0}' from endpoint 1 with groupID 0
Info  2023-11-22 19:41:26MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T19:41:26+01:00","linkquality":83,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'
Debug 2023-11-22 19:41:29Received Zigbee message from 'LichtschalterHobbyraum', type 'attributeReport', cluster 'genOnOff', data '{"onOff":1}' from endpoint 1 with groupID 0
Info  2023-11-22 19:41:29MQTT publish: topic 'zigbee2mqtt/LichtschalterHobbyraum', payload '{"last_seen":"2023-11-22T19:41:29+01:00","linkquality":87,"power_on_behavior":"previous","state":"ON","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}'

copystring avatar Nov 22 '23 18:11 copystring

These is published because you have the last seen option enabled in your configuration.yaml

Koenkk avatar Nov 22 '23 20:11 Koenkk

Enabling last seen makes z2m publish a false state? Seems odd.

copystring avatar Nov 22 '23 20:11 copystring