dresden-elektronik / deconz-rest-plugin

deCONZ REST-API plugin to control ZigBee devices
BSD 3-Clause "New" or "Revised" License
1.9k stars 499 forks source link

Tuya Smart Zigbee Temperature And Humidity Sensor, with LCD Display #6362

Closed bellerG closed 1 year ago

bellerG commented 2 years ago

Hi, is there a way to create a DDF for this device?

image


Product name: Tuya Zigbee Temperature And Humidity Sensor Manufacturer: _TZE200_locansqn Model identifier: TS0601 Device type : Sensor Shop Link

Screenshots

image image image

Mimiix commented 2 years ago

Hi,

Can you please provide all requested screenshots?

bellerG commented 2 years ago

Hi,

Can you please provide all requested screenshots?

Sorry, here are the remaining cluster attributes:

image image image image image image image

image

Smanar commented 2 years ago

Can try this one

{
  "schema": "devcap1.schema.json",
  "manufacturername": "_TZE200_locansqn",
  "modelid": "TS0601",
  "product": "TS0601",
  "sleeper": true,
  "status": "Gold",
  "subdevices": [
    {
      "type": "$TYPE_HUMIDITY_SENSOR",
      "restapi": "/sensors",
      "uuid": [
        "$address.ext",
        "0x01",
        "0x0405"
      ],
      "items": [
        {
          "name": "attr/id"
        },
        {
          "name": "attr/lastannounced"
        },
        {
          "name": "attr/lastseen"
        },
        {
          "name": "attr/manufacturername"
        },
        {
          "name": "attr/modelid"
        },
        {
          "name": "attr/name"
        },
        {
          "name": "attr/swversion"
        },
        {
          "name": "attr/type"
        },
        {
          "name": "attr/uniqueid"
        },
        {
          "name": "config/offset",
          "default": 0
        },
        {
          "name": "config/on"
        },
        {
          "name": "config/reachable"
        },
        {
          "name": "state/humidity",
          "parse": {"fn": "tuya", "dpid": 2, "eval": "Item.val = 10 * Attr.val;" },
          "read": {"fn": "tuya"},
          "default": 0
        },
        {
          "name": "config/battery",
          "parse": {"fn": "tuya", "dpid": 4, "eval": "Item.val = Attr.val;" },
          "read": {"fn": "none"},
          "default": 0
        },
        {
          "name": "state/lastupdated"
        }
      ]
    },
    {
      "type": "$TYPE_TEMPERATURE_SENSOR",
      "restapi": "/sensors",
      "uuid": [
        "$address.ext",
        "0x01",
        "0x0402"
      ],
      "items": [
        {
          "name": "attr/id"
        },
        {
          "name": "attr/lastannounced"
        },
        {
          "name": "attr/lastseen"
        },
        {
          "name": "attr/manufacturername"
        },
        {
          "name": "attr/modelid"
        },
        {
          "name": "attr/name"
        },
        {
          "name": "attr/swversion"
        },
        {
          "name": "attr/type"
        },
        {
          "name": "attr/uniqueid"
        },
        {
          "name": "config/offset",
          "default": 0
        },
        {
          "name": "config/battery",
          "parse": {"fn": "tuya", "dpid": 4, "eval": "Item.val = Attr.val;" },
          "read": {"fn": "none"},
          "default": 0
        },
        {
          "name": "config/on"
        },
        {
          "name": "config/reachable"
        },
        {
          "name": "state/lastupdated"
        },
        {
          "name": "state/temperature",
          "parse": {"fn": "tuya", "dpid": 1, "eval": "Item.val = 10 * Attr.val;" },
          "read": {"fn": "none"},
          "default": 0
        }
      ]
    }
  ]
}

I have cloned this one https://github.com/dresden-elektronik/deconz-rest-plugin/blob/master/devices/tuya/ih-k009_temp_hum_sensor.json

But I don't find the dpid used by this device on other zigbee project, so I m using the same one, if it doesn't work, can you enable deconz log (with "info" and "info_l2") and check for logs with "tuya" when heating the device for exemple.

bellerG commented 2 years ago

Can try this one

Hi Smanar,

