dresden-elektronik / deconz-rest-plugin

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

SONOFF SNZB-03P #7821

Open febalci opened 4 days ago

febalci commented 4 days ago

Is there already an existing issue for this?

Product name

SONOFF SNZB-03P Motion Sensor Link

Manufacturer

SONOFF

Model identifier

SNZB-03P

Device type to add

Sensor

Node info

node

Endpoints and clusters

node_b

Basic

basic_a

Further relevant clusters

Power Configuration

power

Identify

identify

Occupancy Sensing

occupancy

IAS Zone

IAS
febalci commented 4 days ago

I used DDF fromn SNZP-06P as with some changes like below; the 'state/presence' and 'config/battery' works fine. cl:0x406, attribute 0x0020 is the delay time in seconds for occupied to unoccupied delay timeout. Good thing is you can set it down to 5 seconds and it works. I can change it from within phoscon but in this DDF i couldn't make it work via Home Assistant deconz device settings. Also, the state/dark setting is nowhere to be seen in HA deconz settings. So i need to correct 'config/duration', 'state/dark' and the 'bindings' parts somehow...


{
  "schema": "devcap1.schema.json",
  "manufacturername": "eWeLink",
  "modelid": "SNZB-03P",
  "vendor": "SONOFF",
  "product": "SNZB-03P",
  "sleeper": false,
  "status": "Draft",
  "path": "/devices/snzb-03p.json",
  "subdevices": [
    {
      "type": "$TYPE_PRESENCE_SENSOR",
      "restapi": "/sensors",
      "uuid": [
        "$address.ext",
        "0x01",
        "0x0406"
      ],
      "fingerprint": {
        "profile": "0x0104",
        "device": "0x0107",
        "endpoint": "0x01",
        "in": [
          "0x0000",
          "0x0001",
          "0x0406",
          "0x0500",
          "0xFC11"
        ]
      },
      "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/battery",
          "parse": {
            "at": "0x0021",
            "cl": "0x0001",
            "ep": 1,
            "eval": "Item.val = Attr.val / 2;",
            "fn": "zcl:attr"
          },
          "default": 0
        },
        {
          "name": "config/duration",
          "refresh.interval": 3600,
          "read": {
            "at": "0x0020",
            "cl": "0x0406",
            "ep": 1,
            "fn": "zcl:attr"
          },
          "write": {
            "at": "0x0020",
            "cl": "0x0406",
            "dt": "0x21",
            "ep": 1,
            "eval": "Item.val",
            "fn": "zcl:attr"
          },
          "parse": {
            "at": "0x0020",
            "cl": "0x0406",
            "ep": 1,
            "eval": "Item.val = Attr.val",
            "fn": "zcl:attr"
          },
          "default": 60
        },
        {
          "name": "config/on"
        },
        {
          "name": "config/reachable"
        },
        {
          "name": "state/dark",
          "refresh.interval": 360,
          "read": {
            "at": "0x2001",
            "cl": "0xfc11",
            "ep": 1,
            "fn": "zcl:attr"
          },
          "parse": {
            "at": "0x2001",
            "cl": "0xfc11",
            "ep": 1,
            "eval": "if (Attr.val === 0) { Item.val = true } else { Item.val = false }",
            "fn": "zcl:attr"
          },
          "default": false
        },
        {
          "name": "state/lastupdated"
        },
        {
          "name": "state/presence",
          "read": {
            "fn": "none"
          },
          "parse": {
            "at": "0x0000",
            "cl": "0x0406",
            "ep": 1,
            "eval": "Item.val = Attr.val",
            "fn": "zcl:attr"
          },
          "default": false
        }
      ]
    }
  ],
  "bindings": [
    {
      "bind": "unicast",
      "src.ep": 1,
      "cl": "0xFC11",
      "report": [
        {
          "at": "0x2001",
          "dt": "0x20",
          "min": 1,
          "max": 300,
          "change": "0x00000001"
        }
      ]
    },
    {
      "bind": "unicast",
      "src.ep": 1,
      "cl": "0x0406",
      "report": [
        {
          "at": "0x0000",
          "dt": "0x18",
          "min": 0,
          "max": 1,
          "change": "0x00000001"
        }
      ]
    }
  ]
}```
Smanar commented 3 days ago

So i need to correct 'config/duration', 'state/dark' and the 'bindings' parts somehow...

HA don't manage state/dark ? "config/duration" is not working using API ? For the bindong

      "cl": "0x0406",
      "report": [
        {
          "at": "0x0000",
          "dt": "0x18",
          "min": 1,
          "max": 300
        }
      ]
    },

Will be better.

I don't think you need more stuff for bind ?

febalci commented 3 days ago

HA don't manage state/dark ? "config/duration" is not working using API ?

Screenshot 2024-06-25 at 20 35 22

All i got in HA are these. There's no state/dark here. And also config/duration can't read or write to 0x0406/attr:0x0020.

The 47 secs shown in the image is changed by myself, but in phoscon 0x0020 is still keeps 5 secs value.

Smanar commented 3 days ago

All i got in HA are these. There's no state/dark here.

Strange from my memory HA have no problem with them, @Kane610 you have an idea ? a Synchronisation issue ?

The 47 secs shown in the image is changed by myself, but in phoscon 0x0020 is still keeps 5 secs value.

Your DDF seem good for me, device on battery are boring with that, need to awake them to be sure it work. You are saying "in phoscon", it mean in phoscon/help/API information/sensor or you mean "deconz" ?

If you try to change the value using deconz, it's updated in the API ?

And your DDF have the "draft" status, you have another one on the one you are using for tests ?

Kane610 commented 2 days ago

Dark is reported as an attribute on Presence binary sensor and lightlevel sensor right now. Its not its own sensor currently

febalci commented 1 day ago

@Smanar and @Kane610 Thanks for all help, SZNB-03P is working perfectly fine with all its features now including timeout delay setting (min 5 secs) from HA, and dark (true/false) attribute on occupancy; with the DDF below:

{
  "schema": "devcap1.schema.json",
  "manufacturername": "eWeLink",
  "modelid": "SNZB-03P",
  "vendor": "SONOFF",
  "product": "SNZB-03P",
  "sleeper": false,
  "status": "Bronze",
  "path": "/devices/snzb-03p.json",
  "subdevices": [
    {
      "type": "$TYPE_PRESENCE_SENSOR",
      "restapi": "/sensors",
      "uuid": [
        "$address.ext",
        "0x01",
        "0x0406"
      ],
      "fingerprint": {
        "profile": "0x0104",
        "device": "0x0107",
        "endpoint": "0x01",
        "in": [
          "0x0000",
          "0x0001",
          "0x0406",
          "0x0500",
          "0xFC11"
        ]
      },
      "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/battery",
          "parse": {
            "at": "0x0021",
            "cl": "0x0001",
            "ep": 1,
            "eval": "Item.val = Attr.val / 2;",
            "fn": "zcl:attr"
          },
          "default": 0
        },
        {
          "name": "config/delay",
          "refresh.interval": 3600,
          "read": {
            "at": "0x0020",
            "cl": "0x0406",
            "ep": 1,
            "fn": "zcl:attr"
          },
          "write": {
            "at": "0x0020",
            "cl": "0x0406",
            "dt": "0x21",
            "ep": 1,
            "eval": "Item.val",
            "fn": "zcl:attr"
          },
          "parse": {
            "at": "0x0020",
            "cl": "0x0406",
            "ep": 1,
            "eval": "Item.val = Attr.val",
            "fn": "zcl:attr"
          },
          "default": 60
        },
        {
          "name": "config/on"
        },
        {
          "name": "config/reachable"
        },
        {
          "name": "state/dark",
          "read": {
            "fn": "none"
          },
          "parse": {
            "at": "0x2001",
            "cl": "0xfc11",
            "ep": 1,
            "eval": "if (Attr.val === 0) { Item.val = true } else { Item.val = false }",
            "fn": "zcl:attr"
          },
          "default": false
        },
        {
          "name": "state/lastupdated"
        },
        {
          "name": "state/presence",
          "read": {
            "fn": "none"
          },
          "parse": {
            "at": "0x0000",
            "cl": "0x0406",
            "ep": 1,
            "eval": "Item.val = Attr.val",
            "fn": "zcl:attr"
          },
          "default": false
        }
      ]
    }
  ],
  "bindings": [
    {
      "bind": "unicast",
      "src.ep": 1,
      "cl": "0x0406",
      "report": [
        {
          "at": "0x0000",
          "dt": "0x18",
          "min": 1,
          "max": 300
        },
        {
          "at": "0x0020",
          "dt": "0x21",
          "min": 5,
          "max": 60
        }
      ]
    },
    {
      "bind": "unicast",
      "src.ep": 1,
      "cl": "0xfc11",
      "report": [
        {
          "at": "0x2001",
          "dt": "0x20",
          "min": 1,
          "max": 300,
          "change": "0x00000001"
        }
      ]
    }
  ]
}
Smanar commented 1 day ago

Lol, faster than me. There is no bind for battery, some device can work without, but IDK for this one.

Kane610 commented 1 day ago

Great!

febalci commented 4 hours ago

There is no bind for battery, some device can work without, but IDK for this one.

You are correct, this also needs the bind for battery. Here is the corrected DDF:

{
  "schema": "devcap1.schema.json",
  "manufacturername": "eWeLink",
  "modelid": "SNZB-03P",
  "vendor": "SONOFF",
  "product": "SNZB-03P",
  "sleeper": false,
  "status": "Bronze",
  "path": "/devices/snzb-03p.json",
  "subdevices": [
    {
      "type": "$TYPE_PRESENCE_SENSOR",
      "restapi": "/sensors",
      "uuid": [
        "$address.ext",
        "0x01",
        "0x0406"
      ],
      "fingerprint": {
        "profile": "0x0104",
        "device": "0x0107",
        "endpoint": "0x01",
        "in": [
          "0x0000",
          "0x0001",
          "0x0406",
          "0x0500",
          "0xFC11"
        ]
      },
      "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/battery",
          "awake": true,
          "refresh.interval": 7265,
          "read": {
            "at": "0x0021",
            "cl": "0x0001",
            "ep": 1,
            "fn": "zcl:attr"
          },
          "parse": {
            "at": "0x0021",
            "cl": "0x0001",
            "ep": 1,
            "eval": "Item.val = Attr.val / 2;",
            "fn": "zcl:attr"
          },
          "default": 0
        },
        {
          "name": "config/delay",
          "refresh.interval": 3600,
          "read": {
            "at": "0x0020",
            "cl": "0x0406",
            "ep": 1,
            "fn": "zcl:attr"
          },
          "write": {
            "at": "0x0020",
            "cl": "0x0406",
            "dt": "0x21",
            "ep": 1,
            "eval": "Item.val",
            "fn": "zcl:attr"
          },
          "parse": {
            "at": "0x0020",
            "cl": "0x0406",
            "ep": 1,
            "eval": "Item.val = Attr.val",
            "fn": "zcl:attr"
          },
          "default": 60
        },
        {
          "name": "config/on"
        },
        {
          "name": "config/reachable"
        },
        {
          "name": "state/dark",
          "read": {
            "fn": "none"
          },
          "parse": {
            "at": "0x2001",
            "cl": "0xfc11",
            "ep": 1,
            "eval": "if (Attr.val === 0) { Item.val = true } else { Item.val = false }",
            "fn": "zcl:attr"
          },
          "default": false
        },
        {
          "name": "state/lastupdated"
        },
        {
          "name": "state/presence",
          "read": {
            "fn": "none"
          },
          "parse": {
            "at": "0x0000",
            "cl": "0x0406",
            "ep": 1,
            "eval": "Item.val = Attr.val",
            "fn": "zcl:attr"
          },
          "default": false
        }
      ]
    }
  ],
  "bindings": [
    {
      "bind": "unicast",
      "src.ep": 1,
      "cl": "0x0406",
      "report": [
        {
          "at": "0x0000",
          "dt": "0x18",
          "min": 1,
          "max": 300
        },
        {
          "at": "0x0020",
          "dt": "0x21",
          "min": 5,
          "max": 60
        }
      ]
    },
    {
      "bind": "unicast",
      "src.ep": 1,
      "cl": "0xFC11",
      "report": [
        {
          "at": "0x2001",
          "dt": "0x20",
          "min": 1,
          "max": 300,
          "change": "0x00000001"
        }
      ]
    },
    {
      "bind": "unicast",
      "src.ep": 1,
      "cl": "0x0001",
      "report": [
        {
          "at": "0x0021",
          "dt": "0x20",
          "min": 0,
          "max": 200,
          "change": "0x00000002"
        }
      ]
    }
  ]
}
Smanar commented 3 hours ago

Thx, BTW do you want to make a PR to submit the DDF or want someone make it ?