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

Support for human presence sensor ZG-205W #7

Open
vfontes opened this issue May 31, 2024 · 2 comments
Open

Support for human presence sensor ZG-205W #7

vfontes opened this issue May 31, 2024 · 2 comments

Comments

@vfontes
Copy link

vfontes commented May 31, 2024

Describe your device
ZG-205W is a human presence sensor, on the hps category.

It's very similar in functionality to the ZY-M100, but unfortunately the ZG-205W doesn't work with this plugin.

https://www.aliexpress.com/item/1005005951586853.html?spm=a2g0o.order_list.order_list_main.124.4d191802iS9vfz

  • I have a couple spare units of this sensor, and I'm willing to send them free of charge in case it's absolutely needed for development.

Partial Support?
No

Device Schema
Here's all the data I gathered from the iot.tuya.com API that I believe is relevant; feel free to ask me for anything else!

Get the specifications and properties of the device:


 {
   "result": {
     "category": "hps",
     "functions": [
       {
         "code": "sensitivity",
         "desc": "{\"unit\":\"x\",\"min\":0,\"max\":10,\"scale\":0,\"step\":1}",
         "name": "灵敏度",
         "type": "Integer",
         "values": "{\"unit\":\"x\",\"min\":0,\"max\":10,\"scale\":0,\"step\":1}"
       },
       {
         "code": "near_detection",
         "desc": "{\"unit\":\"cm\",\"min\":0,\"max\":1000,\"scale\":0,\"step\":10}",
         "name": "最近距离检测",
         "type": "Integer",
         "values": "{\"unit\":\"cm\",\"min\":0,\"max\":1000,\"scale\":0,\"step\":10}"
       },
       {
         "code": "far_detection",
         "desc": "{\"unit\":\"cm\",\"min\":0,\"max\":600,\"scale\":0,\"step\":10}",
         "name": "最远距离检测",
         "type": "Integer",
         "values": "{\"unit\":\"cm\",\"min\":0,\"max\":600,\"scale\":0,\"step\":10}"
       }
     ],
     "status": [
       {
         "code": "presence_state",
         "name": "存在状态",
         "type": "Enum",
         "values": "{\"range\":[\"none\",\"presence\"]}"
       },
       {
         "code": "sensitivity",
         "name": "灵敏度",
         "type": "Integer",
         "values": "{\"unit\":\"x\",\"min\":0,\"max\":10,\"scale\":0,\"step\":1}"
       },
       {
         "code": "near_detection",
         "name": "最近距离检测",
         "type": "Integer",
         "values": "{\"unit\":\"cm\",\"min\":0,\"max\":1000,\"scale\":0,\"step\":10}"
       },
       {
         "code": "far_detection",
         "name": "最远距离检测",
         "type": "Integer",
         "values": "{\"unit\":\"cm\",\"min\":0,\"max\":600,\"scale\":0,\"step\":10}"
       },
       {
         "code": "illuminance_value",
         "name": "光照度",
         "type": "Integer",
         "values": "{\"unit\":\"lux\",\"min\":0,\"max\":10000,\"scale\":0,\"step\":1}"
       }
     ]
   },
   "success": true,
   "t": 1717161651726,
   "tid": "9a35f5ae1f5011ef9b1bb62641605345"
 }

Get the instruction set of the device:

 {
   "result": {
     "category": "hps",
     "functions": [
       {
         "code": "sensitivity",
         "desc": "sensitivity",
         "name": "sensitivity",
         "type": "Integer",
         "values": "{\"unit\":\"x\",\"min\":0,\"max\":10,\"scale\":0,\"step\":1}"
       },
       {
         "code": "near_detection",
         "desc": "near detection",
         "name": "near detection",
         "type": "Integer",
         "values": "{\"unit\":\"cm\",\"min\":0,\"max\":1000,\"scale\":0,\"step\":10}"
       },
       {
         "code": "far_detection",
         "desc": "far detection",
         "name": "far detection",
         "type": "Integer",
         "values": "{\"unit\":\"cm\",\"min\":0,\"max\":600,\"scale\":0,\"step\":10}"
       }
     ]
   },
   "success": true,
   "t": 1717161690911,
   "tid": "b1926cb31f5011efb9130e1a774ae1f3"
 }

Get the status of a single device:

 {
   "result": [
     {
       "code": "presence_state",
       "value": "presence"
     },
     {
       "code": "sensitivity",
       "value": 9
     },
     {
       "code": "near_detection",
       "value": 200
     },
     {
       "code": "far_detection",
       "value": 200
     },
     {
       "code": "illuminance_value",
       "value": 78
     }
   ],
   "success": true,
   "t": 1717161739048,
   "tid": "ce44ebea1f5011ef9c7442b1fe1466b5"
 }

Query Things Data Model

 {
   "result": {
     "model": "{\"modelId\":\"esimak\",\"services\":[{\"actions\":[],\"code\":\"\",\"description\":\"\",\"events\":[],\"name\":\"默认服务\",\"properties\":[{\"abilityId\":1,\"accessMode\":\"ro\",\"code\":\"presence_state\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-renxingyidong\",\"attribute\":\"1664\"},\"name\":\"存在状态\",\"typeSpec\":{\"type\":\"enum\",\"range\":[\"none\",\"presence\"]}},{\"abilityId\":2,\"accessMode\":\"rw\",\"code\":\"sensitivity\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_mode\",\"attribute\":\"1152\"},\"name\":\"运动探测灵敏度\",\"typeSpec\":{\"type\":\"value\",\"max\":10,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"x\"}},{\"abilityId\":3,\"accessMode\":\"rw\",\"code\":\"near_detection\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-gongneng\",\"attribute\":\"1152\"},\"name\":\"运动探测最远距离\",\"typeSpec\":{\"type\":\"value\",\"max\":1000,\"min\":0,\"scale\":0,\"step\":10,\"unit\":\"cm\"}},{\"abilityId\":4,\"accessMode\":\"rw\",\"code\":\"far_detection\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-gongneng\",\"attribute\":\"1152\"},\"name\":\"呼吸探测最远距离\",\"typeSpec\":{\"type\":\"value\",\"max\":600,\"min\":0,\"scale\":0,\"step\":10,\"unit\":\"cm\"}},{\"abilityId\":101,\"accessMode\":\"ro\",\"code\":\"illuminance_value\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-liangdu\",\"attribute\":\"4096\"},\"name\":\"光照度\",\"typeSpec\":{\"type\":\"value\",\"max\":10000,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"lux\"}},{\"abilityId\":102,\"accessMode\":\"rw\",\"code\":\"sensitivity_cz\",\"description\":\"\",\"name\":\"呼吸探测灵敏度\",\"typeSpec\":{\"type\":\"value\",\"max\":10,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"x\"}},{\"abilityId\":103,\"accessMode\":\"rw\",\"code\":\"led_onoff\",\"description\":\"\",\"name\":\"指示灯\",\"typeSpec\":{\"type\":\"bool\"}},{\"abilityId\":104,\"accessMode\":\"rw\",\"code\":\"mode\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-HomeArm\",\"attribute\":\"4\"},\"name\":\"主机模式\",\"typeSpec\":{\"type\":\"enum\",\"range\":[\"arm\",\"disarm\",\"sos\",\"doorbell\"]}},{\"abilityId\":105,\"accessMode\":\"rw\",\"code\":\"wd_detection\",\"description\":\"\",\"name\":\"微动探测最远距离\",\"typeSpec\":{\"type\":\"value\",\"max\":600,\"min\":0,\"scale\":0,\"step\":10,\"unit\":\"cm\"}},{\"abilityId\":106,\"accessMode\":\"rw\",\"code\":\"sensitivity_wd\",\"description\":\"\",\"name\":\"微动探测灵敏度\",\"typeSpec\":{\"type\":\"value\",\"max\":10,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"x\"}},{\"abilityId\":107,\"accessMode\":\"rw\",\"code\":\"alarm_volume\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-yinliang\",\"attribute\":\"4096\"},\"name\":\"报警音量\",\"typeSpec\":{\"type\":\"enum\",\"range\":[\"low\",\"middle\",\"high\",\"mute\"]}},{\"abilityId\":108,\"accessMode\":\"rw\",\"code\":\"pir_delay\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_time3\",\"attribute\":\"4096\"},\"name\":\"有人保持时间\",\"typeSpec\":{\"type\":\"value\",\"max\":28800,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"s\"}},{\"abilityId\":109,\"accessMode\":\"rw\",\"code\":\"alarm_time\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_time2\",\"attribute\":\"4096\"},\"name\":\"报警时长\",\"typeSpec\":{\"type\":\"value\",\"max\":60,\"min\":1,\"scale\":0,\"step\":1,\"unit\":\"min\"}},{\"abilityId\":110,\"accessMode\":\"rw\",\"code\":\"mov_min_detection\",\"description\":\"\",\"name\":\"移动最小距离\",\"typeSpec\":{\"type\":\"value\",\"max\":1000,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"cm\"}},{\"abilityId\":111,\"accessMode\":\"rw\",\"code\":\"micro_min_detection\",\"description\":\"\",\"name\":\"微动最小距离\",\"typeSpec\":{\"type\":\"value\",\"max\":1000,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"cm\"}},{\"abilityId\":112,\"accessMode\":\"rw\",\"code\":\"bre_min_detection\",\"description\":\"\",\"name\":\"静止最小距离\",\"typeSpec\":{\"type\":\"value\",\"max\":1000,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"cm\"}},{\"abilityId\":113,\"accessMode\":\"rw\",\"code\":\"study_timer\",\"description\":\"\",\"name\":\"自适应检测时长\",\"typeSpec\":{\"type\":\"value\",\"max\":300,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"second\"}},{\"abilityId\":114,\"accessMode\":\"rw\",\"code\":\"start_study\",\"description\":\"\",\"name\":\"启动自适应\",\"typeSpec\":{\"type\":\"bool\"}},{\"abilityId\":115,\"accessMode\":\"rw\",\"code\":\"reset_setting\",\"description\":\"\",\"name\":\"恢复出厂设置\",\"typeSpec\":{\"type\":\"bool\"}},{\"abilityId\":116,\"accessMode\":\"ro\",\"code\":\"mov_status\",\"description\":\"\",\"name\":\"人体动作状态\",\"typeSpec\":{\"type\":\"enum\",\"range\":[\"none\",\"large_move\",\"small_move\",\"breathe\"]}},{\"abilityId\":117,\"accessMode\":\"rw\",\"code\":\"small_mov_start\",\"description\":\"\",\"name\":\"微动自检\",\"typeSpec\":{\"type\":\"bool\"}},{\"abilityId\":118,\"accessMode\":\"rw\",\"code\":\"breathe_start\",\"description\":\"\",\"name\":\"呼吸自测\",\"typeSpec\":{\"type\":\"bool\"}},{\"abilityId\":119,\"accessMode\":\"rw\",\"code\":\"false_alarm\",\"description\":\"\",\"name\":\"移动防误报检测\",\"typeSpec\":{\"type\":\"value\",\"max\":20,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"x\"}},{\"abilityId\":120,\"accessMode\":\"rw\",\"code\":\"false_breath\",\"description\":\"\",\"name\":\"呼吸防误报检测\",\"typeSpec\":{\"type\":\"bool\"}}]}]}"
   },
   "success": true,
   "t": 1717161832236,
   "tid": "05cebd601f5111ef9b1bb62641605345"
 }

