Introducing a New Add-on Feature using the SwitchBot API for MQTT Integration

Hey there!

I’m excited to share that we’ve developed and released a brand-new add-on using the SwitchBot API specifically tailored for MQTT integration.

One of the standout features is its comprehensive support for virtual infrared remote devices. Plus, it’s capable of receiving and processing Webhooks, which is quite a game-changer.

What’s more, the core of this add-on is built using C# .NET 6, and you’ll be amazed to know that the user interface is powered by Blazor Server, bringing a unique touch to the Ingress screen.

I understand that some folks might have security concerns, but we’ve taken a novel approach by incorporating Ngrok internally to enable Webhook reception without the need to open ports externally. It’s something you probably haven’t seen before.

Lastly, since it’s running on the .NET , it does have a slightly higher memory consumption (around 300MB on the amd64 architecture).

I invite you to check out the repository and would absolutely love to hear your feedback. Pull requests are more than welcome too!

10 Likes

Thank you, this works like a charm!!

Looks like a great add-on. Just getting started with it and when I try to pull in my devices, the list remains blank. The logs show a success/100 message back, and I can see all of my devices in the array, but then it appears to hit an error:

10:11:00 fail: SwitchBotMqttApp.Logics.DeviceConfigurationManager[0] LoadDevicesAsync error. System.InvalidOperationException: Sequence contains no matching element    at System.Linq.ThrowHelper.ThrowNoMatchException()    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)    at SwitchBotMqttApp.Logics.DeviceConfigurationManager.<>c__DisplayClass9_0.<LoadDevicesAsync>b__0(Devicelist d) in C:\github\hsakoh\switchbot-mqtt\src\SwitchBotMqttApp\Logics\DeviceConfigurationManager.cs:line 86    at System.Linq.Enumerable.SelectArrayIterator`2.ToList()    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)    at SwitchBotMqttApp.Logics.DeviceConfigurationManager.LoadDevicesAsync(DevicesConfig currentData, CancellationToken cancellationToken)

Any assistance would be appreciated. Thanks.

I am so happy to have found this post.
It’s been weeks if not months that I am trying to implement my K10+ vaccuum in HA.
As suggested by hskoh, just had to configure in the addon:

EnforceDeviceTypes:

  • DeviceId: <K10+ DeviceId>
    DeviceType: Robot Vacuum Cleaner S1

hsakoh, you are the one.
Hopefully, you’ll integrate the K10+ (maybe if it is fully referenced in the API v1.1)

This add-on really need to be advertised.

Just trying this out - after a bit of messing about I seem to have the K10+ added, but I’m not seeing it in MQTT

Any ideas why?

EDIT: Somehow got it to work by messing about. Not quite sure how, but awesome!
Fingers crossed some new functionality hits down the line

Has anyone successfully connected the keypad touch?
I can see the device but all sensors are displayed with the status unknown
keypad

UPDATE: Has anyone successfully connected the keypad touch?

Switchbo S10 integrated in HA easily thanks to this add on. Thanks a lot for that ! Works like a charm. Just a few issues with some of the functions of the robot, maybe due to the API, but the most important is working fine. In case you need feedback to work on the S10 piece and test though, I’m happy to help !

Thanks again !

Looks very useful. Thank you.

Let’s hope Switchbot get around to adding the map name and room name to be cleaned to the API (for the S10) at some stage.

Hi everyone,

To compensate for a missing feature in the SwitchBot Keypad Pro, I want to create an automation that generates a one-time password for the person who will be cleaning my house. I managed to do this using the web interface of this add-on but I can’t figure out the MQTT payloads to use in a n automation. Can someone help me?

Unfortunately not, I have the same problem as shown in the screenshot from jimmy.edison. Would love to get this working. If I can help with any testing / validation, happy to support.

Through MQTT, I see the your same device info, but when I try to set the disposable password using the interface provided by the integration, I can set it.


For me, it’s not clear how to replicate the same functionality in an automation

I haven’t checked this forum for a while.

Regarding the sensor values for KeyPad Touch and KeyPad:

In short, the values for eventName, commandId, and result will only be populated when Webhook reception is enabled and you receive a Webhook for creating or deleting a passcode.

Please refer to the following table:

SwitchBot devices have values that can be obtained through the GetDeviceStatusAPI and those that can be obtained via Webhook.

For instance, for the Curtain, slidePosition can be obtained from both sources. The KeyPad is somewhat unique in that meaningful values cannot be retrieved through the GetDeviceStatusAPI.

If you do not plan to receive Webhooks, it is advisable to disable the relevant fields in the device configuration page.

In the image below, the clock icon represents values that can be obtained through the GetDeviceStatusAPI, while the cloud icon represents values that can be obtained through Webhook.
image

(If possible, please write issue in a GitHub so that I can notice it promptly!)

One inconvenient aspect of the KeyPad’s CreateKey command is that startTime and endTime can only be entered as Unix Timestamps (numbers).

This is due to the absence of input_datetime.mqtt in MQTT Auto Discovery. If you find this inconvenient, please vote for it here:

With the help of @ [hsakoh]hep, I found a solution that works for me.

This is the YAML file related to the automation that I created.

alias: one time password
description: ""
trigger:
  - platform: time_pattern
    hours: "0"
    minutes: "0"
    seconds: "1"
condition: []
action:
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      payload: >-
        { "CommandType": "command", "Command": "createKey", "ParamName": "name",
        "ParamValue": "Pluto" }
      topic: switchbot/XXXXXXXXXXXX/cmd
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: switchbot/XXXXXXXXXXXX/cmd
      payload: >-
        { "CommandType": "command", "Command": "createKey", "ParamName": 
        "type", "ParamValue": "a one-time passcode." }
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: switchbot/XXXXXXXXXXXX/cmd
      payload: >-
        { "CommandType": "command", "Command": "createKey", "ParamName":
        "password", "ParamValue":"123456789" }
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: switchbot/XXXXXXXXXXXX/cmd
      payload_template: >-
        { "CommandType": "command", "Command": "createKey", "ParamName":
        "startTime", "ParamValue": "{% set current_date =
        now().strftime('%Y-%m-%d') %}{% set specific_time = current_date + '
        08:30:00' %}{% set timestamp = as_timestamp(specific_time) %}{{
        timestamp | int }}"}
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: switchbot/XXXXXXXXXXXX/cmd
      payload_template: >-
        { "CommandType": "command", "Command": "createKey", "ParamName":
        "endTime", "ParamValue": "{% set current_date =
        now().strftime('%Y-%m-%d') %}{% set specific_time = current_date + '
        14:30:00' %}{% set timestamp = as_timestamp(specific_time) %}{{
        timestamp | int }}"}
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: switchbot/XXXXXXXXXXXX/cmd
      payload: >-
        { "CommandType": "command", "Command": "createKey", "ParamName": "btn",
        "ParamValue": "action" }
mode: single

I just purchased a SwitchBot K10+ Vacuum and this is just what I needed to add it to HomeAssistant. It works great - and thanks!

need help or the outdoor 2k Camera or suggestion to access the motion detection only in the 2k cameras

At this time, the Outdoor Spotlight Cam 2K does not return meaningful responses via the GetStatus API, and webhooks are not triggered even when an event occurs, making it difficult to integrate with Home Assistant.

Hey there, I’m looking at getting a k10+ and am trying to figure out what level of control you get from this add-on. Do you get a map with room names or just a vacuum entity or some services?? Sorry, really having a hard time finding that info without having the device to try it out

@jackson.moormeier In short, no, is the answer to your question. The K10+ commands and responses are found in the actual API document - just scroll down.