Thanks a lot for this. I created the json and restarted the server.

It has now renamed the device (Humidity) and there is a battery indicator. But the clusters are still the old ones and it still says "Smart Plug" as the device type:

image

image

--

This is what I found in the logs: (The string "tuya" does not appear in the whole log - INFO a. INFO_L2)

    Zeile  587: 08:29:46:875 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"61","lastannounced":null,"lastseen":"2022-09-30T06:29Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Humidity 61","swversion":null,"type":"ZHAHumidity","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"},"e":"changed","id":"61","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"} (ret = 328)
    Zeile  589: 08:29:46:877 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"62","lastannounced":null,"lastseen":"2022-09-30T06:29Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Temperature 62","swversion":null,"type":"ZHATemperature","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"},"e":"changed","id":"62","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"} (ret = 334)
    Zeile  591: 08:29:46:914 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"61","lastannounced":null,"lastseen":"2022-09-30T06:29Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Humidity 61","swversion":null,"type":"ZHAHumidity","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"},"e":"changed","id":"61","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"} (ret = 328)
    Zeile  592: 08:29:46:916 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"62","lastannounced":null,"lastseen":"2022-09-30T06:29Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Temperature 62","swversion":null,"type":"ZHATemperature","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"},"e":"changed","id":"62","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"} (ret = 334)
    Zeile  593: 08:29:46:955 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"61","lastannounced":null,"lastseen":"2022-09-30T06:29Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Humidity 61","swversion":null,"type":"ZHAHumidity","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"},"e":"changed","id":"61","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"} (ret = 328)
    Zeile  594: 08:29:46:957 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"62","lastannounced":null,"lastseen":"2022-09-30T06:29Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Temperature 62","swversion":null,"type":"ZHATemperature","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"},"e":"changed","id":"62","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"} (ret = 334)
    Zeile 3956: 08:36:43:338 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"61","lastannounced":null,"lastseen":"2022-09-30T06:36Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Humidity 61","swversion":null,"type":"ZHAHumidity","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"},"e":"changed","id":"61","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"} (ret = 328)
    Zeile 3957: 08:36:43:339 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"62","lastannounced":null,"lastseen":"2022-09-30T06:36Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Temperature 62","swversion":null,"type":"ZHATemperature","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"},"e":"changed","id":"62","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"} (ret = 334)
    Zeile 4115: 08:36:58:742 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"61","lastannounced":null,"lastseen":"2022-09-30T06:36Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Humidity 61","swversion":null,"type":"ZHAHumidity","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"},"e":"changed","id":"61","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"} (ret = 328)
    Zeile 4116: 08:36:58:743 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"62","lastannounced":null,"lastseen":"2022-09-30T06:36Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Temperature 62","swversion":null,"type":"ZHATemperature","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"},"e":"changed","id":"62","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"} (ret = 334)
    Zeile 4117: 08:36:58:769 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"61","lastannounced":null,"lastseen":"2022-09-30T06:36Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Humidity 61","swversion":null,"type":"ZHAHumidity","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"},"e":"changed","id":"61","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405"} (ret = 328)
    Zeile 4118: 08:36:58:771 Websocket 172.16.0.11:48046 send message: {"attr":{"id":"62","lastannounced":null,"lastseen":"2022-09-30T06:36Z","manufacturername":"_TZE200_locansqn","modelid":"TS0601","name":"Temperature 62","swversion":null,"type":"ZHATemperature","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"},"e":"changed","id":"62","r":"sensors","t":"event","uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0402"} (ret = 334)

image


I deleted the device and reconnected it, this DDF was then automatically taken, but everything else is the same as above.

Smanar commented 2 years ago

That you see in deconz will not change, it's the reality, the type is Smart plug and will stay stay like that. But it will be updated in the API, can take a look in phoscon / help / API Information / sensors / (61 and 62) You will be able to see the device json, and I think thoses one will be good, except the temperature/humidity values.

for tuya device handled by DDF core, debug are visible with "info"

DBG_Printf(DBG_INFO, "TY_DATA_%s: seq %u, dpid: 0x%02X, type: 0x%02X, length: %u, val: %d\n",
                   rt, seq, dpid, dataType, dataLength, num.s32);

