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

Switchbot Lock Pro + Keypad no updates via Webhook #67

Open
astumpf opened this issue Jan 11, 2025 · 6 comments
Open

Switchbot Lock Pro + Keypad no updates via Webhook #67

astumpf opened this issue Jan 11, 2025 · 6 comments

Comments

@astumpf
Copy link

astumpf commented Jan 11, 2025

Hello,

I'm struggeling to get the addon running. Since I installed the Addon a few months ago, the Webhook update seems to have never worked. In the logs I'm getting

Logger: homeassistant.components.mqtt.sensor
Source: components/mqtt/sensor.py:296
integration: MQTT (documentation, issues)
First occurred: January 10, 2025 at 05:17:18 (3216 occurrences)
Last logged: 01:07:18

Invalid state message 'unknown' from 'switchbot/XXXXX/status'
Invalid state message 'unknown' from 'switchbot/YYYYY/status'

Short Summary:

  • Core 2025.1.2
  • Supervisor 2024.12.3
  • Operating System 14.1
  • Frontend 20250109.0
  • SwitchBot-Mqtt Current version: 1.0.31
    ** Webhook enabled, also for each device in the Web Config
    ** Ngrok enabled

Polling via API seems to work. But Webhook does not update any states. In my Ngrok account I can see an active tunnel and data is going through.

I appreciate any help :-)

@hsakoh
Copy link
Owner

hsakoh commented Jan 11, 2025

First, in my environment, I am able to receive webhooks and update statuses.

There are a few points I would like to confirm:

  • Could you let me know which SwitchBot devices you have?

  • Are you unable to receive webhooks from all of your SwitchBot devices?
    (Is it specific devices that cannot send webhooks, or is it all of them?)

  • Do any logs related to WebhookController appear in the add-on logs?
    (For example, logs like the following might appear.)

    09:06:55 info: SwitchBotMqttApp.Controllers.WebhookController[0] {"eventType":"changeReport","eventVersion":"1","context":{"CO2":1305,"battery":100,"deviceMac":"B0E9FEXXXXXX","deviceType":"MeterPro(CO2)","humidity":38,"scale":"CELSIUS","temperature":25.1,"timeOfSample":1736554014976}}
    
  • If you post a dummy payload to the Ngrok webhook endpoint, do logs appear?

    • Please try posting the following payload to https://{your-endpoint}.ngrok-free.app/webhook.
    {"eventType":"changeReport","eventVersion":"1","context":{"CO2":1305,"battery":100,"deviceMac":"B0E9FEXXXXXX","deviceType":"MeterPro(CO2)","humidity":38,"scale":"CELSIUS","temperature":25.1,"timeOfSample":1736554014976}}
    
    • If the following logs appear, there should be no issues with the webhook communication path.
    09:31:09 warn: SwitchBotMqttApp.Services.MqttCoreService[0] unknown deviceMac B0E9FEXXXXXX
    

@astumpf
Copy link
Author

astumpf commented Jan 11, 2025

* Could you let me know which SwitchBot devices you have?
* Are you unable to receive webhooks from all of your SwitchBot devices?
  (Is it specific devices that cannot send webhooks, or is it all of them?)
  • Lock Pro, Keypad Touch, Hub Mini Matter

grafik

grafik

The states are not reliably updating when the door is phyiscally opened/closed. Currently the door is CLOSED and LOCKED, which is also the Lock's state in the Android App.

* Do any logs related to `WebhookController` appear in the add-on logs?
  (For example, logs like the following might appear.)
  ```
  09:06:55 info: SwitchBotMqttApp.Controllers.WebhookController[0] {"eventType":"changeReport","eventVersion":"1","context":{"CO2":1305,"battery":100,"deviceMac":"B0E9FEXXXXXX","deviceType":"MeterPro(CO2)","humidity":38,"scale":"CELSIUS","temperature":25.1,"timeOfSample":1736554014976}}
  ```

