Switch-Bot API integration

Hi there - First off thank you so much for this great discussion on this topic. I have been able to get one set of my SwitchBot Curtain 2 working with the API integration. However, when I am working to add my second curtain 2 for another room, I am getting the following error.

Template variable warning: 'parameter' is undefined when rendering '{"command": "{{ command }}","parameter": "{{ parameter }}"}'

What is interesting to me is when I open the switchbot app and look at the log for the device, i do see a Failed to connect warning where it calls out API. So it seems like it is connecting and authenticating okay, but having problems getting to the curtain 2 from the hub. I double checked the deviceID and can use curl to query the url status, and it reports as expected.

What is interesting to me is that the API request to fetch the location (closed/open) is working, it is just when I try to do a close/open/stop on the cover. So to me it seems like the POST command and call is failing. But it shouldn’t be a problem with the POST command since the same code works for the other curtain set…

Any thoughts on where to look, or others have problems with just a single device? Almost seems like a permission issue or something.

1 Like

Just responding that I figured out the issue.

For anyone else going down this rabbit hole, have a look at this: GitHub - OpenWonderLabs/homebridge-switchbot: The Homebridge SwitchBot plugin allows you to access your SwitchBot Device(s) from HomeKit. Homebridge.

Between spinning up the container, adding the switchbot plugin, and setting it up, I probably only lost 15 minutes. Muuuuuch less than the amount of time I was sinking into getting Bluetooth working through Docker or setting up these python scripts.

Once Homebridge was done, it was automatically detected by Home Assistant and waiting for me in the integrations page. Couple clicks later, I’m able to control my “Bot” (the button-pushing one) with the switch.toggle service

1 Like

Ugh, well that’s sad… I’m not sure what is going on with the integration team, but this sounds like an easy method of using the API rather than Bluetooth. (Which I have never liked as a point of communication. Using BT for initial install is fine, but unfortunately right now the official integration gets a B- for competition and a D+ for effort) any time I try to setup a Bluetooth dongle, it works great for a day then I get severe hardware hci issues. Ends up bricking supervisor. The proxy will work but it’s another item you gotta plug in and well at the end of it all you can only passively connect to 3 devices maximum.

@Nardol is there anyway to convert this integration to have 2 methods of connection. 1 current system, 2 cloud/API?

I have created a new add-on using the SwitchBotAPI and have released it.
Please refer to the following topic for more details.

Additionally, I will share what I discovered during development.
While not documented in the API specifications,
I have found commands to operate default buttons of automatically detected or list-selected virtual infrared remote devices.
The command type is “tag”.

  • Example payload for preset commands
    {"commandType":"command","command": "turnOn","parameter": "default"}
    {"commandType":"command","command":"setPosition","parameter":"0,ff,70"}

  • Example payload for custom commands:
    {"commandType":"customize","command": "MyButtonName","parameter": "default"}

  • Example payload for tag commands
    {"commandType":"tag","command": "1","parameter": "default"}

Based on a limited range of testing, it seems that the buttons are assigned sequentially from the top left of the screen, with smaller numbers assigned first.

1 Like

Does anyone have API version 1.0 working with a recent version of Home Assistant like 2023.8? I got a message when I upgraded saying:

The switchbot integration does not support YAML configuration

How can I configure it then via some automated method? Don’t the Home Assistant developers understand that if you integrate a 100 services that you can’t do that manually anymore?

I have over 53 switchbot devices.

Is anything known about how long API version 1.0 will still work? I configured it with the understanding that it would work “forever”. Is there an alternative to Switchbot temperature sensors that will continue to work?

Update: actually, I am thinking that perhaps the Home Assistant Switchbot integration is completely independent of these REST-calls. As such, I should just be able to not install the integration and the error would go away. It has been a long time ago that I set it up. Can someone acknowledge that please?

I wouldn’t mind porting my configuration to the 1.1 API if that has some real benefits. All I care about is the temperature value right now.

The Switch Bot native integration uses Bluetooth, not the API.

If you have rest sensors to get temperature from your switch bot meters and this solution is OK for you, there is no need for the native integration.
Personally I have switched to the native integration with a Bluetooth dongle and an ESP32 Bluetooth proxy, when this topic was created meters was not compatible with the native integration which used YAML.

I haven’t found a Bluetooth device that doesn’t scream in dmesg all day long how it doesn’t work. Which one are you using? I bought the “best” that Amazon had a year ago or so.

(I also tried the ESP32 Bluetooth proxy, but not all sensors are reachable.)

For the ESP32 bluetooth proxy if you use a Wifi ESp32 you might use two, in my case I have only one and this Bluetooth dongle.
It is listed as one which has best performance in the Bluetooth integration documentation.

I made a pull requests to add API support for plugs and remotes as switches.

3 Likes

Nice to see your PR has been merged, congrats @SeraphicRav!

1 Like

Thanks ! The first version is quite basic, it only allows to turn on/off plugs and remotes configured in hubs.,

Still wondering what I should implement next.

1 Like

How could I test this integration? The possibility of creating a media player for each device added to SwitchBot (in my case TV and amplifier) would already be sufficient for me. With broadlink I was able to do this with “SmartIR” and for me it’s great

I think it will be available in the next release in October.

For now, it only handles on/off for remotes.

I tried to integrate Switchbot and it tells me it can’t find anything connected to Bluetooth. I was trying to connect the hub with IR but I couldn’t. Even on off it would have been enough for me

Sorry, I meant the new integration Switchbot Cloud which should be released next October will support only on/off by infrared.

The current integration for Switchbot will be renamed Switchbot Bluetooth during that release.

1 Like

Thank you for the SwitchBot cloud integration. Am I right to say that this integration only supports remote and hub, and won’t be able to work with other devices like curtain bots yet?

The documentation here SwitchBot Cloud - Home Assistant seem to suggest everything will work, so it was a bit misleading. I was confused and thought there was a bug until I looked at the PR and realized it isn’t a full support yet.

1 Like

Yes for now it supports only supports plugs and remotes through hubs.
I am currently working on a better support for the remote feature. Will probably extend to the vacuum cleaner and camera (if the api is available).

For already supported Bluetooth devices, I am not planning yet for support but maybe another developper will add them.

1 Like

So, is there any IR blaster support coming? Or what do you mean by remotes?

This device is the remote:

Oh, I see, I understand the confusion now.

I meant IR appliances in the SwitchBot app which can be controlled by the different hubs.

1 Like