Query Device Details

{
  "result": {
    "active_time": 1699986887,
    "bind_space_id": "18181642",
    "category": "hps",
    "create_time": 1699986887,
    "custom_name": "REDACTED",
    "icon": "smart/icon/ay1531985537002uUUZI/795816ee34ae450907eb799d1308706c.jpg",
    "id": "REDACTED",
    "ip": "REDACTED,
    "is_online": true,
    "lat": "-30.02",
    "local_key": "REDACTED",
    "lon": "-51.18",
    "model": "ZG-205W",
    "name": "MINI人体存在传感器 2",
    "product_id": "uykwakpl6rbxvjdd",
    "product_name": "MINI人体存在传感器",
    "sub": false,
    "time_zone": "-03:00",
    "update_time": 1717161390,
    "uuid": "880fc9d01a6858fd"
  },
  "success": true,
  "t": 1717161544353,
  "tid": "5a3587aa1f5011ef9b1bb62641605345"
}

Query Properties:

{
   "result": {
     "properties": [
       {
         "code": "presence_state",
         "custom_name": "",
         "dp_id": 1,
         "time": 1717161533044,
         "value": "presence"
       },
       {
         "code": "sensitivity",
         "custom_name": "",
         "dp_id": 2,
         "time": 1717161478539,
         "value": 9
       },
       {
         "code": "near_detection",
         "custom_name": "",
         "dp_id": 3,
         "time": 1717161478370,
         "value": 200
       },
       {
         "code": "far_detection",
         "custom_name": "",
         "dp_id": 4,
         "time": 1717161479503,
         "value": 200
       },
       {
         "code": "illuminance_value",
         "custom_name": "",
         "dp_id": 101,
         "time": 1717161601723,
         "value": 77
       },
       {
         "code": "sensitivity_cz",
         "custom_name": "",
         "dp_id": 102,
         "time": 1717161479673,
         "value": 9
       },
       {
         "code": "led_onoff",
         "custom_name": "",
         "dp_id": 103,
         "time": 1717161477604,
         "value": true
       },
       {
         "code": "mode",
         "custom_name": "",
         "dp_id": 104,
         "time": 1717161477346,
         "value": "disarm"
       },
       {
         "code": "wd_detection",
         "custom_name": "",
         "dp_id": 105,
         "time": 1717161478954,
         "value": 200
       },
       {
         "code": "sensitivity_wd",
         "custom_name": "",
         "dp_id": 106,
         "time": 1717161479341,
         "value": 9
       },
       {
         "code": "alarm_volume",
         "custom_name": "",
         "dp_id": 107,
         "time": 1717161477775,
         "value": "high"
       },
       {
         "code": "pir_delay",
         "custom_name": "",
         "dp_id": 108,
         "time": 1717161478196,
         "value": 5
       },
       {
         "code": "alarm_time",
         "custom_name": "",
         "dp_id": 109,
         "time": 1717161477945,
         "value": 2
       },
       {
         "code": "mov_min_detection",
         "custom_name": "",
         "dp_id": 110,
         "time": 1717161481267,
         "value": 0
       },
       {
         "code": "micro_min_detection",
         "custom_name": "",
         "dp_id": 111,
         "time": 1717161481445,
         "value": 0
       },
       {
         "code": "bre_min_detection",
         "custom_name": "",
         "dp_id": 112,
         "time": 1717161481705,
         "value": 0
       },
       {
         "code": "study_timer",
         "custom_name": "",
         "dp_id": 113,
         "time": 1717161480245,
         "value": 300
       },
       {
         "code": "start_study",
         "custom_name": "",
         "dp_id": 114,
         "time": 1717161480509,
         "value": false
       },
       {
         "code": "reset_setting",
         "custom_name": "",
         "dp_id": 115,
         "time": 1699986886980,
         "value": false
       },
       {
         "code": "mov_status",
         "custom_name": "",
         "dp_id": 116,
         "time": 1717161616517,
         "value": "large_move"
       },
       {
         "code": "small_mov_start",
         "custom_name": "",
         "dp_id": 117,
         "time": 1717161480665,
         "value": false
       },
       {
         "code": "breathe_start",
         "custom_name": "",
         "dp_id": 118,
         "time": 1717161480836,
         "value": false
       },
       {
         "code": "false_alarm",
         "custom_name": "",
         "dp_id": 119,
         "time": 1717161480847,
         "value": 0
       },
       {
         "code": "false_breath",
         "custom_name": "",
         "dp_id": 120,
         "time": 1717161481098,
         "value": false
       }
     ]
   },
   "success": true,
   "t": 1717161616726,
   "tid": "855b67d61f5011ef9b1bb62641605345"
 }