And my bad no "tuya" inside but "TYDATA"

bellerG commented 2 years ago

Hi Smanar,

image

I can find the sensor under "uniqueid":"a4:c1:38:15:c6:80:c2:f2-01-0405" and "uniqueid":"a4:c1:38:15:c6:80:c2: f2-01-0402" Unfortunately I can't find "TYDATA", here's an excerpt: debug_INFO+INFO_L2.txt

Smanar commented 2 years ago

the sensor is not yet displayed in Phoscon.

f the device json is good I can do nothing for that, can you share one of them from phoscon/help/apiInformation/sensor/X ? You don't have other third app to test ? But if you have value over API, it s probably phoscon that block it.

in DeConz-GUI the clusters for temperature/humidity are not displayed.

And it will be never displayed, this device don't have them

the cluster battery does not exist either (but the icon is displayed)

Lol, yes, and with red status, good question, I don't see where it is from.

Same for logs, if it's working, we can forget them.

So the device is working ATM ? (I mean over API)

bellerG commented 1 year ago

Hi Smanar, thx you for your answer.

the sensor is not yet displayed in Phoscon.

f the device json is good I can do nothing for that, can you share one of them from phoscon/help/apiInformation/sensor/X ? You don't have other third app to test ? But if you have value over API, it s probably phoscon that block it.

image image

Does that have to be done directly by Dresden-Elektronik, because the device pushes data, but unfortunately the clusters and settings are not available. e.g. Temperature correction so that the display on the device is also correct.

in DeConz-GUI the clusters for temperature/humidity are not displayed.

And it will be never displayed, this device don't have them

the cluster battery does not exist either (but the icon is displayed)

Lol, yes, and with red status, good question, I don't see where it is from.

I changed the batteries for the test. It updated immediately even though there is no cluster for it. image -> image

Same for logs, if it's working, we can forget them.

So the device is working ATM ? (I mean over API)

Yes exactly, in Phoscon it is not but via the API (ioBroker/Deconz) I have the values. image

Smanar commented 1 year ago

Does that have to be done directly by Dresden-Elektronik, because the device pushes data, but unfortunately the clusters and settings are not available. e.g. Temperature correction so that the display on the device is also correct.

You mean the "config/offset" value ? We can use fake cluster in the API, but deconz is the reality.

I changed the batteries for the test. It updated immediately even though there is no cluster for it.

Ok, I will ask immedialty how it's possible lol, serioulsy deconz is able to read device json to display icon ?

BTW if all is working, if the device is full working on third app, tell me if you want to make the PR or if I need to make it ?

bellerG commented 1 year ago

Does that have to be done directly by Dresden-Elektronik, because the device pushes data, but unfortunately the clusters and settings are not available. e.g. Temperature correction so that the display on the device is also correct.

You mean the "config/offset" value ? We can use fake cluster in the API, but deconz is the reality.

OK, that's a pity, because you can probably set a lot more setttings on the device over the Tuya app/gateway. e.g. also the push intervals from the device. See the video at 0:50 https://www.aliexpress.com/item/1005003634353180.html Or comments "Color: 1 pcs Logistics: AliExpress Standard Shipping excellent, works very well. There are a lot of settings, I can change update intervals for temp and for humidity."

In the delivery state, the values ​​only come at very large intervals: image vs. reference device image

I changed the batteries for the test. It updated immediately even though there is no cluster for it.

Ok, I will ask immedialty how it's possible lol, serioulsy deconz is able to read device json to display icon ?

I found the values ​​for this in the node info: image

BTW if all is working, if the device is full working on third app, tell me if you want to make the PR or if I need to make it ?

Can you do that, I'm not familiar with it. The basic functions battery/temperature/humidity are transferred.

Smanar commented 1 year ago

Ha yes there is a setting for the report interval. But this one is not in the temperature cluster but the tuya one.

DP = 17 = 0x11

I don't have tuya device, but it's perhaps posible using the GUI

Edit: I m searching a value to use with DDF

Smanar commented 1 year ago

