You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-5Lines changed: 70 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,21 +8,86 @@ Designed for ease of deployment, this solution can be run natively or as a Docke
8
8
9
9
By translating commands and status updates between SwitchBot's proprietary API and standard MQTT messages, this solution enables you to control and monitor your SwitchBot devices directly from your MQTT-enabled smart home platform. This eliminates the need for separate apps or complex workarounds, providing a unified and efficient control experience.
10
10
11
+
Tested on Smart Lock Pro device
12
+
11
13
***Please, use version 0.1 if you would like to control your smart lock pro in a simple way***
12
14
15
+
***Please, use version 0.2 if you would like to operate in a generic way***
16
+
13
17
## Usage
14
18
15
-
- Copy *.env-template* in *.env* and populate config variables according to your setup
19
+
- Copy *.env-template* in *.env* and populate config variables according to your setup (see .env.example for help)
20
+
- Make the appropriate changes to the logging.json file for management of application log
16
21
- Follow this guide to obtain your authentication secrets: https://github.com/OpenWonderLabs/SwitchBotAPI?tab=readme-ov-file#getting-started
17
22
- Run switchbot_api2mqtt.py using your python environment OR run with docker compose
18
-
- Send GET and POST call to Switchbot API to *MQTT_TOPIC_COMMAND* topic using an MQTT publisher
19
-
- Get responses subscribing to *MQTT_TOPIC_RESPONSE* topic
20
-
- Actually the *MQTT_TOPIC_STATUS* topic is not used
23
+
- Send commands to *MQTT_SMARTLOCK_BASE_TOPIC/[deviceid]/cmnd* topic to interact with smartlock devices. Payload is a plain string with command name. Responses will be published on *MQTT_SMARTLOCK_BASE_TOPIC/[deviceid]/response* topic
24
+
- Send generic GET and POST call to Switchbot API to *MQTT_GENERIC_BASE_TOPIC* topic using an MQTT publisher. Responses will be published on *MQTT_GENERIC_BASE_TOPIC/response* topic
25
+
- Webhook events will be published on *MQTT_SMARTLOCK_BASE_TOPIC/[deviceid]/event* topic
26
+
- It is possible to enable a polling thread to obtain state information periodically (this is mandatory to periodically update battery information not managed by webhooks)
-*MQTT_SMARTLOCK_BASE_TOPIC*=**base topic for smart lock pro interaction**
40
+
-*MQTT_GENERIC_BASE_TOPIC*=**base topic for generic api interaction**
41
+
-*SWITCHBOT_TOKEN*=**switchbot authentication token** see https://github.com/OpenWonderLabs/SwitchBotAPI?-tab=readme-ov-file#getting-started
42
+
-*SWITCHBOT_SECRET*=**switchbot authentication secret** see https://github.com/OpenWonderLabs/SwitchBotAPI?-tab=readme-ov-file#getting-started
43
+
-*API_BASEURL*=**switchbot api base url**
44
+
-*HTTP_PORT*=**http port listening for webhook events**
45
+
-*SWITCHBOT_VALID_DEVICE_TYPES*=**array of valid device types managed by bridge** see https://github.com/-OpenWonderLabs/SwitchBotAPI?tab=readme-ov-file
46
+
-*SWITCHBOT_VALID_DEVICE_ID*=**array of valid device id managed by bridge**
47
+
-*SWITCHBOT_SMARTLOCK_VALID_COMMAND*=**array of valid smartlock commands managed by bridge**
48
+
-*SWITCHBOT_POLLING_INTERVAL_SEC*=**polling interval in seconds. 0 means no polling**
49
+
50
+
### MQTT Topics
51
+
52
+
-*MQTT_SMARTLOCK_BASE_TOPIC/[deviceid]/cmnd*=**to send command to smart lock pro device**
53
+
-*MQTT_SMARTLOCK_BASE_TOPIC/[deviceid]/response*=**to receive command response from smart lock pro device**
54
+
-*MQTT_SMARTLOCK_BASE_TOPIC/[deviceid]/event*=**to receive webhook events from smart lock pro device**
55
+
-*MQTT_GENERIC_BASE_TOPIC/cmnd*=**to send generic get/post call to switchbot api**
56
+
-*MQTT_GENERIC_BASE_TOPIC/response*=**to receive response from switchbot api generic get/post call**
57
+
58
+
### WEBHOOK configuration
59
+
60
+
A simple video about webhook: https://youtu.be/FxlmHL5eWR8
61
+
62
+
To enable webhook integration you must configure webhook using API. See https://github.com/OpenWonderLabs/SwitchBotAPI?tab=readme-ov-file#webhook
63
+
64
+
So that webhook can work you need to have a public url to receive events.
65
+
66
+
This can be directly managed by this bridge or by a frontend http server which through Reverse Proxy forwards requests to this bridge.
67
+
68
+
It is important to know and manage security aspects before exposing services on the internet.
69
+
70
+
As an example, this is a valid setup:
71
+
72
+

73
+
74
+
-*Reception of the Webhook (Cloud Server)*: Switchbot webhook calls are sent to the public url of your cloud server (for example, http://www.example.com/switchbot_webhook). Being the server publicly accessible, it is able to receive these requests from Switchbot.
75
+
-*SSH tunnel*: the cloud server is connected to your local Raspberry Pi via an SSH tunnel. This tunnel creates a safe and persistent connection between the external server and your home network, allowing the cloud server to forward the traffic to the Raspberry Pi.
76
+
-*Forwarding of the request (Raspberry PI)*: once the webhook arrives at the Cloud server, this forwards it through the SSH tunnel to the Raspberry Pi. The Raspberry Pi, which acts as "bridge" for the webhooks, receives the request and can therefore process it.
77
+
-*Local processing*: the bridge running on the Raspberry PI performs the desired actions based on the content of the Webhook request, such as checking the status of switchbot devices or activating specific automations within your home network.
78
+
79
+
This setup allows you to receive the Switchbot Webhooks while keeping your Raspberry Pi and your home network protected behind a firewall, exposing only an intermediate server.
80
+
81
+
## *Version 1.0 beta*
82
+
- Added webhooks support using an internal http server (**flask**)
83
+
- Added full support for **Smart Lock Pro** devices
84
+
- Added polling thread for status information
85
+
- Removed *LOG_FILE*, *MQTT_TOPIC_COMMAND*, *MQTT_TOPIC_STATUS* and *MQTT_TOPIC_RESPONSE* configuration properties
0 commit comments