-
Notifications
You must be signed in to change notification settings - Fork 960
Improve Aqara E1 TRV (AGL001) with heartbeat parsing and write support #4604
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
base: dev
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #4604 +/- ##
==========================================
+ Coverage 92.28% 92.35% +0.07%
==========================================
Files 371 371
Lines 12155 12271 +116
==========================================
+ Hits 11217 11333 +116
Misses 938 938 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
61a26bc to
dce0a7a
Compare
Features:
- Add heartbeat parsing (attribute 0x00F7) to extract:
- Device temperature → new LocalDeviceTemperatureCluster
- Local temperature → Thermostat.local_temperature
- Battery percentage, preset, valve alarm, power outage count
- Add DeviceTemperature cluster for internal TRV temperature
- Add read/write support with Xiaomi manufacturer code for all
manufacturer-specific attributes
- Add calibrate attribute (0x0270) to trigger valve calibration
- Add setup mode detection (preset=3, "E11" on display)
Type-safe enums (improvement over Z2M):
- SystemMode: Off, Heat
- Preset: Manual, Auto, Away, Setup
- SensorMode: Internal, ExternalPaired, ExternalInput
(Z2M maps both external modes to just "external")
Code quality improvements:
- Use t.Bool for boolean attributes (window_detection, valve_detection,
valve_alarm, child_lock, window_open, calibrated, schedule)
- Define XIAOMI_MANUFACTURER_CODE constant
- Refactor heartbeat parser with _ZCL_TYPE_SIZES lookup table
- Add comprehensive type hints
Tests:
- Add tests for heartbeat parsing
Based on zigbee2mqtt/zigbee-herdsman-converters implementation.
WIP: External sensor switching and external temperature input
not yet implemented.
dce0a7a to
a43eb46
Compare
Test coverage for: - Float parsing (type 0x39) - Signed integers (int8, int16, int32) - Unknown data type handling - Valve alarm updates from heartbeat - Calibrate attribute write - Away preset temperature conversion - Attribute write by name - Preset setup mode detection
Coverage for: - Truncated heartbeat data (IndexError/struct.error handling) - Unknown attribute name in write_attributes
|
@cl445 I worked on similar quirk in past how, to make calibratiuon working. Without luck, it is nice to se that someone was able to do it how ever, most of time i try to set temperaturute /mod/something i get Failed to perform the action switch/turn_on. Failed to write attribute child_lock=1: Failed to perform the action number/set_value. Failed to write attribute away_preset_temperature=1200: <Status.INVALID_VALUE: 135> notification in HA any idea why ? |
|
@GamerClassN7 I opened this PR as WIP on purpose, to get early feedback and maybe some help. Thanks! |
I hame small experience with adding stuff to quirk if you use quirks V2 you can even add calibration button: it is then autmatically added to card in HASS. if you need any testing i am happy to help :) |
Tested on real device via Home Assistant: - child_lock, preset, system_mode: Use t.uint8_t instead of t.Bool/enums (device expects ZCL type 0x20, not Bool or enum8) - away_preset_temperature: Use t.uint32_t, no *100 multiplication (ZHA Number entity already sends centidegrees) - sensor attribute: Use t.uint8_t instead of SensorMode enum - Add firmware version parsing from heartbeat to Basic cluster All write operations now work correctly on real hardware.
Real Device Testing CompleteI've tested all write operations on an actual Aqara E1 TRV and fixed the attribute types based on the device's responses: Fixed Issues from @GamerClassN7's Report:
Additional Changes:
All operations now work correctly on real hardware! |
|
Thank you. I am looking forward to see this reviewed and approved. Looks good to me. I hope I'll get to try it as custom quirk on my home assistant and might give feedback. |
|
@cl445 I can confirm that the type errors are fixed 👍 Also, I think the HCAC Action entity should be removed, since it is not used by this model. Do you have any idea how to get external sensor calibration working? Reference:
also want to ask is there reason why are you using original v1 iteragion of quirks and not V2 whitch is mutch more easeally implementable on side of HASS ? :) Thank you once morre for your hard work !!!! |
- Replace AGL001 class with QuirkBuilder pattern - Add complete entity definitions: - Switches: child_lock, window_detection, valve_detection, schedule - Binary sensors: valve_alarm, window_open, calibrated - Selects: preset, sensor_mode - Number: away_preset_temperature - Button: calibrate (triggers valve calibration) - Update tests to use zigpy_device_from_v2_quirk fixture Note: ZHA has legacy hardcoded entities for this device which may cause duplicates. Those should be removed from ZHA in a follow-up.
|
@GamerClassN7 Thanks for your feedback! I've now addressed your suggestions:
Please test the updated version when you have time! |
The Aqara E1 TRV doesn't report running_state, but we can derive it from the heartbeat data: - Heat_State_On when setpoint > local_temperature and system is on - Idle (0) when at/above setpoint or system is off This fixes the "unknown" HVAC action in Home Assistant.
|
@GamerClassN7 I've also added running_state simulation now! The Aqara E1 TRV doesn't report
This should fix the "unknown" HVAC action in Home Assistant. 🎉 |

Summary
Improves the Aqara E1 Radiator Thermostat (AGL001) quirk with heartbeat parsing, firmware version display, tested attribute types, and migrates to QuirkBuilder v2 API.
Features
QuirkBuilder v2 Migration
Migrated from v1 (CustomDevice with signature/replacement) to v2 (QuirkBuilder) API with complete entity definitions:
ZHA currently has legacy hardcoded entity definitions for this device in
zha/application/platforms/. This causes duplicate entities (e.g., "Child lock" and "Kindersicherung"). These legacy definitions should be removed from ZHA in a follow-up PR once this quirk is merged.Running State Simulation
The Aqara E1 TRV doesn't report
running_state, so we simulate it based on the heartbeat data:setpoint > local_temperatureand system is onThis fixes the "unknown" HVAC action in Home Assistant.
Attribute Types (tested on real device)
All manufacturer-specific attributes now use correct ZCL types that the device accepts:
child_lockt.uint8_tpresett.uint8_tsystem_modet.uint8_tsensort.uint8_taway_preset_temperaturet.uint32_twindow_detection,valve_detection, etc.t.uint8_tCode Quality
XIAOMI_MANUFACTURER_CODEconstant instead of magic number_ZCL_TYPE_SIZESlookup tableRelated Work
This PR focuses on:
Out of scope (follow-up PR):
The following features require more complex implementation and should be addressed in a separate PR:
External temperature sensor functionality is being addressed in separate PRs:
Changes
_parse_heartbeat()function for TLV-encoded heartbeat messagesLocalDeviceTemperatureClusterfor device temperaturelocal_temperatureon thermostat from heartbeatzigpy_device_from_v2_quirkfixtureTest plan