Problem with switchbot 3 curtain

I use openhab with config files. openmqttgateway works fine (webupload esp32dev-ble) and mqttexplorer shows me ble devices nearby. but I only get the mac and rssi:
BTtoMQTT: {“id”:“E1:xx:xx:xx:xx:xx”,“rssi”:-53}
how can I get more Information/connect to switchbot via mqtt.
I don’t see details like battery,…
Later on I will define the things in openhab by myself (without auto discovery).

Welcome @usrstephan

Could you set Advertisement and advanced data to true and post some more messages then received with the actual undecoded advertising data, so we can see what might be the issue of your undecoded SwitchBot 3 Curtains?

Also a copy of your BTtoMQTT message would help, to see the settings of your gateway.

sure, after setting advanced data to true:
{"id":"E1:xx:xx:xx:xx:x","mac_type":1,"adv_type":0,"manufacturerdata":"6909e1301c7a763b3c030011040057","rssi":-56,"servicedata":"7bc057001104","servicedatauuid":"0xfd3d"}

BTtoMQTT:
{"bleconnect":true,"interval":55555,"adaptivescan":true,"intervalacts":55555,"intervalcnct":3600000,"scanduration":10000,"onlysensors":false,"randommacs":false,"hasspresence":false,"prestopic":"presence/","presuseuuid":false,"minrssi":-100,"extDecoderEnable":false,"extDecoderTopic":"undecoded","filterConnectable":false,"pubadvdata":true,"pubuuid4topic":false,"ignoreWBlist":false,"presenceawaytimer":120000,"movingtimer":60000,"forcepscn":false,"tskstck":2936,"crstck":3116,"enabled":true,"scnct":1}
hope that helps…

Thanks @usrstephan !

I almost forgot that I have only added the 3 model of the SwitchBot Curtain to Theengs Decoder 3 weeks ago, released with version 1.6.7, so it is not yet included in the current OpenMQTTGateway release 1.7.0.

Could you try the same esp32dev-ble binary install with the latest development test version available at

https://docs.openmqttgateway.com/dev/upload/web-install.html

Takes about 90 minutes from now to be available there with SHA: fc1ce0

It will then correctly recognise your Curtain 3 already and will be included in the next official OpenMQTTGateway release.

You above sample will then be decoded and published as

{"brand":"SwitchBot","model":"Curtain (2/3)","model_id":"W070160X","type":"WCVR","acts":true,"moving":false,"position":0,"calibrated":true,"lightlevel":1,"batt":87}

Let us know how you get on with the development test build above.

I will define the things in openhab by myself (without auto discovery).

That is how I like to do it as well :wink:

@usrstephan

There was a small hiccup with the previous development build.

Now available at

Let us know how it works for you.

thanks so much - it works like a charm:
{"id":"E1:xx:xx:xx:xx:x","rssi":-52,"brand":"SwitchBot","model":"Curtain (2/3)","model_id":"W070160X","type":"WCVR","moving":false,"position":0,"calibrated":true,"lightlevel":1,"batt":87}
may I ask for some additional information:

  • could you tell me the topic and message needed for e.g. changing the position to 45. I did not find that information in the docs (only auto discovery)
  • do you have definitions for the different versions (e.g. xxx-ble vs xxx-ble-mqtt-unencoded)
  • using arduino ide does not work for me (yes, I added the libraries and did not change any configuration for testing)

I’m not sure if the Curtain 3 uses the same commands as Curtain 1/2, but for these they would be

Open : 570F450105FF00
Close : 570F450105FF64
Certain position: 570F450105FF00-64 (0-100%)
Stop : 570F450100FF

With
serviceUUID = “cba20d00-224d-11e6-9fb8-0002a5d5c51b”
charUUID = “cba20002-224d-11e6-9fb8-0002a5d5c51b”

for an OpenMQTTGateway WRITE command, e.g.

{"ble_write_address":"AA:BB:CC:DD:EE:FF",
  "mac_type":1,
  "ble_write_service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b",
  "ble_write_char":"cba20002-224d-11e6-9fb8-0002a5d5c51b",
  "ble_write_value":"570F450105FF2D",
  "value_type":"HEX",
  "ttl":4,
  "immediate":true }'

with the 2D hex for 45 decimal.

Let us know if this also works for Curtain 3.

