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

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.

Hello — pleased to come across this add-on. I have what is likely going to be a very novice question. The documentation provides quite a bit of YAML, but doesn’t specify where it goes. Is it intended to go in to configuration.yaml?

For instance, the docs provide the following:

SwitchBot:
  ApiKey: >-
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  ApiSecret: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

and

WebhookService:
  UseWebhook: true
  UseNgrok: true
  NgrokAuthToken: _________________ngrokauthtoken__________________
  HostUrl: <Configuration required only when using Webhook without ngrok>

Specifically where should I place that code?

Thank you!

It is not for configuration.yaml. You need to input it on the add-on configuration screen.
If you installed the add-on on HA-OS, it can be accessed via the following url:
http://homeassistant.local:8123/hassio/addon/cafb8c58_switchbot_mqtt/config

If you installed Home Assistant as a Container or Core, you should configure it as /data/Options.json, since you are likely running a Docker image.
(Details are mentioned in the Wiki.)

1 Like

Thank you very much! Appreciate it.

I now have this working. I have sensors for both the Evaporative Humidifier and the Meter Pro CO2 and can also control the Evaporative Humidifier.

However — the Meter Pro CO2 reports “0” or unknown for all sensors while the Evaporative Humidifier seems to be fully functional. The temp reports 32 degrees F.

Pressing “Polling” does not update values.

The Device ID shown is correct.

Has anyone encountered this before? Are there troubleshooting steps I should try?

Thank you!

Might you have any ideas on why the Meter Pro CO2 is not returning correct data, @hsakoh ?

It seems that there was an outage causing the API service to stop during the following period. Did it have any impact on you? From 2024/12/16 06:47:03 (UTC) for about one day.

It should have recovered naturally, but if it is still ongoing, please first check the add-on logs. Set the log level to trace and obtain the response JSON when you press the Polling button. (I also have a MeterProCO2 monitor, and I am able to obtain values without any issues.)

32 degrees F. is zero in Celsius degrees, which may indicate that no MeterPro values were taken (they are all initial values).

Ah, I might have figured it out. The Evaporative Humidifier is WiFi-enabled, so it sends data to SwitchBot on its own. The MeterPro only has Bluetooth, so it won’t send data to SwitchBot unless it’s connected to the Hub. (To obtain values from the API, it needs to be connected to the internet via the Hub.)

This makes complete sense. I am trying to get around having to install yet another hub.

Thank you @hsakoh! Appreciate it.