switchbot.bluetooth

class platypush.plugins.switchbot.bluetooth.SwitchbotBluetoothPlugin(interface=None, connect_timeout=None, scan_timeout=2, devices=None, **kwargs)[source]

Plugin to interact with a Switchbot (https://www.switch-bot.com/) device and programmatically control switches over a Bluetooth interface.

See platypush.plugins.bluetooth.ble.BluetoothBlePlugin for how to enable BLE permissions for the platypush user (a simple solution may be to run it as root, but that’s usually NOT a good idea).

Requires:

  • pybluez (pip install pybluez)

  • gattlib (pip install gattlib)

  • libboost (on Debian `apt-get install libboost-python-dev libboost-thread-dev)

class Command(value)[source]

Base64 encoded commands

__init__(interface=None, connect_timeout=None, scan_timeout=2, devices=None, **kwargs)[source]
Parameters
  • interface (str) – Bluetooth interface to use (e.g. hci0) default: first available one

  • connect_timeout (float) – Timeout for the connection to the Switchbot device - default: None

  • scan_timeout (float) – Timeout for the scan operations

  • devices (dict) – Devices to control, as a MAC address -> name map

off(device, **kwargs)[source]

Send a press-off button command to a device

Parameters

device (str) – Device name or address

on(device, **kwargs)[source]

Send a press-on button command to a device

Parameters

device (str) – Device name or address

press(device)[source]

Send a press button command to a device

Parameters

device (str) – Device name or address

scan(interface: str = None, duration: int = 10) platypush.message.response.bluetooth.BluetoothScanResponse[source]

Scan for available Switchbot devices nearby.

Parameters
  • interface – Bluetooth interface to scan (default: default configured interface)

  • duration – Scan duration in seconds

property switches: List[dict]
Returns

[
  {
    "id": "Device unique ID",
    "name": "Device name",
    "on": "True if the device is on, False otherwise"
  }
]

toggle(device, **kwargs)[source]

Toggle the device status (on/off)