Skip to content
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

Zigbee Thermostat example does not work with commercial temperature sensors #10808

Open
1 task done
FrankX0 opened this issue Jan 5, 2025 · 14 comments
Open
1 task done
Assignees
Labels
Area: Zigbee Issues and Feature Request about Zigbee Status: Community help needed Issue need help from any member from the Community.

Comments

@FrankX0
Copy link

FrankX0 commented Jan 5, 2025

Board

ESP32-C6

Device Description

None

Hardware Configuration

None

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

Example sketch hangs when bound to a commercial Zigbee temperature sensor (e.g. TS0201).
Sketch works when bound to example temperature sensor sketch on other ESP32-C6.
Both getSensorSettings() (blocks) and setTemperatureReporting() (no response) are not working.
Functions readManufacturer() and readModel() work correctly though.

Sketch

Default Thermostat example sketch (Zigbee_Thermostat.ino)

Debug Message

[    57][I][ZigbeeCore.cpp:138] zigbeeInit(): List of registered[  2631][I][ZigbeeCore.cpp:328] esp_zb_app_signal_handler(): Network(0x0a8e) closed, devices joining not allowed.
[  2642][I][ZigbeeCore.cpp:260] esp_zb_app_signal_handler(): Formed network successfully (Extended PAN ID: 8c:bf:ea:ff:fe:b9:c6:c4, PAN ID: 0x0a8e, Channel:15, Short Address: 0x0000)
[  3125][I][ZigbeeCore.cpp:326] esp_zb_app_signal_handler(): Network(0x0a8e) is open for 180 seconds
[  3135][I][ZigbeeCore.cpp:275] esp_zb_app_signal_handler(): Network steering started
Waiting for Temperature sensor to bound to the thermostat.........................
[ 15421][I][ZigbeeCore.cpp:298] esp_zb_app_signal_handler(): New device commissioned or rejoined (short: 0x2727)
[ 15538][I][ZigbeeThermostat.cpp:48] findCb(): Found temperature sensor
[ 15545][I][ZigbeeThermostat.cpp:72] findCb(): Request temperature sensor to bind us
[ 15552][I][ZigbeeThermostat.cpp:88] findCb(): Bind temperature sensor
[ 15562][I][ZigbeeThermostat.cpp:35] bindCb(): The temperature sensor originating from address(0x2727) on endpoint(1)
[ 15643][I][ZigbeeThermostat.cpp:163] getSensorSettings(): Sending 'read temperature' command
[ 16920][I][ZigbeeCore.cpp:326] esp_zb_app_signal_handler(): Network(0x0a8e) is open for 180 seconds
[196921][I][ZigbeeCore.cpp:328] esp_zb_app_signal_handler(): Network(0x0a8e) closed, devices joining not allowed.

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@FrankX0 FrankX0 added the Status: Awaiting triage Issue is waiting for triage label Jan 5, 2025
@SuGlider SuGlider added the Area: Zigbee Issues and Feature Request about Zigbee label Jan 5, 2025
@P-R-O-C-H-Y
Copy link
Member

Hi @FrankX0, is the getTemperature() working? Maybe the Zigbee temperature sensor (e.g. TS0201). does not have the reporting cluster implemented and also they don't have any sensor settings attributes implemented. Are you able if you connect the temperature to any system like HomeAssistant or Z2MQTT to set the reporting there or receive the temp. sensor settings?

@P-R-O-C-H-Y
Copy link
Member

I will fix the blocking getSensorSettings(), there should be some kind of timeout, not to wait forever.

@FrankX0
Copy link
Author

FrankX0 commented Jan 6, 2025

getTemperature() also does not give any response.
I guess the zbThermostat.onTempRecieve(recieveSensorTemp) callback should trigger, right?
(minor BTW: the code uses incorrectly written recieve instead of receive).

This sensor (and others) connect successfully to Z2MQTT and reports its data as expected.
If it helps, this is how the clusters of this device are reported in Z2MQTT:
image

Added

I have the same issue with different sensors, but all point to Tuya.
I looked at how Z2M deals with these sensors, and found the following in tuya.js:

        fingerprint: [
            { modelID: 'TS0201', manufacturerName: '_TZ3000_bguser20' },
            { modelID: 'TS0201', manufacturerName: '_TZ3000_yd2e749y' },
            { modelID: 'TS0201', manufacturerName: '_TZ3000_6uzkisv2' },
            { modelID: 'TS0201', manufacturerName: '_TZ3000_xr3htd96' },
            { modelID: 'TS0201', manufacturerName: '_TZ3000_fllyghyj' },
            { modelID: 'TS0201', manufacturerName: '_TZ3000_saiqcn0y' },
        ],
        model: 'WSD500A',
        vendor: 'TuYa',
        description: 'Temperature & humidity sensor',
        fromZigbee: [fzLocal.TS0201_battery, fromZigbee_1.default.temperature, fromZigbee_1.default.humidity],
        toZigbee: [],
        exposes: [e.battery(), e.temperature(), e.humidity(), e.battery_voltage()],
        configure: tuya.configureMagicPacket,
        whiteLabel: [
            tuya.whitelabel('TuYa', 'TH02Z', 'Temperature and humidity sensor', ['_TZ3000_fllyghyj', '_TZ3000_saiqcn0y']),
        ],

