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

Use different Tuya cluster for _TZE200_yjjdcqsq temp sensor #3244

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Maddimax
Copy link
Contributor

@Maddimax Maddimax commented Jul 5, 2024

Proposed change

When using Var04, my temp sensor cannot read any values. With Var03 the main values (temp, humidity and battery can be read).

Additional information

The raw signature of the device:

"signature": {
      "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
      "endpoints": {
        "1": {
          "profile_id": "0x0104",
          "device_type": "0x0051",
          "input_clusters": [
            "0x0000",
            "0x0004",
            "0x0005",
            "0xef00"
          ],
          "output_clusters": [
            "0x000a",
            "0x0019"
          ]
        }
      },
      "manufacturer": "_TZE200_yjjdcqsq",
      "model": "TS0601"
    },

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

When using Var04, my temp sensor cannot read any values. With Var03 the main values (temp, humidity and battery can be read).
@Maddimax
Copy link
Contributor Author

Maddimax commented Jul 5, 2024

@Jonas-Meyer97 Since you added the device to variant 04 in the first place, can you check and see if your devices still work with Variant 03 as well?

Copy link

codecov bot commented Jul 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.18%. Comparing base (e3c115e) to head (e7f813b).
Report is 3 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #3244   +/-   ##
=======================================
  Coverage   88.18%   88.18%           
=======================================
  Files         301      301           
  Lines        9412     9412           
=======================================
  Hits         8300     8300           
  Misses       1112     1112           

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

@TheJulianJES TheJulianJES added the Tuya Request/PR regarding a Tuya device label Jul 5, 2024
@Jonas-Meyer97
Copy link
Contributor

@Maddimax Sorry, I wasn't able to try it earlier. With variant 03, my device no longer reports the battery status. I tested it with two different devices and waited 24 hours. It seems there are two different variants for _TZE200_yjjdcqsq. I have attached the signature for my device, which is the same for all my devices reporting as _TZE200_yjjdcqsq. Perhaps it is possible to filter on a different parameter between these two variants, such as device_type or the available input_clusters. Unfortunately, I'm a novice with Zigpy and can't contribute much, but I hope this information is helpful.

"signature": {
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
	"1": {
	  "profile_id": "0x0104",
	  "device_type": "0x0302",
	  "input_clusters": [
		"0x0000",
		"0x0001",
		"0x0004",
		"0x0005",
		"0x0402",
		"0x0405",
		"0xef00"
	  ],
	  "output_clusters": [
		"0x000a",
		"0x0019"
	  ]
	}
  },
  "manufacturer": "_TZE200_yjjdcqsq",
  "model": "TS0601"
}

@TheJulianJES
Copy link
Collaborator

Hmm, it's not ideal that there are apparently two almost identical versions of this sensor.
The only difference between the two different Tuya manufacturer clusters is indeed the battery:

class TemperatureHumidityManufCluster(TuyaMCUCluster):
"""Tuya Manufacturer Cluster with Temperature and Humidity data points."""
dp_to_attribute: dict[int, DPToAttributeMapping] = {
1: DPToAttributeMapping(
TuyaTemperatureMeasurement.ep_attribute,
"measured_value",
converter=lambda x: x * 10, # decidegree to centidegree
),
2: DPToAttributeMapping(
TuyaRelativeHumidity.ep_attribute,
"measured_value",
# converter=lambda x: x * 10, --> move conversion to TuyaRelativeHumidity cluster
),
4: DPToAttributeMapping(
TuyaPowerConfigurationCluster2AAA.ep_attribute,
"battery_percentage_remaining",
converter=lambda x: x * 2, # double reported percentage
),
}
data_point_handlers = {
1: "_dp_2_attr_update",
2: "_dp_2_attr_update",
4: "_dp_2_attr_update",
}
class TemperatureHumidityBatteryStatesManufCluster(TuyaMCUCluster):
"""Tuya Manufacturer Cluster with Temperature and Humidity data points. Battery states 25, 50 and 100%."""
dp_to_attribute: dict[int, DPToAttributeMapping] = {
1: TemperatureHumidityManufCluster.dp_to_attribute[1],
2: TemperatureHumidityManufCluster.dp_to_attribute[2],
3: DPToAttributeMapping(
TuyaPowerConfigurationCluster2AAA.ep_attribute,
"battery_percentage_remaining",
converter=lambda x: {0: 25, 1: 50, 2: 100}[x], # double reported percentage
),
}
data_point_handlers = {
1: "_dp_2_attr_update",
2: "_dp_2_attr_update",
3: "_dp_2_attr_update",
}

We might be able to parse Tuya datapoints 3 and 4 and map them onto the same battery_percentage_remaining attribute.
I'll put this PR into draft for now.

@TheJulianJES TheJulianJES marked this pull request as draft August 3, 2024 23:31
@TheJulianJES TheJulianJES added the help wanted Extra attention is needed label Aug 3, 2024
@TheJulianJES TheJulianJES changed the title _TZE200_yjjdcqsq: Use Var03 instead of Var04 Use different Tuya cluster for _TZE200_yjjdcqsq temp sensor Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants