OpenWonderLabs / SwitchBotAPI

SwitchBot Open API Documents
900 stars 74 forks source link

The new webhook documentation for the contact sensor is incorrect #94

Open AdyRock opened 2 years ago

AdyRock commented 2 years ago

Describe The Bug: The new documentation for the webhook call-back for the contact sensor is wrong.

To Reproduce: Read the document and look at the webhook response.

Expected behavior: The detection state shows the contact status NOT the motion status. But, It would be very nice to ALSO have the motion status available.

Screenshots:

detectionState | String | the motion state of the device, "DETECTED" stands for motion is detected; "NOT_DETECTED" stands for motion has not been detected for some time -- | -- | --

Device Model:

SwitchBotAPI

Detecting the contact state.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AdyRock commented 2 years ago

Will the document be corrected?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AdyRock commented 2 years ago

Any news if this will be corrected?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AdyRock commented 2 years ago

Any news if this will be corrected?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AdyRock commented 2 years ago

Will this be updated?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AdyRock commented 2 years ago

Any updates?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AdyRock commented 2 years ago

Any updates?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 2 years ago

This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.

JGKarlin commented 2 years ago

I would like to see this bug fixed as well. There is currently no way to do a webhook with the contact sensor for the detection of motion. The detectionState shows the contact status NOT the motion status, and should probably be labelled differently.

AdyRock commented 2 years ago

I got annoyed trying to keep this open, so probably nothing will be done.

LittleJ commented 2 years ago

I agree. The documentation is not clear and the motion detection is missing. It would be great if this feature was added and if answers could be given…

LittleJ commented 2 years ago

When we query device info we get:

{
    "statusCode": 100,
    "body": {
        "deviceId": "",
        "deviceType": "Contact Sensor",
        "hubDeviceId": "",
        "moveDetected": false,
        "brightness": "bright",
        "openState": "close"
    },
    "message": "success"
}

detectionState matches none of those attributes. Could we reopen this issue ?

AdyRock commented 2 years ago

I don't think there is anyone from Switchbot that looks at the issues, so I doubt it will be reopened or fixed.

LittleJ commented 2 years ago

I think you are right, that's a shame... But thank YOU for answering. I was feeling alone here :-D

LittleJ commented 2 years ago

FYI: I emailed the support to say that customers were not getting any answer on Github, here was the answer:

Hi there,

Thank you for reaching out.
We apologize for the trouble caused.
We will forward your need to the related department, and they will handle it accordingly.

Thank you for your patience.

If you have any other questions, please let us know, and we'll try to accommodate your request as soon as possible.
Have a nice day!

Best Regards!
SwitchBot Support -Ellen
Customer Service Agent
SwitchBot Customer Happiness
chenliuyun commented 2 years ago

I don't think there is anyone from Switchbot that looks at the issues, so I doubt it will be reopened or fixed.

Hi,AdyRock,sorry for our answer,I will check and fix it in next few days. Thank you for your feedback

chenliuyun commented 2 years ago

When we query device info we get:


{
    "statusCode": 100,
    "body": {
        "deviceId": "",
        "deviceType": "Contact Sensor",
        "hubDeviceId": "",
        "moveDetected": false,
        "brightness": "bright",
        "openState": "close"
    },
    "message": "success"
}
detectionState matches none of those attributes. Could we reopen this issue ?

Hi, could you check if the cloudservice is enabled in the device setting page?We will try to reproduce and fixed this bug,thanks

LittleJ commented 2 years ago

Hello @chenliuyun. All is enabled. What we need is this: https://github.com/OpenWonderLabs/SwitchBotAPI/issues/125

chenliuyun commented 2 years ago

Hello @chenliuyun. All is enabled. What we need is this: #125

Hi, I have update code already, please check it ,

chenliuyun commented 2 years ago

I don't think there is anyone from Switchbot that looks at the issues, so I doubt it will be reopened or fixed.

Hi, I have fixed the bug, please check it.

AdyRock commented 2 years ago

Hi @chenliuyun, thank you for participating in here, it is much appreciated.

I am however confused! What have you fixed?

LittleJ commented 2 years ago

@chenliuyun Almost good ! 2 issues:

1/ Webhook must be triggered when "detectionState" AND "openState" change. For now it does NOT work if move is detected, only when it is open. There is no POST from webhook. Please verify detectionState and openState.

Contact sensor OPENED -> Webhook trigger (changeReport) -> openState: "open"
Motion DECTECTED by contact sensor -> Webhook trigger (changeReport) -> detectionState: "DETECTED"

2/ README not up to date. Here is my pull request: https://github.com/OpenWonderLabs/SwitchBotAPI/pull/126

AdyRock commented 2 years ago

I can confirm the detectionState and openState now work as described. Thank you for that update.

Will the detectionState be updated independently of the contact soon, so the benefit of the motion sensor can be used, especially the NOT_DETECTED state?

Also would it be possible to include the left open and button press as separate webbook messages?

My goal is to stop polling for all the changes and just rely on the webhook, so that will reduce the load on your server and on my device.

LittleJ commented 2 years ago

@AdyRock My changes have been pulled to the main repo. Documentation is now up to date. But the webhook is not triggered when movement is detected, and I suspect that when you open the contact sensor it still relies on the "detectionState" attribute.

I requested access to the source code here: https://github.com/OpenWonderLabs/SwitchBotAPI/issues/127 I am very interested in seeing what is happening in there. Users could certainly help accelerating the development/improvement of (new) features.

AdyRock commented 2 years ago

@LittleJ , Correct, the webhook is not triggered just by movement, it has to have the contact state change to trigger it. Hence, why I asked if it will be changed soon so the movement alone can trigger it ;-) But at least now the detectionState is based on the motion sensor and the new doorStatus shows if the door is open or closed, so a big improvment.

chenliuyun commented 2 years ago

@AdyRock OK, I understand your need(open and button press separate event), I will support this feature. But this will take some time. And I have tested the movement webhook event, it is ok , I need to reproduct this bug.

AdyRock commented 2 years ago

I understand your need(open and button press separate event),

@chenliuyun just to confirm, it is the "left open" event, and thank you for your input here, I look forward to seeing these very useful improvements at some point.

And I have tested the movement webhook event, it is ok , I need to reproduct this bug.

I get the movement report, but only when the contact opens or closes, which seems to be working OK. So, if I walk up to the door from inside (where the detector is mounted) and open it, the event shows door open and movement detected. If I open the door from the outside then I get door open and movement not detected.

It would be great if the movement report could also come in when the door contact doesn't change, so it can be used as a simple motion detector as well. I don't mind if this is a separate event or the normal event with the door status reported as well.

LittleJ commented 2 years ago

Any news @chenliuyun ? :-)

LittleJ commented 2 years ago

@chenliuyun Are you still here ? :-D

chenliuyun commented 2 years ago

@chenliuyun Are you still here ? :-D

Hi, sorry for my late reply,We were working on new API migration. Next we'll update this and some other webhook issuss(eg. curtain and ceiling light), thanks for your support.

JGKarlin commented 2 years ago

This is still not entirely fixed as noted above by others. The webhook's "detectionState" should indicate motion detection from the motion sensor and not the openState of the contact sensor.