-
Notifications
You must be signed in to change notification settings - Fork 9
HowToInstall
-
Preparation
This add-on sends SwitchBot device information to the Home Assistant's MQTT integration, enabling operation.
-
Install MQTT Broker
First, Install the MQTT broker.
The recommended setup method is to use the Mosquitto MQTT broker add-on.
-
Configure MQTT Integration
Follow the instructions on this page to set up which broker the MQTT integration exchanges information with.
-
-
Adding add-on Repository and Installing add-on
-
Add the public repository of add-on image from the button below.
-
If the above button does not work, follow the steps below to add the repository.
- Navigate to add-on store in the Home Assistant UI (Supervisor in the left menu, then Add-on Store on the top tab)
- Select the three vertical dots in the upper right-hand corner and select repositories
- In the Manage add-on repositories screen enter the URL for
https://github.com/hsakoh/ha-addonand click add - After adding the repository scroll to the bottom of the list of addons or use search to find the addon
-
-
Select add-on and install it.
-
-
Add-on Configuration
-
MQTT Broker
-
If you simply introduced the Mosquitto MQTT broker add-on, it works with the default values.
This is because it can receive the information necessary for connection from the Supervisor API of Home Assistant OS.
Mqtt: AutoConfig: true Host: "" Port: 1883 Id: "" Pw: "" Tls: false
-
If you have introduced the Mosquitto MQTT broker add-on with a changed configuration, or if you are using another broker, enter the values.
Mqtt: AutoConfig: false Host: 192.168.0.100 Port: 1883 Id: mqtt-user Pw: mqtt-user-password Tls: false
Setting Key Default Value Description Mqtt:AutoConfig trueFor users of the default Home Assistant Mosquitto integration, connection details can be detected via the Home Assistant Supervisor API. Therefore, this value should be set to true Mqtt:Host - MQTT Broker
Specify the hostnameMqtt:Port 1883Specify the port number. Mqtt:Id - If authentication is required, specify the ID Mqtt:Pw - If authentication is required, specify the PW. Mqtt:Tls falseIf TLS connection is required, set to true. -
-
SwitchBot API Key & Secret
-
Obtain and configure the token and secret according to the SwitchBotApi documentation.
SwitchBot: ApiBaseUrl: https://api.switch-bot.com/v1.1/ ApiKey: >- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ApiSecret: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
Setting Key Default Value Description SwitchBot:ApiBaseUrl https://api.switch-bot.com/v1.1/API Base URL SwitchBot:ApiKey - Obtain and configure the open token according to the SwitchBotApi documentation.The token is 96 characters long. SwitchBot:ApiSecret - Obtain and configure the secret key according to the SwitchBotApi documentation.The secret is 32 characters long. -
-
Webhook
-
Disabled
WebhookService: TunnelMode: Disabled
-
Via Ngrok (account required)
- Sign up for an ngrok account.
- Copy your ngrok authtoken from your ngrok dashboard.
WebhookService: TunnelMode: Ngrok NgrokAuthToken: _________________ngrokauthtoken__________________
-
Via TryCloudflare / Quick Tunnel (no account needed)
WebhookService: TunnelMode: TryCloudflare
-
Via Cloudflare Zero Trust tunnel (fixed URL, account required)
- Create a tunnel in the Cloudflare Zero Trust dashboard and obtain the tunnel token.
- In the dashboard, go to
Networks>Connectors>Create a tunnel. - Select
Cloudflared. - Enter any tunnel name you like, then record the
eyJ...token included in the shown startup command. - Configure the public hostname by choosing the subdomain and domain you want to use.
- In the service settings, set
TypetoHTTPandURLto127.0.0.1:8098, then complete the setup.
WebhookService: TunnelMode: CloudflareZeroTrust CloudflareTunnelToken: _________________cloudflaretunneltoken__________________ HostUrl: https://your-fixed-domain.example.com
-
Direct (Home Assistant OS directly receives)
WebhookService: TunnelMode: HostUrl HostUrl: http://<internet-reachable-hostname-of-homeassistant>:8098
Setting Key Default Value Description WebhookService:TunnelMode TryCloudflareSelect webhook reception mode. One of: Disabled,HostUrl,Ngrok,TryCloudflare,CloudflareZeroTrust.WebhookService:NgrokAuthToken - Required when TunnelMode is Ngrok. Set the Ngrok authentication token.WebhookService:HostUrl - Required when TunnelMode is HostUrl. Also required forCloudflareZeroTrust(the fixed public URL configured in the Cloudflare dashboard).WebhookService:CloudflareTunnelToken - Required when TunnelMode is CloudflareZeroTrust. Obtain from the Cloudflare Zero Trust dashboard. -
-
Others
- AutoStartServices
- After rebooting the Home Assistant OS or upgrading add-on version, the service will start automatically.
- We recommend enabling this after configuring the device and confirming that it works without any problems.
- LogLevel
- If trouble occurs, set the log level to Trace, check the log, and create an Issue on Github.
- EnforceDeviceTypes
- There are rare cases where devices, such as new ones, do not include the device type in their API responses. In such cases, you can specify a device type to be forcibly recognized based on the device ID.
EnforceDeviceTypes: - DeviceId: <K10+ DeviceId> DeviceType: Robot Vacuum Cleaner S1 - DeviceId: <Hub Mini2 DeviceId> DeviceType: Hub Mini MessageRetain: Entity: true State: false ImageFetch: MaxRetries: 25 RetryIntervalMs: 1000 DeviceStatePersistence: false AutoStartServices: true ExitOnServiceFailure: false LogLevel: Trace
Setting Key Default Value Description AutoStartServices falseIf various internal services should start automatically when add-on is started, set to true. ExitOnServiceFailure falseWhen enabled, the application exits if any internal service (MQTT, Polling, or Webhook) enters a failed state. This allows the Home Assistant Supervisor's watchdog to automatically restart the add-on and recover from transient failures. DeviceStatePersistence falseWhen enabled, the last device state is persisted and continuously sent to the state topic.
This helps reduce the duration during which MQTT sensors are in an "unknown" state after restarting Home Assistant.
Specifically, it reduces the occurrence of warning logs in the MQTT integration in scenarios such as when a webhook is not triggered after a restart. (This also applies when webhooks are received without polling.)
The downside is that persisting the state involves writing to the file system each time a state notification is made.LogLevel TraceSet the log level. Specify one of the following values:
Trace, Debug, Information, Warning, Error, Critical, NoneMessageRetain:Entity trueTo enable retention for MQTT configuration messages, set to true.
See Using Retained Config Messages for more details.MessageRetain:State falseTo enable retention for MQTT state messages, set to true.
See Using Retained State Messages for more details.ImageFetch:MaxRetries 25Maximum number of retry attempts when fetching a device image (e.g., camera snapshot) from a presigned URL returns a 404 response. ImageFetch:RetryIntervalMs 1000Interval in milliseconds between image fetch retry attempts. EnforceDeviceTypes[]:DeviceId - There are rare cases where devices, such as new ones, do not include the device type in their responses. In such cases, you can specify a device type to be forcibly recognized based on the device ID. EnforceDeviceTypes[]:DeviceType - Use the value found in the "ApiDeviceTypeString" field of this JSON files. - AutoStartServices
-
-
Start the add-on, open the Ingress page, and continue to the device settings.
This add-on supports the following five modes for webhook reception, configurable via WebhookService:TunnelMode.
Webhook reception is turned off. Only polling will be used for device state updates.
Configure your environment so that add-on's port 8098 is reachable from the internet. Set HostUrl to the publicly accessible base URL (excluding /webhook).
Add-on listens at http://<your home assistant private ip address>:8098/webhook and registers that URL with SwitchBot Cloud on startup.
When configured, add-on internally downloads and installs Ngrok, establishes a session via outbound connections, and enables webhook reception without opening an inbound port.
Before using Ngrok, read its terms of use, sign up, obtain an authentication token, and configure NgrokAuthToken.
Uses Cloudflare TryCloudflare (Quick Tunnel) — no Cloudflare account or pre-configuration is needed. A random temporary https://xxxxx.trycloudflare.com URL is issued automatically at each startup.
Before using it, review Cloudflare's terms, privacy policy, and related legal notice.
No inbound port needs to be opened. The URL changes every time the add-on restarts.
Powered by CloudflaredKit.
Uses a permanent Cloudflare Zero Trust tunnel with a fixed URL configured in the Cloudflare dashboard.
- In the Cloudflare Zero Trust dashboard, go to
Networks>Connectorsand selectCreate a tunnel. - Select
Cloudflared. - Enter any tunnel name you like, then copy the
eyJ...token included in the startup command. - Configure the public hostname by choosing the subdomain and domain you want to use.
- In the service settings, set
TypetoHTTPandURLto127.0.0.1:8098, then complete the setup. - Set
CloudflareTunnelTokento the obtained token. - Set
HostUrlto the fixed public URL you configured in the Cloudflare dashboard (used to register with SwitchBot Cloud).
No inbound port needs to be opened, and the URL is stable across restarts.
Powered by CloudflaredKit.
Add-on is created as a .NET 10 Blazor Web App.
As long as you have an environment where .NET 10's Blazor Web App operates, you can basically run it anywhere.
-
Container image
Add-on images are published on GitHub Container Registry and DockerHub.
-
GitHub Container Registry
-
DockerHub
-
-
See _docker-compose/docker-compose.yaml for instructions on running the image. Key points:
- Expose port
8099for WebUI. - Expose port
8098if you need to receive webhooks. - Mount the
/datavolume. - Configure add-on using options_Example.json as a reference, rename it to
options.json, and place it directly under the mounted/data.
- Expose port
This procedure assumes a Windows environment with .NET 10 SDK installed. While it is possible to build on Linux, Adjust the scripts accordingly.
-
Execute ./_compile_self/dotnet_publish.ps1 at the root of the repository.
-
Build the Docker image using the following command.
docker build ` "./_compile_self" ` --build-arg BUILD_FROM="ghcr.io/home-assistant/amd64-base:latest" ` --build-arg BUILD_ARCH="amd64" ` --progress=plain ` --label org.opencontainers.image.source=https://github.com/hsakoh/switchbot-mqtt
- It has been confirmed to work not only on
amd64but also onaarch64andarmv7.
- It has been confirmed to work not only on
- Open the solution file in Visual Studio and execute the application.
- Configure the app setting to appsettings.Development_Example.json, and then rename it to
appsettings.Development.json.
This procedure assumes a Windows environment with .NET 10 SDK installed. While it is possible to build on Linux, Adjust the scripts accordingly.
- Execute ./_compile_self/dotnet_publish.ps1 at the root of the repository.
- Place the contents of the _compile_self folder into
HA-OS /addons/switchbot-mqtt. - Check for updates on the Home Assistant add-on page and install add-on.
- Place the contents of both the src folder and _build_on_haos folder into
HA-OS /addons/switchbot-mqtt. - If the HA-OS machine is resource-limited, this method might lead to extended downtime while building (installing) processes occur. Not recommended.
- Check for updates on the Home Assistant add-on page and install add-on.