@vfontes
Copy link
Author

vfontes commented May 31, 2024

I think I may have found why it doesn't work: this device uses Tuya local protocol version 3.4:

[5/31/2024, 2:02:25 PM] [homebridge-tuya-platform-local] Discovered Escritorio Occupancy-local (eb9b1d79e56183587aaded) identified as OccupancySensor (3.4)
[Tuya] Changing ping gap for Escritorio Occupancy-local to 9s
[Tuya DEBUG] reconnect called for Escritorio Occupancy-local
[5/31/2024, 2:02:25 PM] [homebridge-tuya-platform-local] Connected to Escritorio Occupancy-local
[Tuya] Sending first query to Escritorio Occupancy-local (3.4)
[Tuya] Disconnected from Escritorio Occupancy-local
[Tuya] Closed connection with Escritorio Occupancy-local
[TuyaDiscovery] UDP from 192.168.1.21:6667 0x000055aa...0x0000aa55

Another project called localtuya has implemented 3.4 support, this may be useful: https://github.com/rospogrigio/localtuya/blob/d2fa4dc2a0306a9721c5660f163a3bf84b075f28/custom_components/localtuya/pytuya/__init__.py#L885

@vfontes
Copy link
Author

vfontes commented May 31, 2024

Oh wow, I got it working almost fully! Presence is correctly detected, but illuminance stays at 0,0001.

This is what I did:

  1. Replaced TuyaAccessory.js with https://github.com/iRayanKhan/homebridge-tuya/blob/main/lib/TuyaAccessory.js
  2. Commented out line 208 as it was throwing an error.

I'm no developer, but I'll give it a shot and try to create a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant