SwitchBot gets an open API!

I think that my question is even dumber lol (so sorry, I am trying to understand how hubitat rules works). I understood the concept of commands and parameters, but I do not know where can I send the command. For example, I want to create a rule with Rule Machine. Trigger button click - Action: TV volume up.(I know how to create the trigger). My problem is where can I write the command in the Actions.

I can not find an action that let me send the command

Thank you for clarifying, since I misunderstood your question.

You want the 'Run Custom Action' option. Then indicate the Switch capability for the Action device. Then specify parameters as you would on the device page -- first command and then parameter (if needed, else omit to use "default").

Here's a sample of the options that you need:

Got it working! thank you so much!

1 Like

Looks like this might be a Zigbee enabled version of Switchbot?

1 Like

Hi Tomw,

I have a SwitchBot Curtain that I want to use with a motion sensor, but am having issues using it in Rule Machine. I've installed all the driver code and set up a child device. When creating a rule, I am not sure what selections to make to open/close the SwitchBot. Does this look correct?

That does look like it should work, but maybe you'd get a better result with using the on or off commands for capability switch, rather than doing it as a custom command.

What happens when you run the rule actions? Does anything show up in the logs?

Thank you for the reply and sorry for the slow response. When I run action, nothing seems to happen. I cannot toggle the curtain bot from my phone app either. I am going to try uninstalling/reinstalling to see if that fixes the issue.

Edit: Reinstalling the virtual devices did not fix the issue. It seems like the curtain bot is not able to be turned on/off or toggled through the hubitat app, even though it is showing up as a device.

do you mean the HE app or the Switchbot app? you might need to repair HE to your Switchbot account

Did you mean the SwitchBot app does not work? I would not expect it to work in HE if it doesn't work in the SwitchBot app first.

I'd focus on getting it working in the SwitchBot app first, potentially by deleting and re-pairing the device to your SwitchBot hub. Once it is working reliably there, then try it again in HE.

Sorry that was confusing. I can get the SwitchBot to work in the SwitchBot app, but cannot get any actions to trigger through the HE app.

OK, something must be failing between my HE driver and the SwitchBot cloud, then. Will you enable debug logging on both the SwitchBot System and SwitchBot Curtain virtual devices and PM the log to me that shows what happens when you try to close or open the curtain?

What's the best way to approach retries on errors between switchbot hub and switchbots?

From time to time my hub will fail to communicate to switchbot curtain - I'll see in the switchbot app logs things like "Connection error (161)" or "Unknown error (190)". Those errors don't propagate via API (I didn't see them in hubitat with enabled debug logging), so the driver in hubitat isn't aware of errors.

I just added simple hacks in the driver code to call each action multiple time, but it's not really a great fix. Do other people have same issues? Any better solutions?

Will you please post a screenshot of the log where you see that error? I want to see how and where it is showing up.

Are you saying that you just execute each command more than once, regardless of whether or not it fails?

I wonder if that status shows up in the reply to a command to the switchbot API. If I turn on logging in the SwitchBot System parent device with my drivers, I see this in the response:

resp.data = [statusCode:100, body:[deviceId:E2CDFxxxxxxx, deviceType:Meter, hubDeviceId:F376xxxxxxxx, humidity:54, temperature:23.2], message:success]

Here are errors from the switchbot app on the phone (it's accessible by clicking on the curtain in the app -> settings -> log) - 1st and 3rd request returned connection error (161)

Meanwhile, on the hubitat side, no errors - all 100:

dev:2612021-06-15 01:09:58.051 pm debugresp.data = [statusCode:100, body:[:], message:success]
dev:2612021-06-15 01:09:56.766 pm debughttpPostExec([uri:https://api.switch-bot.com/v1.0/devices/[...]/commands, headers:[Authorization:[...], Content-Type:application/json; charset=utf8], body:{"command": "turnOn", "parameter": "default","commandType": "command"}])
dev:2612021-06-15 01:09:46.678 pm debugresp.data = [statusCode:100, body:[:], message:success]
dev:2612021-06-15 01:09:45.267 pm debughttpPostExec([uri:https://api.switch-bot.com/v1.0/devices/[...]/commands, headers:[Authorization:[...], Content-Type:application/json; charset=utf8], body:{"command": "turnOn", "parameter": "default","commandType": "command"}])
dev:2612021-06-15 01:09:40.182 pm debugresp.data = [statusCode:100, body:[:], message:success]
dev:2612021-06-15 01:09:39.129 pm debughttpPostExec([uri:https://api.switch-bot.com/v1.0/devices/[...]/commands, headers:[Authorization:[...], Content-Type:application/json; charset=utf8], body:{"command": "turnOn", "parameter": "default","commandType": "command"}])

Do you see failures when moving the curtains by using Hubitat, even though the reply indicates success?

Yes, curtain doesn't move when I get 100 on the Hubitat but see errors in the app. I'm now sending all commands 3 times, with small delay between them. It's ok workaround for me.
It does seem like a switchbot backend issue that should be doing retries, but posting here in case more people face it, and there's an easy way to do smarter retries in the driver.

1 Like

Just to reply to myself. I also contacted switchbot about this issue, and it seems like a known problem that's already fixed. They sent V3.1-2.3 firmware upgrade to the hub, that's suppose to fix it. I've just installed it, and quick test seems to work fine, but we'll see in few days if it's proper fix. I was also told to avoid quick retries, as it'll cause 161 errors to occur.

1 Like

Just curious, is anyone happy with these for rod curtains? I’ve read multiple horror stories. But I see they are having a great prime day sale.

I have 5 of them. They are about half year old.
So far so good but periodically I have to recalibrate them.
This is a bit annoying but not a big deal.

3 Likes

I know this is late for your prime deal. I have 8 of them. They work pretty well. The big issues, which wouldn't stop me from buying them are:

For some reason at my place, bluetooth connections are horrible. I think I've tracked it down to all the google home / speaker devices I have probably all advertising on the bluetooth channels. But that aside, in order to get them to work I had to get one of the mini hubs for each room and put it close to the curtains to get a reliable bluetooth connection. I'm guessing this is a me only issue.

As @vitaliy_kh stated, they sometimes do need to be recalibrated. I think they stay in calibration best if they have something to "hit" as a stop for both open and close - such as hitting the end of the rod and can no longer move. You'll likely have issues if you want to set the fully open before the end of the rod, such as to keep the curtain from being fully compressed.

I have rod curtains. Most of my windows only have 1 switchbot. So I have curtains on both sides of the window, but only one moves. It goes fully across the window to the other side to meet the other curtain. A bit wacky, but I'm not yet convinced to buy another bunch of them just to have both sides of the curtain move together.

With grommet type curtains, they likely won't be able to pull the curtain very far due to the friction caused by the angles of the grommets on the rod when you pull from the one end of the curtain. I have no trouble going across maybe a 3 foot window, but after that there are issues. They sell a grommet accessory that helps with this - a clear plastic cord that goes on top of the curtain to make it pull without causing the grommets to bind up. But I think it looks ugly. Haven't decided if I want to buy the accessory or just find a new curtain - I hear back tab curtains work better.

Finally, the android app, which you probably won't use after setup except for recalibration, is horrible.

All that said, I was considering buying another 6 of them to make my 6 one-sided windows dual open. I ended up not doing so, but it was 50/50. I think I'll wait to see what comes out next, buy some of those, and consolidate what I have to dual action.

2 Likes