Skip to main content

pySwitchbee

A Python module library to control SwitchBee smart home devices.

PyPI PyPI - Downloads

alt text

Example code usage:

from asyncio import get_event_loop

from aiohttp import ClientSession, ClientTimeout, TCPConnector

from switchbee.api import CentralUnitAPI
from switchbee.device import ApiStateCommand, DeviceType


async def main():
    session = ClientSession(
        connector=TCPConnector(ssl=False),
        timeout=ClientTimeout(total=3),
    )

    cu = CentralUnitAPI("192.168.50.2", "user", "pass", session)
    await cu.connect()

    print(f"Central Unit Name: {cu.name}")
    print(f"Central Unit MAC: {cu.mac}")
    print(f"Central Unit Version: {cu.version}")

    devices = await cu.devices

    for device in devices:
        # set the dimmer lights to 50% brightness
        if device.type == DeviceType.Dimmer:
            print(
                "Discovered Dimmer device called {device.name}"
                " current brightness is {device.brigt}"
            )
            await cu.set_state(device.id, 50)

        # set the shutters position to 30% opened
        if device.type == DeviceType.Shutter:
            print(
                "Discovered Shutter device called {device.name}"
                " current position is {device.position}"
            )
            await cu.set_state(device.id, 30)

        # turn off switches
        if device.type == DeviceType.Switch:
            print(
                "Discovered Switch device called {device.name}"
                " current state is {device.state}"
            )
            await cu.set_state(device.id, ApiStateCommand.OFF)

        # set timer switch on for 10 minutes
        if device.type == DeviceType.TimedPower:
            print(
                "Discovered Timed Power device called {device.name}"
                " current state is {device.state} with {device.minutes_left} "
                "minutes left until shutdown"
            )
            await cu.set_state(device.id, 10)

    session.close()


if __name__ == "__main__":

    get_event_loop().run_until_complete(main())
    exit()

Using the CLI tool:

Alternatively, it is possible to control SwitchBee devices using the cli tool switchbee_cli.py as following:

To list devices that currently on:

python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD get_states --only-on

   '_state': 'ON',
    'hardware': <HardwareType.Switch: 'DIMMABLE_SWITCH'>,
    'id': 311,
    'name': 'Ceiling',
    'type': <DeviceType.Switch: 'SWITCH'>,
    'zone': 'Outdoo Storage'}

{   '_state': 'ON',
    'hardware': <HardwareType.Switch: 'DIMMABLE_SWITCH'>,
    'id': 142,
    'name': 'Spotlights',
    'type': <DeviceType.Switch: 'SWITCH'>,
    'zone': 'Porch'}

To set shutter with device id 392 position 50%:

python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 392 --state 50

To turn on Power Timed Switch with device id 450 for 30 minutes:

python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 450 --state 30

To turn off light with device id 122:

python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 122 --state OFF

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyswitchbee-1.8.3.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyswitchbee-1.8.3-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file pyswitchbee-1.8.3.tar.gz.

File metadata

  • Download URL: pyswitchbee-1.8.3.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pyswitchbee-1.8.3.tar.gz
Algorithm Hash digest
SHA256 62b4599b84f4b71f46369f9e7c57defb725812db99987d55eafde4efdc4df0ec
MD5 81464e1ffa646f4e71ec3c51aa31670f
BLAKE2b-256 fe2cd6434e4c6c173733a0976907925d44380b08d00d616afb59b7ded94f8719

See more details on using hashes here.

File details

Details for the file pyswitchbee-1.8.3-py3-none-any.whl.

File metadata

  • Download URL: pyswitchbee-1.8.3-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pyswitchbee-1.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 668ac21d1f74b08cd8aafb86e7ba442b27fc90f2923ad32acb2999e3450e1b8f
MD5 71ca943e68fd783167ebc617556b9adc
BLAKE2b-256 8c492948120ee1366434122439c738d81ab7fe791628d030d89e8887550bd0cb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.8.3 This release

2 files

1.8.2

2 files

1.8.1

2 files

1.8.0

2 files

1.7.34

2 files

1.7.33

2 files

1.7.32

2 files

1.7.31

2 files

1.7.30

2 files

1.7.29

2 files

1.7.28

2 files

1.7.27

2 files

1.7.26

2 files

1.7.25

2 files

1.7.24

2 files

1.7.23

2 files

1.7.22

2 files

1.7.21

2 files

1.7.20

2 files

1.7.19

2 files

1.7.18

2 files

1.7.17

2 files

1.7.16

2 files

1.7.15

2 files

1.7.14

2 files

1.7.13

2 files

1.7.12

2 files

1.7.11

2 files

1.7.10

2 files

1.7.9

2 files

1.7.8

2 files

1.7.7

2 files

1.7.6

2 files

1.7.5

2 files

1.7.3

2 files

1.7.2

2 files

1.7.1

2 files

1.7.0

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.5

2 files

1.5.4

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.8

2 files

1.4.7

2 files

1.4.6

2 files

1.4.5

2 files

1.4.4

2 files

1.4.3

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.15

2 files

1.3.14

2 files

1.3.13

2 files

1.3.12

2 files

1.3.11

2 files

1.3.10

2 files

1.3.9

2 files

1.3.8

2 files

1.3.7

2 files

1.3.6

2 files

1.3.5

2 files

1.3.4

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.7

2 files

1.1.6

2 files

1.1.5

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page