JohanBendz / tech.sonoff

MIT License
3 stars 5 forks source link

SNZB-06P source code #15

Open wavegazer opened 5 months ago

wavegazer commented 5 months ago

Source code attached.

Note that it is based of the athombv/node-homey-zigbeedriver: https://github.com/athombv/node-homey-zigbeedriver

In the node_modules folder, the following file has been changed: \node_modules\homey-zigbeedriver\lib\system\capabilities\alarm_motion\occupancySensing.js

com.ricardo.sonoff.zip

JohanBendz commented 5 months ago

Thanks @wavegazer, I made a test version for you to try out when you find the time :)

wavegazer commented 5 months ago

Hi Johan,

Sorry for the late reply but the last two days were quite busy. I ran your test version in this repo and I get the following error attached. I'll look in to it during the weekend but at first glance it seems some zigbee libraries are missing.

2024-02-02T09_50_47_502Z-debug-0.log

image

Cheers, Ricardo

JohanBendz commented 5 months ago

Hi @wavegazer. No stress, I totally understand the lack of time :) Looks like you forgot to run "NPM Install" to have the Athom modules installed before executing Homey app run. Easy to miss 😎

wavegazer commented 4 months ago

Hi Johan,

Thanks! You were right. :) I ran a quick test and the initial pairing was almost successful. The sensor was added to homey but in an errored state, related to the IAS.

Logs here: log.txt

Let me know if you spot it immediately, otherwise I'll tshoot during the weekend. ;)

Cheers, Ricardo

JohanBendz commented 4 months ago

Documentation for development: Occupancy (binary) Indicates detected occupancy. Value in occupancy property. Not possible to read (/get) or write (/set) this value. If true occupancy is ON, if false OFF.

Occupancy timeout (numeric) Unoccupied to occupied delay. Value in occupancy_timeout property. Support read (/get) and write (/set). Min value is 15 and max value is 65535.

Occupancy sensitivity (enum) Sensitivity of human presence detection. Value in occupancy_sensitivity property. Support read (/get) and write (/set). Values are: low, medium and high.

Illumination (enum) Updated when occupancy is detected. Value in illumination property. Not possible to read (/get) or write (/set) this value. Values are: dim and bright.

msOccupancySensing Cluster / ultrasonicOToUDelay is the detection duration setting. Firmware 1.0.5 or higher can have min 15 seconds, older FW can have min 30 seconds.

msOccupancySensing Cluster / ultrasonicUToOThreshold is the sensitivity setting. 1 = low sensitivity with a detection distance of 2.5m. 2 = medium sensitivity with a detection distance of 3.5m. 3 = high sensitivity with a detection distance of 4m.

nides34 commented 4 months ago

To @JohanBendz , thanks for your work. This device looks like very good. I can't help, I don't understand anything with driver's creation. But I send you all my support and I'll donate for your job if you succeed to add this device to your app :)

razorback16 commented 4 months ago

I see the same 'UNSUP_CLUSTER_COMMAND' error as @wavegazer . How do we fix this?

simonwimell commented 4 months ago

Thanks for all great work @JohanBendz 🙏 I sent you a tiny bit of encouragement on PayPal and wonder if there’s any news on this device and if there’s anything else I can do to help?

JohanBendz commented 4 months ago

@wavegazer / @razorback16, new version in git. I made some changes to how the iasZone is handled and removed tamper capability (if the device have this i can add it later). Please remove and add the device again.

I am testing if the device works best using occupancy or iasZone reporting, the iasZone would be the better choice as it have the ability to report both start and end of a motion. Occupancy use a timeout to reset it

JohanBendz commented 4 months ago

Ping @wavegazer / @razorback16

nides34 commented 4 months ago

Hi,

Got a problem: device is recognized as contact sensor and not motion sensor. Problem with my device?

Thanks 🙂

wavegazer commented 4 months ago

Ping @wavegazer / @razorback16

Hi, @JohanBendz , sorry the late reply (traveling and then forgot about this, sorry for that).

I still get the same error. It seems related to the IAS zone. Maybe you can remove this and keep my original code without this cluster?

zigbee-clusters:cluster ep: 1, cl: iasZone (1280) received frame defaultResponse iasZone.defaultResponse { cmdId: 6, status: 'UNSUP_CLUSTER_COMMAND' } +142ms

Screenshot_20240224-174543

homey_log.txt

And again, thanks for your effort.

Cheers!

wavegazer commented 4 months ago

One small note: you may want to to increment the version inside the code (e.g. app.json) to v.0.0.31 to match git. When I initially installed the updated version I got confused when I saw the older v.0.0.30. ;) Thanks!

razorback16 commented 4 months ago

@JohanBendz I still see the same error as well. Sorry for the delay. This is the error message I am getting when I am trying to pair the zigbee device

zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) configure reporting [
  {
    direction: 'reported',
    attributeId: 0,
    attributeDataType: 24,
    minInterval: 0,
    maxInterval: 65535
  }
]  +0ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) send frame ZCLStandardHeader {
  frameControl: [],
  data: occupancySensing.configureReporting { reports: [ [Object] ] },
  cmdId: 6,
  trxSequenceNumber: 1
} +2ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) configure reporting [
  {
    direction: 'reported',
    attributeId: 2,
    attributeDataType: 25,
    minInterval: 0,
    maxInterval: 65535
  }
]  +3ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) send frame ZCLStandardHeader {
  frameControl: [],
  data: iasZone.configureReporting { reports: [ [Object] ] },
  cmdId: 6,
  trxSequenceNumber: 1
} +1ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) received frame defaultResponse occupancySensing.defaultResponse {
  cmdId: 6,
  status: 'UNSUP_CLUSTER_COMMAND'
} +96ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) configure reporting [
  {
    direction: 'reported',
    attributeId: 0,
    attributeDataType: 24,
    minInterval: 0,
    maxInterval: 65535
  }
]  +5ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) send frame ZCLStandardHeader {
  frameControl: [],
  data: occupancySensing.configureReporting { reports: [ [Object] ] },
  cmdId: 6,
  trxSequenceNumber: 2
} +0ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) received frame defaultResponse iasZone.defaultResponse { cmdId: 6, status: 'UNSUP_CLUSTER_COMMAND' } +102ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) configure reporting [
  {
    direction: 'reported',
    attributeId: 2,
    attributeDataType: 25,
    minInterval: 0,
    maxInterval: 65535
  }
]  +13ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) send frame ZCLStandardHeader {
  frameControl: [],
  data: iasZone.configureReporting { reports: [ [Object] ] },
  cmdId: 6,
  trxSequenceNumber: 2
} +0ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) received frame defaultResponse occupancySensing.defaultResponse {
  cmdId: 6,
  status: 'UNSUP_CLUSTER_COMMAND'
} +83ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) configure reporting [
  {
    direction: 'reported',
    attributeId: 0,
    attributeDataType: 24,
    minInterval: 0,
    maxInterval: 65535
  }
]  +9ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) send frame ZCLStandardHeader {
  frameControl: [],
  data: occupancySensing.configureReporting { reports: [ [Object] ] },
  cmdId: 6,
  trxSequenceNumber: 3
} +0ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) received frame defaultResponse iasZone.defaultResponse { cmdId: 6, status: 'UNSUP_CLUSTER_COMMAND' } +88ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) configure reporting [
  {
    direction: 'reported',
    attributeId: 2,
    attributeDataType: 25,
    minInterval: 0,
    maxInterval: 65535
  }
]  +9ms
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) send frame ZCLStandardHeader {
  frameControl: [],
  data: iasZone.configureReporting { reports: [ [Object] ] },
  cmdId: 6,
  trxSequenceNumber: 3
} +0ms
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) received frame defaultResponse occupancySensing.defaultResponse {
  cmdId: 6,
  status: 'UNSUP_CLUSTER_COMMAND'
} +96ms
2024-02-24T20:11:39.140Z [err] [ManagerDrivers] [Driver:SNZB-06P] [Device:245c9513-99f9-4e80-8858-94a406a8ff37] Error: configuring attribute reporting (endpoint: 1, cluster: occupancySensing) { occupancy: { minInterval: 0, maxInterval: 65535, minChange: 1 } } Error: UNSUP_CLUSTER_COMMAND
    at OccupancySensing.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:1107:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async OccupancySensing.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:527:27)
    at async Promise.all (index 0)
    at async SensorSNZB06P.onNodeInit (/app/drivers/SNZB-06P/device.js:14:13)
    at async /app/node_modules/homey-zigbeedriver/lib/ZigBeeDevice.js:957:11
2024-02-24T20:11:39.141Z [err] [ManagerDrivers] [Driver:SNZB-06P] [Device:245c9513-99f9-4e80-8858-94a406a8ff37] Error: 'onNodeInit()' failed, reason: Error: UNSUP_CLUSTER_COMMAND
    at OccupancySensing.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:1107:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async OccupancySensing.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:527:27)
    at async Promise.all (index 0)
    at async SensorSNZB06P.onNodeInit (/app/drivers/SNZB-06P/device.js:14:13)
    at async /app/node_modules/homey-zigbeedriver/lib/ZigBeeDevice.js:957:11
2024-02-24T20:11:39.142Z [err] [ManagerDrivers] [Driver:SNZB-06P] [Device:245c9513-99f9-4e80-8858-94a406a8ff37] Error: could not initialize node Error: UNSUP_CLUSTER_COMMAND
    at OccupancySensing.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:1107:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async OccupancySensing.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:527:27)
    at async Promise.all (index 0)
    at async SensorSNZB06P.onNodeInit (/app/drivers/SNZB-06P/device.js:14:13)
    at async /app/node_modules/homey-zigbeedriver/lib/ZigBeeDevice.js:957:11
  zigbee-clusters:cluster ep: 1, cl: iasZone (1280) received frame defaultResponse iasZone.defaultResponse { cmdId: 6, status: 'UNSUP_CLUSTER_COMMAND' } +116ms
2024-02-24T20:11:39.256Z [err] [ManagerDrivers] [Driver:SNZB-06P] [Device:245c9513-99f9-4e80-8858-94a406a8ff37] Error: configuring attribute reporting (endpoint: 1, cluster: iasZone) { zoneStatus: { minInterval: 0, maxInterval: 65535, minChange: 1 } } Error: UNSUP_CLUSTER_COMMAND
    at IASZoneCluster.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:1107:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async IASZoneCluster.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:527:27)
    at async Promise.all (index 1)
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) received frame reportAttributes occupancySensing.reportAttributes { attributes: <Buffer 00 00 18 01> } +1s
  zigbee-clusters:endpoint ep: 1, cl: undefined (64529), error while handling frame cluster_unavailable {
  meta: { dstEndpoint: 1 },
  frame: ZCLStandardHeader {
    frameControl: Bitmap [ directionToClient, disableDefaultResponse ],
    trxSequenceNumber: 1,
    cmdId: 10,
    data: <Buffer 01 20 20 01>
  }
} +0ms
t async IASZoneCluster.configureReporting (/app/node_modules/zigbee-clusters/lib/Cluster.js:527:27)
    at async Promise.all (index 1)
  zigbee-clusters:cluster ep: 1, cl: occupancySensing (1030) received frame reportAttributes occupancySensing.reportAttributes { attributes: <Buffer 00 00 18 01> } +1s
  zigbee-clusters:endpoint ep: 1, cl: undefined (64529), error while handling frame cluster_unavailable {
  meta: { dstEndpoint: 1 },
  frame: ZCLStandardHeader {
    frameControl: Bitmap [ directionToClient, disableDefaultResponse ],
    trxSequenceNumber: 1,
    cmdId: 10,
    data: <Buffer 01 20 20 01>
  }
} +0m
nides34 commented 3 months ago

Hi,

Got a problem: device is recognized as contact sensor and not motion sensor. Problem with my device?

Thanks 🙂

Hi,

I still have the problem. My SNZB-06 is recognized as contact sensor.

Why this device as alarm_contact capability in code?

When I'm in the detection zone, the alarm_contact is activated. When I leave zone, alarm_contact is off.

Thanks :)

JohanBendz commented 3 months ago

Thanks all, new version in Git. @nides34 @razorback16 @wavegazer

There are two ways / Zigbee clusters for the sensor to report motion/occupancy: IAS Zone and Occupancy. I have now configured the device to use Motion for the IAS Zone and Contact for the Occupancy.

IAS Zone report on both start and end of a motion/occupancy while Occupancy report on start and then a timer reset the capability. I personally like the IAS Zone way but I know many like to be able to set the reset timer manually, when we have a working driver I will add the ability to set this timer in the settings.

Please report what works / not. :)

jrossouw commented 3 months ago

Hi @JohanBendz - I used your repository to get this device working. Other than the error that the already reported 'UNSUP_CLUSTER_COMMAND' issue, there is an issue in the onOccupancyAttributeReport method. I updated it like this:

onOccupancyAttributeReport(occupancy) { this.log("Occupancy status:", occupancy.occupied); this.setCapabilityValue('alarm_contact', occupancy.occupied) .catch(err => this.error('Error: could not set alarm_motion capability value', err)); }

After this change the device started reporting the occupancy values.

After adding the device - the device was marked as unavailable - but if i click on it - rename it - then it becomes available and works correctly.

nides34 commented 2 months ago

Hi @JohanBendz

Thanks for that great work :)

I have 2 SNZB-06P and I'll test soon with your new driver. But have 1 question ; I use in my flow the When card: any alarm contact ON (to check all my doors and windows). But if this driver uses alarm_contact capability to check an occupancy status, I will send falses values to my flow?

JohanBendz commented 1 month ago

Should be working in the v.0.0.33 release.

JohanBendz commented 1 month ago

@wavegazer @razorback16 @simonwimell @nides34 @jrossouw Can one of you guys please verify that the new test version works with this device? I made it to use two capabilities, alarm_contact and alarm_motion, they trigger using diffenrent methods in the driver. If one works better I can remove the other.. or have both as they are now.

nides34 commented 1 month ago

@JohanBendz So sorry, I can't test it on my homey, because I can't test alarm_contact because on my flows, I have a card called by all alarm_contact to trigger alarm siren :(

But at this moment, the actual version works very well, I have 2 sensors in my garage (big garage), no false detection, and presence are well detected even when there is no motion.