platypush.plugins.switchbot

class platypush.plugins.switchbot.SwitchbotPlugin(api_token: str, **kwargs)[source]

Plugin to interact with the devices registered to a Switchbot (https://www.switch-bot.com/) account/hub.

The difference between this plugin and platypush.plugins.switchbot.bluetooth.SwitchbotBluetoothPlugin is that the latter acts like a Bluetooth hub/bridge that interacts directly with your Switchbot devices, while this plugin requires the devices to be connected to a Switchbot Hub and it controls them through your cloud account.

In order to use this plugin:

  • Set up a Switchbot Hub and configure your devices through the Switchbot app.

  • Follow the steps on the Switchbot API repo to get an API token from the app.

__init__(api_token: str, **kwargs)[source]
Parameters

api_token – API token (see Getting started with the Switchbot API).

devices()List[dict][source]

Get the list of devices associated to the specified Switchbot API account.

Returns

[
  {
    "calibrated": "[Curtain devices only] Set to True if the device has been calibrated, False otherwise",
    "cloud_service_enabled": "True if cloud access is enabled on this device,False otherwise. Only cloud-enabled devices can be controlled from the switchbot plugin.",
    "hub_id": "Parent hub device unique ID",
    "id": "Device unique ID",
    "name": "Device name",
    "open_direction": "[Curtain devices only] Direction where the curtains will be opened (\"left\" or \"right\")",
    "type": "Supported types: [Hub, Hub Plus, Hub Mini, Bot, Curtain, Plug, Meter, Humidifier, Smart Fan, Air Conditioner, TV, Light, IPTV / Streamer, Set Top Box, DVD, Fan, Projector, Camera, Air Purifier, Speaker, Water Heater, Vacuum Cleaner, Others]"
  }
]

off(device: str, **kwargs)[source]

Send a turn-off command to a device

Parameters

device – Device name or ID.

on(device: str, **kwargs)[source]

Send a turn-on command to a device

Parameters

device – Device name or ID.

press(device: str)[source]

Send a press-button command to a device.

Parameters

device – Device name or ID.

run_scene(scene: str)[source]

Execute a scene.

Parameters

scene – Scene ID or name.

scenes()List[dict][source]

Get the list of registered scenes.

Returns

[
  {
    "id": "Scene ID",
    "name": "Scene name"
  }
]

set_curtain_position(device: str, position: int)[source]

Set the position of a curtain device.

Parameters
  • device – Device name or ID.

  • position – An integer between 0 (open) and 100 (closed).

set_fan(device: str, speed: Optional[int] = None, swing_range: Optional[int] = None, mode: Optional[int] = None)[source]

Set properties of a smart fan device.

Parameters
  • device – Device name or ID.

  • speed – Speed between 1 and 4.

  • swing_range – Swing range angle, between 0 and 120.

  • mode – Fan mode (1 or 2).

set_humidifier_efficiency(device: str, efficiency: Union[int, str])[source]

Set the nebulization efficiency of a humidifier device.

Parameters
  • device – Device name or ID.

  • efficiency – An integer between 0 (open) and 100 (closed) or auto.

status(device: Optional[str] = None)Union[dict, List[dict]][source]

Get the status of all the registered devices or of a specific device.

Parameters

device – Filter by device ID or name.

Returns

[
  {
    "auto": "[Humidifier devices only] True if auto mode is on",
    "calibrated": "[Curtain devices only] Set to True if the device has been calibrated, False otherwise",
    "child_lock": "[Humidifier devices only] True if safety lock is on",
    "cloud_service_enabled": "True if cloud access is enabled on this device,False otherwise. Only cloud-enabled devices can be controlled from the switchbot plugin.",
    "hub_id": "Parent hub device unique ID",
    "humidity": "[Meter/humidifier devices only] Humidity in %",
    "id": "Device unique ID",
    "mode": "[Smart fan devices only] Fan mode",
    "moving": "[Curtain devices only] True if the device is moving, False otherwise",
    "name": "Device name",
    "nebulization_efficiency": "[Humidifier devices only] Nebulization efficiency in %",
    "on": "True if the device is on, False otherwise",
    "open_direction": "[Curtain devices only] Direction where the curtains will be opened (\"left\" or \"right\")",
    "position": "[Curtain devices only] Position of the device on the curtain rail, between 0 (open) and 1 (closed)",
    "sound": "[Humidifier devices only] True if sound is muted",
    "speed": "[Smart fan devices only] Fan speed, between 1 and 4",
    "swing_direction": "[Smart fan devices only] Swing direction",
    "swing_range": "[Smart fan devices only] Swing range angle, between 0 and 120",
    "swinging": "[Smart fan devices only] True if the device is swinging",
    "temperature": "[Meter/humidifier devices only] Temperature in Celsius",
    "type": "Supported types: [Hub, Hub Plus, Hub Mini, Bot, Curtain, Plug, Meter, Humidifier, Smart Fan, Air Conditioner, TV, Light, IPTV / Streamer, Set Top Box, DVD, Fan, Projector, Camera, Air Purifier, Speaker, Water Heater, Vacuum Cleaner, Others]"
  }
]

property switches
Returns

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

toggle(device: str, **kwargs)[source]

Shortcut for press().

Parameters

device – Device name or ID.