do you have definitions for the different versions (e.g. xxx-ble vs xxx-ble-mqtt-unencoded)

They are actually on the non-development web upload page :wink:

Using Visual Studio Code with the PlatformIO extension is a lot easier to set up and use.

it works flawlessly:-)
thanks for your detailed answers. I probably would not have guessed how to do that otherwise. I hoped, there was some sort of conversion for commands like:
prefix/gateway/commands/MQTTtoBT/xxxxxxxx
{"position":45}'

anyway - great software!!!

1 Like

We are looking into this for devices which we have state decoders for, like the Curtain, and already doing it for the SwitchBot Bot, admittedly with some issue recently.

For all other devices, basically any Bluetooth device to which you can connect to and which accepts READ or WRITE commands, OpenMQTTGateway has these generic READ/WRITE commands.

I’m trying this against curtain V2, and running theengs gateway in a Docker Container.
Once i send the msg the container immediately crashes with the following error:

INFO:BLEGateway:Received `{ "mac_type":1, "ble_write_service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b", "ble_write_char":"cba20002-224d-11e6-9fb8-0002a5d5c51b", "ble_write_value":"570F450105FF2D", "value_type":"HEX", "ttl":4, "immediate":true }` from `home/TheengsGateway/commands` topic
Traceback (most recent call last):
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 91, in get_address
    return data["mac"]  # type: ignore[return-value]
           ~~~~^^^^^^^
KeyError: 'mac'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/__main__.py", line 5, in <module>
    main()
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/__init__.py", line 57, in main
    run(configuration, config_path)
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 599, in run
    gw.client.loop_forever()
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 223, in on_message
    self.publish_json(msg_json, decoded=False)
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 507, in publish_json
    + get_address(data_json).replace(":", ""),
      ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 93, in get_address
    return data["id"]  # type: ignore[return-value]
           ~~~~^^^^^^
KeyError: 'id'

Welcome @Mohamed_Negm

Theengs Gateway does not have the ability to read or write commands so far, only OpenMQTTGateway does.

Something we are looking into to also implement in a future version Theengs Gateway.

Ohh… didn’t know that.
Is there a possibility to run OpenMQTTGateway in a container as well?

Runs on an ESP32

@Mohamed_Negm While Theengs Gateway doesn’t support the payload you’re sending, it shouldn’t crash on receiving it. This is fixed now in Don't crash when receiving JSON message without id by koenvervloesem · Pull Request #223 · theengs/gateway · GitHub and will be in the next release.

Thanks alot for the feedback.
will update once the release is out.

are you sure about the stop command? (It does not work for me)
I am currently implementing the switchbot in openhab. Should I post the config files somewhere in this forum?

All I’m sure of is that this was confirmed to work with the Curtain and Curtain 2. If and how SwitchBot might have changed this for the Curtain 3 I’m not really sure.

Even the semi-official SwitchBot repo doesn’t seem to have any updated Curtain 3 information.

Could Stop be 570F45010001 for the Curtain 3?

One other thing I stumbled across for Curtain 3, is that by swapping the FF octet to 01 in the Open, Close and Position commands it should move the Curtain 3 in its unique new slow quiet mode.

Would be great if you can confirm any of the above.

Could Stop be 570F45010001 for the Curtain 3?

my mistake - both commands work (570F450100FF and 570F45010001) to stop

One other thing I stumbled across for Curtain 3, is that by swapping the FF octet to 01 in the Open, Close and Position commands it should move the Curtain 3 in its unique new slow quiet mode.

yes - changing 570F450105FFxx to 570F45010501xx switches to slow mode. That mode is actually so slow that I thought it would not work at first - but after double checking with the App I can confirm it works. It works with close, open and even position changes.

One problem remains: every time the curtain is opened and closed it stops about 1 to 2 cm earlier - after ten times it is remarkable. It is better after manual calibration but not really great. Do you know any trick to change this - perhaps with a special command?

Please let me know if I should check anything else.

one more remark:
I used esp32 first and switched to esp-c3. This one is more reliable and does not have hickups…

I would think this is a purely hardware specific issue, possibly that the grip of the Curtain 3 is not strong enough or needs agjusting, or the actual curtain too heavy to be properly moved, but without any person experience with the SwitchBot Curtian at all I really couldn’t tell, sorry.