Move Sonoff occupancy config entities to quirks, or expose the ultrasonic delay for all occupancy sensors
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
The entities are in zha/application/platforms/number/init.py (SonoffPresenceSenorTimeout, PIROccupiedToUnoccupiedDelayConfigurationEntity) and zha/application/platforms/select.py (SonoffPresenceDetectionSensitivity). Compare them with the SNZB-06P and SNZB-03P quirks in zhaquirks/sonoff/, then check which snapshots in tests/data/devices hold ultrasonic_o_to_u_delay. Done when the chosen option is agreed in the thread and the affected snapshot tests still pass.
Written by the indexing model from the issue text.
Description
Problem
ZHA creates the "presence detection timeout" number entity only for two Sonoff models. SonoffPresenceSenorTimeout is a ZHA-native entity on OccupancySensing.ultrasonic_o_to_u_delay (0x0020), matched by models=frozenset({"SNZB-06P", "SNZB-03P"}), range 15–60 s, unique ID {ieee}-1-1030-presence_detection_timeout. Its sibling SonoffPresenceDetectionSensitivity (ultrasonic_u_to_o_threshold, unique ID suffix detection_sensitivity) uses the same model match.
So device-specific config lives in the ZHA library, and quirks have to work around it. The SNZB-03P quirk in zigpy/zha-device-handlers#4628 imports SonoffPresenceSenorTimeout from zha.application.platforms.number and uses .replaces_entity() only to change the minimum to 5 s and add a unit and device class. Meanwhile any other sensor exposing ultrasonic_o_to_u_delay gets no entity for it, while the PIR equivalent, PIROccupiedToUnoccupiedDelayConfigurationEntity, matches every OccupancySensing server cluster (0–65535 s, created when the attribute is supported and cached).
Raised in zigpy/zha-device-handlers#4628 (review thread on zhaquirks/sonoff/snzb03p.py). We need to decide between two directions:
Option A: move it to quirks entirely
- The SNZB-06P quirk (zhaquirks/sonoff/snzb06p.py) and the SNZB-03P quirk from zigpy/zha-device-handlers#4628 declare the timeout with
.number(...)onultrasonic_o_to_u_delayand the sensitivity with.enum(...)onultrasonic_u_to_o_threshold, each with its own range. - Existing entity IDs are kept with
unique_id_suffix="1030-presence_detection_timeout"andunique_id_suffix="1030-detection_sensitivity". v2 IDs don't include the cluster ID, so it has to be in the suffix. - After that quirks release, ZHA removes both Sonoff classes and
SonoffPresenceDetectionSensitivityEnum. This is the same coupled order used for the Inovelli and STARKVIND moves: quirks first, then ZHA bumps its quirks pin and drops the classes. - The ZHA match is on the model string alone (
eWeLink SNZB-03P,SONOFF SNZB-06Pin the snapshots). Check that the quirks cover every manufacturer string that currently gets the entities.
Option B: a generic ultrasonic delay entity for all occupancy sensors
- Add an
UltrasonicOccupiedToUnoccupiedDelayConfigurationEntityto ZHA next to the PIR one: no model filter, 0–65535 s, duration device class, seconds. Optionally add the u→o delay too, like the PIR pair. - The Sonoff devices must not end up with both the generic and the Sonoff entity, and their existing unique ID (
presence_detection_timeout) has to stay. Either the generic class takes over and keeps that suffix for those models, or the Sonoff-specific range moves to the quirks (Option A for the range only). - Other devices gain the entity. Of the current snapshots in
tests/data/devices,ultrasonic_o_to_u_delayis supported and cached onsunricher-hk-dim-0x00000036(value 0) andtze200-jva8ink8-ts0601(value 600, a Tuya TS0601 whose occupancy cluster comes from thetuya_motionquirk). For the Tuya one, check whether a write reaches the device at all before exposing it there. - The sensitivity select stays Sonoff-specific. Its 1/2/3 enum is not a generic meaning of
ultrasonic_u_to_o_threshold.
Either way
zigpy/zha-device-handlers#4628 imports SonoffPresenceSenorTimeout from ZHA. Removing or renaming that class breaks the quirk's import, so the quirk has to be updated in the same release step.
- Dominant language
- Python
- Stars
- 96
- Forks
- 84
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 30
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from zigpy/zha
-
Device override creates the generic entity instead of the vendor-specific one (Light instead of HueLight, ForceOnLight, MinTransitionLight)Possibly taken @zigpy-review-bot claimed this today. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Each time a device becomes available again, ZHA adds another firmware update listener that is never releasedPossibly taken @zigpy-review-bot claimed this 1 day ago. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Devices that left the network are re-initialized on every availability check, reading attributes from a device that is gonePossibly taken @zigpy-review-bot claimed this 1 day ago. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
device specific quirks
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pimutils/vdirsyncer#1242 ·
-
priority:P2
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
QuantConnect/lean-cli#792 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
open-webui/open-webui#35360 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Suggest link: Destiny Verify (MIT zero-dependency pre-commit security, citation & link hygiene CLI)Open
Difficulty 1/5 Under an hour Newbie friendliness 68/100