I was triggered by configure: tuya.configureMagicPacket
Not sure yet what it means, but could be related.

@lsroka76
Copy link

lsroka76 commented Jan 7, 2025

On my code, which is somehow based on or derived from that example TS0201 is working properly (temperature and humidity).
Look at Zigbee_Gateway_2

@P-R-O-C-H-Y
Copy link
Member

@lsroka76 If you can help it would be great. I have the Sonoff temp/hum sensor and I have no issues getting the temperature when using the Thermostat example.

@P-R-O-C-H-Y P-R-O-C-H-Y added Status: Community help needed Issue need help from any member from the Community. and removed Status: In Progress Issue is in progress labels Jan 7, 2025
@lsroka76
Copy link

lsroka76 commented Jan 7, 2025

@FrankX0 1. Can You factory reset Zigbee stack in your Thermostat example (or upload it with Erase flash enabled).
2. Then while network is open run pairing in TS 0201 (needle in the hole for > 5 seconds, confirmed by blinking blue LED).
3. Send here output (set Core output to Verbose in Arduino IDE, please).
4. Don't pair C6 temperature sensor (best switch it off).

@FrankX0
Copy link
Author

FrankX0 commented Jan 7, 2025

@FrankX0 1. Can You factory reset Zigbee stack in your Thermostat example (or upload it with Erase flash enabled). 2. Then while network is open run pairing in TS 0201 (needle in the hole for > 5 seconds, confirmed by blinking blue LED). 3. Send here output (set Core output to Verbose in Arduino IDE, please). 4. Don't pair C6 temperature sensor (best switch it off).

@lsroka76 thanks for helping out!
This is the result:

.[ 13049][I][ZigbeeCore.cpp:298] esp_zb_app_signal_handler(): New device commissioned or rejoined (short: 0x91da)
[ 13049][V][ZigbeeCore.cpp:302] esp_zb_app_signal_handler(): Device capabilities: 0x80
[ 13167][I][ZigbeeThermostat.cpp:48] findCb(): Found temperature sensor
[ 13168][D][ZigbeeThermostat.cpp:55] findCb(): Temperature sensor found: short address(0x91da), endpoint(1)
[ 13168][D][ZigbeeThermostat.cpp:59] findCb(): Request temperature sensor to bind us
[ 13169][D][ZigbeeThermostat.cpp:65] findCb(): Bind temperature sensor
[ 13169][I][ZigbeeThermostat.cpp:72] findCb(): Request temperature sensor to bind us
[ 13170][I][ZigbeeThermostat.cpp:88] findCb(): Bind temperature sensor
[ 13173][I][ZigbeeThermostat.cpp:35] bindCb(): The temperature sensor originating from address(0x91da) on endpoint(1)
[ 13241][I][ZigbeeThermostat.cpp:163] getSensorSettings(): Sending 'read temperature' command
[ 13490][V][ZigbeeThermostat.cpp:38] bindCb(): Local binding success
[ 13497][V][ZigbeeHandlers.cpp:82] zb_cmd_read_attr_resp_handler(): Read attribute response: from address(0x91da) src endpoint(1) to dst endpoint(5) cluster(0x402)
[ 13498][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(0), cluster(0x402), attribute(0x1), type(0x29), value(106)
[ 13499][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(0), cluster(0x402), attribute(0x2), type(0x29), value(33)
[ 13499][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(134), cluster(0x402), attribute(0x3), type(0x0), value(0)
[ 14471][V][ZigbeeCore.cpp:339] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK
[ 14547][I][ZigbeeCore.cpp:326] esp_zb_app_signal_handler(): Network(0x9df9) is open for 180 seconds

Note that the sketch hangs at getSensorSettings(), although the sensor seems to respond (4x Read attribute response)?

@lsroka76
Copy link

lsroka76 commented Jan 7, 2025

I've added endpoints, clusters and cluster attributes discovery to my code and here is result for TS0201:

22:10:28.194 -> [ 44607][I][ZigbeeHandlers.cpp:181] zb_core_cmd_disc_attr_resp_handler(): Attribute Discovery Message - attribute id 0, data type 41 22:10:28.194 -> [ 44607][I][ZigbeeHandlers.cpp:181] zb_core_cmd_disc_attr_resp_handler(): Attribute Discovery Message - attribute id 1, data type 41 22:10:28.236 -> [ 44608][I][ZigbeeHandlers.cpp:181] zb_core_cmd_disc_attr_resp_handler(): Attribute Discovery Message - attribute id 2, data type 41

and in Your logs we can see:

[ 13499][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(134), cluster(0x402), attribute(0x3), type(0x0), value(0)

which confirms above discovery - TS0201 doesn't have attribute id 3 (temperature tolerance).

So try to change this code first:

uint16_t attributes[] = { ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID };

to

uint16_t attributes[] = { ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID};

and this code:

if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_U16) { uint16_t tolerance = attribute->data.value ? *(uint16_t *)attribute->data.value : 0; _tolerance = 1.0 * tolerance / 100; read_config++; } if (read_config == 3) { read_config = 0;

to that

_tolerance = 0; if (read_config == 2) { read_config = 0;

and show Your logs.

@FrankX0
Copy link
Author

FrankX0 commented Jan 8, 2025

Thanks! The first part is working now:

[ 13130][D][ZigbeeThermostat.cpp:65] findCb(): Bind temperature sensor
[ 13131][I][ZigbeeThermostat.cpp:72] findCb(): Request temperature sensor to bind us
[ 13131][I][ZigbeeThermostat.cpp:88] findCb(): Bind temperature sensor
[ 13135][I][ZigbeeThermostat.cpp:35] bindCb(): The temperature sensor originating from address(0x42cd) on endpoint(1)
[ 13247][I][ZigbeeThermostat.cpp:164] getSensorSettings(): Sending 'read temperature' command
[ 13307][V][ZigbeeThermostat.cpp:38] bindCb(): Local binding success
[ 13363][V][ZigbeeHandlers.cpp:82] zb_cmd_read_attr_resp_handler(): Read attribute response: from address(0x42cd) src endpoint(1) to dst endpoint(5) cluster(0x402)
[ 13364][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(0), cluster(0x402), attribute(0x1), type(0x29), value(103)
[ 13364][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(0), cluster(0x402), attribute(0x2), type(0x29), value(33)
Temperature sensor settings: min 16.39°C, max 20.81°C, tolerance 0.00°C
[ 14436][V][ZigbeeCore.cpp:339] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK
[ 14559][I][ZigbeeCore.cpp:326] esp_zb_app_signal_handler(): Network(0xe4fe) is open for 180 seconds

So getSensorSettings is working now.
But still no automatic reporting by the sensor.
setTemperatureReporting also likely needs modification. Not sure if this will trigger the automatic sensor updates?

Thanks again for your help.

@lsroka76
Copy link

lsroka76 commented Jan 9, 2025

@FrankX0 Try to comment out these two lines in Zigbee_Thermostat.ino:

zbThermostat.getSensorSettings();

zbThermostat.setTemperatureReporting(0, 10, 2);

@FrankX0
Copy link
Author

FrankX0 commented Jan 9, 2025

Already tried that: nothing changes.

Result of following commands:

zbThermostat.getTemperature();
[ 46088][I][ZigbeeThermostat.cpp:145] getTemperature(): Sending 'read temperature' command
[ 46385][V][ZigbeeHandlers.cpp:134] zb_cmd_default_resp_handler(): Received default response: from address(0x6426), src_endpoint(1) to dst_endpoint(5), cluster(0x402) with status 0x84
zbThermostat.setTemperatureReporting(0, 1, 0);
[ 23636][I][ZigbeeThermostat.cpp:200] setTemperatureReporting(): Sending 'configure reporting' command
[ 23974][V][ZigbeeHandlers.cpp:134] zb_cmd_default_resp_handler(): Received default response: from address(0xaf45), src_endpoint(1) to dst_endpoint(5), cluster(0x402) with status 0x84

In both cases the response is 0x84 (unsupported command?).

So, after the sensor is bound there are no sensor updates received.
Once bound, should the sensor start sending updates automatically, or should it be configured first to do so?
And if so, how? The setTemperatureReporting apparently is not supported.

@lsroka76
Copy link

In my setup TS0201 starts to send reporting just after joining network and sends reports after each temp/hum change.
Maybe don't invoke any commands?

@lsroka76
Copy link

Try to compile Z2S_Gateway example from my library:
Z2S Library

@FrankX0
Copy link
Author

FrankX0 commented Jan 11, 2025

Try to compile Z2S_Gateway example from my library: Z2S Library

I had some compilation errors:

C:\Users\Frank\OneDrive\Documents\Arduino\Zigbee_Gateway_2\ZigbeeGateway.cpp:228:20: error: cannot convert 'esp_zb_zcl_cmd_direction_t' to 'esp_zb_zcl_report_direction_t' in initialization
  228 |       .direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV, //0x00, //ESP_ZB_ZCL_REPORT_DIRECTION_SEND, ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV

Changed it to ESP_ZB_ZCL_REPORT_DIRECTION_SEND, which resolved the error.
Then:

c:\Users\Frank\OneDrive\Documents\Arduino\libraries\Zigbee\src\ep\ZigbeeThermostat.h:62:8: error: 'void ZigbeeThermostat::zbAttributeRead(uint16_t, const esp_zb_zcl_attribute_t*)' marked 'override', but does not override
   62 |   void zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute) override;

I removed the override. Then it compiled.

The sensor gets bound and reports temperature and humidity!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Zigbee Issues and Feature Request about Zigbee Status: Community help needed Issue need help from any member from the Community.
Projects
None yet
Development

No branches or pull requests

4 participants