Try adding in the DDF

        {
          "name": "config/sensitivity",
          "parse": {"fn": "tuya", "dpid": 17, "eval": "Item.val = Attr.val;" },
          "read": {"fn": "none"},
          "write": {"fn": "tuya", "dpid": 17, "dt": "0x2b", "eval": "Item.val"},
          "default": 0
        },
HahnBenjamin commented 1 year ago

You can try to pick some datapoints from my ddf for this device. I never finished up adding all the datapoints the device due to missing possibilities to map those to the existing attributes available in the DDF editor. Writing DPs to the device used to be a hit and miss, not sure if that was improved in the meanwhile. The latest release of the rest-plugin also enabled the device to successfully perform a time sync.

bellerG commented 1 year ago

Try adding in the DDF

        {
          "name": "config/sensitivity",
          "parse": {"fn": "tuya", "dpid": 17, "eval": "Item.val = Attr.val;" },
          "read": {"fn": "none"},
          "write": {"fn": "tuya", "dpid": 17, "dt": "0x2b", "eval": "Item.val"},
          "default": 0
        },

Ingenious, after a neutart it goes through the API. Not in DeConz, though.

Smanar commented 1 year ago

Not in DeConz, though.

Normal, same reason, to set it using deconz you need to use the tuya cluster, trying opening this cluster in the GUI, from my memory you have stuff to write value

Ingenious, after a neutart it goes through the API

But it work ? To know if I add it in the PR too.

Smanar commented 1 year ago

Writing DPs to the device used to be a hit and miss, not sure if that was improved in the meanwhile. The latest release of the rest-plugin also enabled the device to successfully perform a time sync.

@HahnBenjamin perhaps this PR can help for your problem https://github.com/dresden-elektronik/deconz-rest-plugin/pull/6323

bellerG commented 1 year ago

You're gonna have to adjust that:

          "name": "state/humidity",
          "parse": {"fn": "tuya", "dpid": 2, "eval": "Item.val = 100 * Attr.val;" },
bellerG commented 1 year ago

You can try to pick some datapoints from my ddf for this device. I never finished up adding all the datapoints the device due to missing possibilities to map those to the existing attributes available in the DDF editor. Writing DPs to the device used to be a hit and miss, not sure if that was improved in the meanwhile. The latest release of the rest-plugin also enabled the device to successfully perform a time sync.

The date and time on the LCD was displayed correctly from the beginning. I didn't have to do anything here.

Smanar commented 1 year ago

Ok so i just need to correct the humidity ? But the config/sensitivity is working or not ?

bellerG commented 1 year ago

Ok so i just need to correct the humidity?

Yes exactly, only here I had to adjust it.

But the config/sensitivity is working or not ?

Half like?! The value is displayed in the API and I can change it - changes are confirmed. However, the value is reset to the default value of 120 when a temperature change occurs.

I'll have to keep an eye on it.

Smanar commented 1 year ago

Ok so perhaps it's the problem described by @HahnBenjamin , but the swoop PR is still in waiting list.

BTW your DDF is relay more advanced than mine @HahnBenjamin, do you want to make a PR for it ?

bellerG commented 1 year ago

Ok so perhaps it's the problem described by @HahnBenjamin , but the swoop PR is still in waiting list.

BTW your DDF is relay more advanced than mine @HahnBenjamin, do you want to make a PR for it ?

BTW.: The battery display in DeConZ only works with the DDF from @Smanar, with the DDF from @HahnBenjamin it is not displayed.

Smanar commented 1 year ago

It's because he use "name": "state/battery",

And need to use config/battery for sensor

HahnBenjamin commented 1 year ago

I'll adjust the config for the device, try to add the missing data points and file a PR when done

bellerG commented 1 year ago

I'll adjust the config for the device, try to add the missing data points and file a PR when done

I can then test it when you have adjusted it.

github-actions[bot] commented 1 year ago

As there has not been any response in 21 days, this issue has been automatically marked as stale. At OP: Please either close this issue or keep it active It will be closed in 7 days if no further activity occurs.

github-actions[bot] commented 1 year ago

As there has not been any response in 28 days, this issue will be closed. @ OP: If this issue is solved post what fixed it for you. If it is not solved, request to get this opened again.