Koenkk / zigbee-herdsman-converters

Collection of device converters to be used with zigbee-herdsman
MIT License
863 stars 2.85k forks source link

[New device support]: Tuya Soil sensor - TS0601 TZE284_g2e6cpnw #7609

Closed rare-magma closed 1 month ago

rare-magma commented 1 month ago

Link

https://www.aliexpress.com/item/1005007016626219.html

Database entry

{"id":19,"type":"EndDevice","ieeeAddr":"0xa4c1382e2ab69997","nwkAddr":40942,"manufId":4417,"manufName":"_TZE284_g2e6cpnw","powerSource":"Battery","modelId":"TS0601","epList":[1],"endpoints":{"1":{"profId":260,"epId":1,"devId":81,"inClusterList":[4,5,61184,0,60672],"outClusterList":[25,10],"clusters":{"genBasic":{"attributes":{"65487":14400,"65503":"��-\u0019��-\u0007\u0000\u0000\u0000\u0000\u0011","65506":56,"65508":1,"65534":0,"appVersion":77,"modelId":"TS0601","manufacturerName":"_TZE284_g2e6cpnw","powerSource":3,"zclVersion":3,"stackVersion":0,"hwVersion":1,"dateCode":""}}},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":77,"stackVersion":0,"hwVersion":1,"dateCode":"","zclVersion":3,"interviewCompleted":true,"meta":{"configured":-903893911},"lastSeen":1717618244776}

Comments

Device 0xa4c1382e2ab69997 with Zigbee model TS0601 and manufacturer name TZE284_g2e6cpnw.

I'm not sure if the 102 datapoint is correct. I got the following debug info:

Received Zigbee message from 'Soil sensor', type 'commandDataReport', cluster 'manuSpecificTuya', data:
 '{
  "dpValues": [
    { "data": { "data": [2], "type": "Buffer" }, "datatype": 4, "dp": 102 }
  ],
  "seq": 3840
}' 
from endpoint 1 with groupID 0

The device sends the following messages more frequently:

{
    "dpValues": [
      {
        "data": { "data": [0, 0, 0, 0], "type": "Buffer" },
        "datatype": 2,
        "dp": 3
      },
      {
        "data": { "data": [0, 0, 1, 19], "type": "Buffer" },
        "datatype": 2,
        "dp": 5
      },
      {
        "data": { "data": [0, 0, 3, 47], "type": "Buffer" },
        "datatype": 2,
        "dp": 110
      }
    ],
    "seq": 3072
  }
rare-magma commented 1 month ago

@Koenkk I'm not sure if this is setup correctly, the device's manual states that the temperature and humidity sensitivity can be adjusted so I guess there's at least a couple of tuyaDatapoints that are missing. I don't have a Tuya gateway to confirm this via Tuya IoT Platform tho.

Koenkk commented 1 month ago

the device's manual states that the temperature and humidity sensitivity can be adjusted so I guess there's at least a couple of tuyaDatapoints that are missing.

The only way to figure out that datapoint is via the TuYa gateway, but your PR looks OK and can be merged if you move it out of draft

rare-magma commented 1 month ago

@Koenkk I've moved the PR out of draft

Koenkk commented 1 month ago

thanks!

xpavli44 commented 2 weeks ago

@rare-magma does it work for you? I cannot see any data :(

Screenshot 2024-06-29 at 9 38 59

I've tried to dump the datapoints from TuYa

{"3":"Moisture",
"5":"Temperature",
"9":"Temp unit convert",
"14":"Battery level state",
"15":"Battery level",
"101":"Temp Alarm",
"102":"Moisture Alarm",
"103":"Maxtemp Set",
"104":"Minitemp Set",
"105":"Maxhum Set",
"106":"Minihum Set",
"107":"Temp Sensitivity",
"108":"Moisture Sensitivity",
"109":"Detection time",
"110":"Temperature",
"111":"Temp Sensitivity",
"112":"Maxtemp Set",
"113":"Minitemp Set"}

this is instructions set

temp_unit_convert   Enum    
{
  "range": [
    "c",
    "f"
  ]
}

this is status set

humidity    Integer 
{
  "unit": "%",
  "min": 0,
  "max": 100,
  "scale": 0,
  "step": 1
}
temp_current    Integer 
{
  "unit": "℃",
  "min": -100,
  "max": 600,
  "scale": 1,
  "step": 1
}
temp_unit_convert   Enum    
{
  "range": [
    "c",
    "f"
  ]
}
battery_state   Enum    
{
  "range": [
    "low",
    "middle",
    "high"
  ]
}
battery_percentage  Integer 
{
  "unit": "%",
  "min": 0,
  "max": 100,
  "scale": 0,
  "step": 1
}
xpavli44 commented 2 weeks ago

My mistake. I did not realise you need to push the button after pairing to send the data, it works :). If I find some time, I will try to add the rest of the DPs. ![Uploading Screenshot 2024-06-29 at 11.17.00.png…]()

rare-magma commented 2 weeks ago

@xpavli44 thanks for sharing the tuya datapoints dump, I just noticed that the battery state and battery level data points might be incorrectly mapped. Could you please confirm in the debug logs if the battery levels are correctly reported by your device?

rare-magma commented 2 weeks ago

it would be interesting to figure out how to adjust the sensitivity of the sensors as well

xpavli44 commented 2 weeks ago

@rare-magma I am not exactly sure how to do that. However I saw battery values over 100% reported by the device when it was hot (temp around 40C, which could be accurate as it was in sun shine).

rare-magma commented 2 weeks ago

@xpavli44 see https://www.zigbee2mqtt.io/advanced/support-new-devices/01_support_new_devices.html#_2-1-extending-the-external-definition for instructions on how to enable debug logs in zigbee2mqtt:

Now set the Zigbee2MQTT log_level to debug and enable the external definition by adding the following to your Zigbee2MQTT configuration.yaml.

advanced:
  log_level: debug
xpavli44 commented 2 weeks ago

I think I did it correctly, but I cannot see the debug level, just info. @rare-magma can you see some mistake in my setup?

info 2024-06-30 07:36:44MQTT publish: topic 'zigbee2mqtt/vlkost_puda_bazen', payload '{"battery":74.4,"battery_state":"low","linkquality":48,"soil_moisture":28,"temperature":23.6}'
Screenshot 2024-06-30 at 7 37 14 Screenshot 2024-06-30 at 7 39 10
xpavli44 commented 2 weeks ago

found it :)

[2024-06-30 08:42:33] debug: z2m: Received Zigbee message from 'vlkost_puda_bazen', type 'commandDataReport', cluster 'manuSpecificTuya', data '{"dpValues":[{"data":{"data":[0,0,0,0],"type":"Buffer"},"datatype":2,"dp":3},{"data":{"data":[0,0,1,2],"type":"Buffer"},"datatype":2,"dp":5},{"data":{"data":[0,0,3,16],"type":"Buffer"},"datatype":2,"dp":110}],"seq":6658}' from endpoint 1 with groupID 0 [2024-06-30 08:42:33] debug: zhc:tuya: Datapoint 110 not defined for '_TZE284_g2e6cpnw' with value 784 [2024-06-30 08:42:33] info: z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/vlkost_puda_bazen', payload '{"battery":75.3,"battery_state":"low","linkquality":3,"soil_moisture":0,"temperature":25.8}'

Mapping should probably look like this:

exposes: [e.temperature(), e.soil_moisture(), e.battery(), tuya.exposes.batteryState()],
    meta: {
        tuyaDatapoints: [
            [3, 'soil_moisture', tuya.valueConverter.raw],
            [5, 'temperature', tuya.valueConverter.divideBy10],
            [14, 'battery_state', tuya.valueConverter.batteryState],
            [15, 'battery', tuya.valueConverter.raw]
        ],
    },

but even with this, 75.3% battery state shows as low :(

rare-magma commented 2 weeks ago

@xpavli44 thanks for sharing the debug logs! I've created a PR with a new mapping based on your Tuya datapoint dump, could you please give it a try? https://github.com/Koenkk/zigbee-herdsman-converters/pull/7710

xpavli44 commented 2 weeks ago

@rare-magma I would love to, but I have no idea how to run the z2m code from branch in the homeassistant, I guess we would need @Koenkk to merge it and the I could use it from the edge version of the addon?

Koenkk commented 2 weeks ago

@rare-magma it's best to test the changes via an external converter first (example)