Switchbot Curtain

as a workaround - i might try and make my HA shell_commands read the successful "OK!"and try again on failure or at least show an error to the user.

I have updated the script.js to have a ok/error check via mqtt. Every time you call the bot, it will either have ok or error message output to mqtt.

From there you can create a sensor and use it to re run the bot if it outputs error. You will need to think how you can implement this check for all your bots. I was testing it on the bot device using script. Seems to work. The below script template will run 10 times or until until sensor.switchbot_status state is ok.

script.yaml

  switchbot_bot_enable:
    sequence:
    - repeat:
        until:
        - condition: or
          conditions:
          - condition: template
            value_template: "{{ is_state('sensor.switchbot_status', 'ok') }}"
          - condition: template
            value_template: "{{ repeat.index % 10 == 0 }}"
        sequence:
        - service: switch.turn_{{ mode }}
          data:
            entity_id: '{{ bot }}'

automation.yaml

- alias: 'turn on 24hr fan'
  trigger:
    platform: time
    at: '05:30:00'
  condition:
  - condition: template # Not on Vacation
    value_template: "{{ not is_state('input_select.home_mode', 'Vacation') }}"
  - condition: template # Someone is home
    value_template: "{{ not is_state('input_select.home_mode', 'Away') }}"
  action:
    - service: script.switchbot_bot_enable
      data:
        mode: 'on'
        bot: switch.24hr_fan_bot

- alias: 'turn off 24hr fan'
  trigger:
    platform: time
    at: '23:00:00'
  condition:
  - condition: template # Not on Vacation
    value_template: "{{ not is_state('input_select.home_mode', 'Vacation') }}"
  - condition: template # Someone is home
    value_template: "{{ not is_state('input_select.home_mode', 'Away') }}"
  action:
    - service: script.switchbot_bot_enable
      data:
        mode: 'off'
        bot: switch.24hr_fan_bot

sensor.yaml

  - platform: mqtt
    name: 'Switchbot Status'
    state_topic: 'switchbot/status/msg'
    value_template: '{{ value }}'

Guys, I’m planning to buy Switchbot Curtain but I have some doubts.
I have NAS with Docker HA installed 2nd floor and curtains which I wish to control on 1st floor. Im pretty sure of that Bluetooth range will not cover that place.

Is it possible to extend a range of bluetooth or mage Rpi Zero as some kind of extender or bridge?
Upper you wrote about switchbots.js as I understand I have to install it on Rpi0? This connect via MQTT with my Mosquito Broker on NAS?

So the communication looks like:
SwitchBot -- (BT) --> Raspberry Pi -- (MQTT - WiFi) --> NAS with MQTT

Did I understand correctly?

Hi.
That looks right. Though mqtt is optional if you don’t care about knowing the data of the bot. My pi 3 is connected via wire, but I am sure wifi will work as well. Just make sure the pi zero has good wifi coverage.

You have the pi zero W? Let us know how it goes if you are going to go forward with it. I am thinking about switching over to a rpi zero w myself.

Is it possible to extend a range of bluetooth or mage Rpi Zero as some kind of extender or bridge?

I am not sure if that is possible or if it is, it maybe not worth the trouble not knowing how far it can be extended.

Is anyone integrate Switchbot Curtain via BT-MQTT-GATEWAY (https://github.com/zewelor/bt-mqtt-gateway)?
Yesterday with success I installed this on my old RPi0 and connected to Xiaomi Thermostat.
In documentation it support Switchbot but I didn’t found information if it support Curtain.

Hi Everyone,

My set up is HA installed via docker on a NAS in the basement and the curtains are in the bedroom two floors up. I do have the Hub in the bedroom.

I recently purchased the switchbot curtain and it works very well. I’m also starting out with HA for the 4th time. I integrated the curtain via mac and it does show up in HA. However, none of the buttons do anything. I’m assuming that is because it’s trying to communicate via BT and it can’t reach it.

I’ve read through this entire thread and I’m not more confused than I started. I’ve tried using the mac of the curtain, hub and BLE but only the mac for the curtains show up as pressable buttons (which again don’t do anythign when clicked).

Is there a way to integrate the HUB to control the curtains in HA?

TIA

The curtain integration provided by the user above works by communicating with HA via BT and not the Switchbot Hub. Since your HA is install 3 floors down, it is out of range. Does your NAS have BT?

As far as I know, there is no HA Integration to talk to the hub. However, there is a switchbot api method you can try which needs the hub to communicate. Request a token via the mobile app feedback. I don’t have a hub to test. But an example of a way to trigger via HA is by curl.

curl "https://api.switch-bot.com/v1.0/devices" -H "authorization: YOUR_TOKEN_KEY"

The downfall to the api method is that, if you lose internet connection, you will not be able to trigger your devices. An alternative is to move your HA closer to the curtain device or install another server (ex. rpi) and try my method.

There is another method I have found recently that uses ESP32 to connect to the device. It is setup for 2 bot devices and the author claims it should work for the curtain devices as well, but not tested.

1 Like

ya it should work with curtains, but I would have to make a couple code changes. It currently only does push. Shouldn’t be difficult to make the changes for open/close calls. I can look at that this weekend if someone wants to test

I have updated my esp32 code

  • it is now setup to work with “unlimited” devices
  • it works with press/on/off (buttons)
  • it works with open/close/pause (curtains)

I’ve read your guide again and it seems the switchbot hub is needed with this setup? I don’t have the hub to test.

no switchbot hub needed for my esp32 setup. Any smarthub that can do MQTT works.

HA <–(MQTT)–> ESP32 <–(Bluetooth BLE) --> switchbot

1 Like

thanks for this. Reading your guide, i’m not sure if this will work in my situation as all i have is the switchbot hub. I’m also still having issues getting Mosquitto MQTT to work properly on my Qnap Nas. I took a look at the switchbot api solution as well and that was a bit over my head.

I do however have an old smartthings hub laying around somewhere thats not being used. not sure if that would help.

I was hoping there was a solution for HA (in docker on a QNAP NAS) > Switchbot Hub > Switchbot Curatin.

If you don’t mind using the api, which means you’ll need an active internet connection for this to work, it’s quite easy to get it working. I’ve posted instructions here: Switch-Bot API integration - Feature Requests - Home Assistant Community (home-assistant.io)

there are a couple solutions. you just need to decide which one suite your needs. using the switchbot hub is a solution but will always require internet access as mentioned

If you want full local control you need to do it with bluetooth BLE. You can either have your smarthub make the bluetooth calls or have your smarthub call something else, and that something else makes the bluetooth calls.

for me, my main switchbot is too far from my smarthub to be reliable. This is why I wrote the esp32 option. an esp32 cost $5.

my esp32 option avoids the hassle of ensuring the linux box bluetooth is configured correctly. you don’t use the bluetooth on the linux box.

2 Likes

Thank you for your code. I tested it and it is working impressively good.
I noticed a bug with the position of the curtains, which is reported after using requestInfo.
Independently from the state of the curtain it always reports the same position.

yes there is an issue with the curtain and meter values I am hoping to get to that this weekend

the control part should be pretty solid though. I put in a couple fixes recently

I would like to let you know that using your latest version position is reported correctly for switchbot-curtains.

Thank you!

cool thanks. to get the latest value I needed to do a rescan of that specific bluetooth device

when you call requestInfo, it deletes the current device and rescans for it. it will scan max 60 sec, but should only take a sec depending on distance from bot

so you should be able to spam control calls as much as u want. When calling requestInfo tho, depending on how close the devices are, you wont want to spam those calls to often

I might have a better version at some point which doesnt need to rescan. I just havent figured that out yet

for now though the code should work for all switchbot devices bot, curtain, temp sensor

Thank you, I noticed that after some hours (with one requestInfo per hour) the device doesn’t respond any more and needs a power cycle. I should probably avoid sending requestInfo commands.

There is an issue. It does become unresponsive with my latest code, Ill look at it later