Yes

00:38:14 info: SwitchBotMqttApp.Controllers.WebhookController[0] {"eventType":"changeReport","eventVersion":"1","context":{"battery":95,"deviceMac":"xxxxxxxxxxxx","deviceType":"WoLockPro","lockState":"LOCKED","timeOfSample":1736552294002}}
00:38:18 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send GET,devices/xxxxxxxxxxxx/status,(null)
00:38:18 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Send GET,devices/xxxxxxxxxxxx/status,(null)
00:38:18 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response GET,https://api.switch-bot.com/v1.1/devices/xxxxxxxxxxxx/status,{"statusCode":100,"body":{"deviceId":"xxxxxxxxxxxx","deviceType":"Keypad Touch","hubDeviceId":"xxxxxxxxxxxx"},"message":"success"}
00:38:18 trce: SwitchBotMqttApp.Logics.SwitchBotApiClient[0] Response GET,https://api.switch-bot.com/v1.1/devices/xxxxxxxxxxxx/status,{"statusCode":100,"body":{"version":"V1.9","battery":95,"lockState":"locking","doorState":"opened","calibrate":true,"deviceId":"xxxxxxxxxxxx","deviceType":"Smart Lock Pro","hubDeviceId":"xxxxxxxxxxxx"},"message":"success"}
00:38:20 info: SwitchBotMqttApp.Controllers.WebhookController[0] {"eventType":"changeReport","eventVersion":"1","context":{"battery":95,"deviceMac":"xxxxxxxxxxxx","deviceType":"WoLockPro","lockState":"LOCKED","timeOfSample":1736552300510}}
* If you post a dummy payload to the Ngrok webhook endpoint, do logs appear?

Yes that works

02:04:48 info: SwitchBotMqttApp.Controllers.WebhookController[0] {"eventType":"changeReport","eventVersion":"1","context":{"CO2":1305,"battery":100,"deviceMac":"B0E9FEXXXXXX","deviceType":"MeterPro(CO2)","humidity":38,"scale":"CELSIUS","temperature":25.1,"timeOfSample":1736554014976}}
02:04:48 warn: SwitchBotMqttApp.Services.MqttCoreService[0] unknown deviceMac B0E9FEXXXXXX

Ok, so I see two issues here:

  1. The webhook data does only include one state information: lockState. I would expect more data, but based on the Addon's WebUI config I see also that the doorState is apparently not part of the Webhook. Something I overlooked.
  2. The API call reports something different as I can see in the App. It still reports the door is opened while the App says it is closed. My smartphone has no direct bluetooth connection.

@astumpf
Copy link
Author

astumpf commented Jan 11, 2025

Hmm it seems that the Lock itself has an issue. It does not detect the magnet anymore and thus is not able to detect the door state. So sry for bother you :-). Thanks for your quick help!

@astumpf astumpf closed this as completed Jan 11, 2025
@hsakoh
Copy link
Owner

hsakoh commented Jan 11, 2025

Actually, as part of SwitchBot's internal operation, when Bluetooth is turned off, the smartphone app communicates in real-time with the Lock via Bluetooth through the Hub over the internet.
(This is why the data accessible via the API or received through webhooks often differs from what can be seen in the app.)

The issue this time is that doorState is neither included in the webhook nor a triggering condition.
The Contact Sensor, on the other hand, does send notifications even for just open/close events...

@astumpf
Copy link
Author

astumpf commented Jan 12, 2025

Sry to bother again. So I got sorted out the issue with the doorState. I re-calibrated the lock and now it seems to work okeyish.

Anyway, I still see a lot Invalid state message 'unknown' from ... warnings in the Homeassistant Logs.

grafik

@astumpf astumpf reopened this Jan 12, 2025
@hsakoh
Copy link
Owner

hsakoh commented Jan 28, 2025

@astumpf
Sorry for overlooking the re-opened issue. What problems are still ongoing at this point?

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

2 participants