Skip to content

Add Tuya motion sensor _TZE200_agumlajc quirk #4027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

ausfas
Copy link

@ausfas ausfas commented Apr 25, 2025

Proposed change

This PR adds a custom quirk for the Mercator Ikuü TS0601 Motion Sensor (_TZE200_agumlajc), which is a Tuya-based combination sensor.

The quirk enables full functionality for:

  • Occupancy (motion) detection using DP104
  • Temperature (DP1)
  • Humidity (DP2)
  • Illuminance (DP101)
  • Motion timeout / fade time setting
  • Sensitivity, distance, and other optional datapoints

The quirk was developed using the TuyaQuirkBuilder framework, and tested successfully with ZHA in Home Assistant on firmware 0x00000042.

Additional information

This device previously paired but was non-functional under ZHA without a quirk. The implementation uses datapoint references confirmed via Zigbee2MQTT and verified manually through ZHA logs and testing.

This is a non-breaking addition and does not interfere with other Tuya TS0601-based devices.

Let me know if naming or structure adjustments are needed to align with ZHA device handler conventions.

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works

Copy link

codecov bot commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.20%. Comparing base (e4844d4) to head (64f12af).
Report is 7 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4027      +/-   ##
==========================================
+ Coverage   91.17%   91.20%   +0.02%     
==========================================
  Files         334      335       +1     
  Lines       10858    10891      +33     
==========================================
+ Hits         9900     9933      +33     
  Misses        958      958              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheJulianJES TheJulianJES added the Tuya Request/PR regarding a Tuya device label Apr 29, 2025
@TheJulianJES TheJulianJES changed the title Add quirk for TS0601 Motion Sensor (_TZE200_agumlajc) Add Tuya motion sensor _TZE200_agumlajc quirk Apr 29, 2025
Copy link
Collaborator

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should put this in the tuya_motion.py file instead.
We've generally started using the tuya_ prefix for files containing Tuya v2 quirks.
Other similar motion quirks are already in that file as well.

And TS0601 is used by basically all Tuya devices unfortunately (from dimmers to thermostats, ...).

max_value=1000,
step=1,
translation_key="brightness_threshold",
fallback_name="Brightness Threshold",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to HA naming conventions, please only capitalize the first word, i.e. this should be "Brightness threshold" for the fallback_name (which will be the basis for US English translations when it's merged into HA).
Please also change the other names.

Comment on lines 50 to 57
.tuya_binary_sensor(
dp_id=104,
attribute_name="motion",
device_class=BinarySensorDeviceClass.MOTION,
entity_type=EntityType.STANDARD,
translation_key="motion",
fallback_name="Motion",
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not wrong, but instead of directly mapping a Tuya dp to a v2 quirk entity, we've generally mapped the dp to a (fake) ZCL attribute on the IasZone cluster or the OccupancySensing cluster using TuyaOccupancySensing or TuyaMotionWithReset in tuya_motion.py, then mapping the dp with tuya_dp. See the examples in that file.
We may want to follow that here as well (and/or even introduce a tuya_motion method at some point instead).

@TheJulianJES TheJulianJES added waiting for changes Waiting for changes to the PR v2 quirk Quirks using v2 API. Might add custom entities that need translation keys in HA. labels Apr 29, 2025
@ausfas ausfas force-pushed the add_ts0601_motion branch from 321d8c5 to f753c97 Compare April 30, 2025 10:10
@ausfas
Copy link
Author

ausfas commented Apr 30, 2025

Thanks @TheJulianJES! I’ve:

Moved the quirk into tuya_motion.py alongside similar Tuya motion devices

Replaced low-level .tuya_dp() with .tuya_binary_sensor() for motion DP (104) to align with other Tuya v2 quirks

Standardized fallback names to use sentence-style capitalization

Let me know if anything further is needed.
image

@TheJulianJES TheJulianJES removed the waiting for changes Waiting for changes to the PR label May 3, 2025
@ausfas
Copy link
Author

ausfas commented May 7, 2025

Hi @TheJulianJES, do I need to do anything at my end or will you merge this into main branch later ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tuya Request/PR regarding a Tuya device v2 quirk Quirks using v2 API. Might add custom entities that need translation keys in HA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants