Skip to main content

Python bindings for the e7-switcher C++ client

Project description

E7 Switcher Library

A cross-platform library for controlling Switcher smart home devices from ESP32 and desktop platforms (Mac/Linux/Windows), with support for x86_64 and aarch64.

Switcher smart home devices are manufactured by Switcher.

This repo is not affiliated with the Switcher product, it is meant to help give some extra automation capabilities to Switcher devices.

Features

  • Control Switcher devices (switches, AC units, boilers)
  • Cross-platform compatibility: ESP32, Mac, Linux, and Windows
  • CPU architectures: x86_64 and aarch64
  • Easy integration with PlatformIO and CMake projects
  • Python bindings for easy integration with Python projects

Installation

Using PlatformIO

Add the library to your platformio.ini file using the PlatformIO registry package name:

lib_deps =
    elhanan7/e7-switcher

Note: If you need the latest, unreleased changes, you can depend directly on the Git repository instead. Prefer the registry package for stability.

lib_deps =
    https://github.com/elhanan7/e7-switcher.git

Using CMake

There are multiple ways to include this library in your CMake project:

Option 1: Using FetchContent

include(FetchContent)
FetchContent_Declare(
    e7-switcher
    GIT_REPOSITORY https://github.com/elhanan7/e7-switcher.git
    GIT_TAG main  # or specific tag/commit
)
FetchContent_MakeAvailable(e7-switcher)

# Link with your target
target_link_libraries(your_target PRIVATE e7-switcher)

Option 2: Using find_package

First, install the library:

git clone https://github.com/elhanan7/e7-switcher.git
cd e7-switcher
mkdir build && cd build
cmake ..
make
sudo make install

Then in your CMakeLists.txt:

find_package(e7-switcher REQUIRED)
target_link_libraries(your_target PRIVATE e7-switcher::e7-switcher)

Using Python Bindings

The library provides Python bindings using pybind11, allowing you to control Switcher devices from Python.

Installation

Install from PyPI (recommended):

pip install e7-switcher

Install from source (optional):

# From the repository root
pip install build
python -m build
pip install dist/e7-switcher-1.0.6-py3-none-any.whl

Dependencies

For ESP32

  • Arduino framework
  • ArduinoJson (v7.0.4 or higher)
  • zlib-PIO

For Desktop

  • CMake 3.10 or higher
  • C++17 compatible compiler
  • OpenSSL development libraries
  • nlohmann_json library (v3.11.2 or higher)
  • zlib

For Python Bindings

  • Python 3.6 or higher
  • pybind11 (automatically fetched during build)
  • pip and setuptools

Usage

Basic Usage

#include "e7-switcher/e7_switcher_client.h"
#include "e7-switcher/logger.h"

// Initialize the logger (debug messages are disabled by default)
e7_switcher::Logger::initialize(); // Default log level is INFO
auto& logger = e7_switcher::Logger::instance();

// To enable debug messages:
// e7_switcher::Logger::initialize(e7_switcher::LogLevel::DEBUG);

// Create client with your credentials
e7_switcher::E7SwitcherClient client{"your_account", "your_password"};

// List all devices
const auto& devices = client.list_devices();
for (const auto& device : devices) {
    logger.infof("Device: %s (Type: %s)", device.name.c_str(), device.type.c_str());
}

// Control a switch (optional auto-off timer in seconds)
client.control_switch("Your Switch Name", "on", 0);  // action: "on"/"off", operation_time seconds

// Get switch status
e7_switcher::SwitchStatus status = client.get_switch_status("Your Switch Name");
logger.infof("Switch status: %s", status.to_string().c_str());

// Control a boiler (optional auto-off timer in seconds)
client.control_boiler("Your Boiler Name", "on", 1800);  // turn on for 1800 seconds (30 minutes)

// Get boiler status
e7_switcher::BoilerStatus boiler = client.get_boiler_status("Your Boiler Name");
logger.infof("Boiler status: %s", boiler.to_string().c_str());

// Control an AC unit
client.control_ac(
    "Your AC Name",
    "on",                        // "on" or "off"
    e7_switcher::ACMode::COOL,  // COOL, HEAT, FAN, DRY, AUTO
    22,                          // temperature
    e7_switcher::ACFanSpeed::FAN_MEDIUM,  // FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO
    e7_switcher::ACSwing::SWING_ON        // SWING_OFF, SWING_ON, SWING_HORIZONTAL, SWING_VERTICAL
);

Python Usage

from e7_switcher import E7SwitcherClient, ACMode, ACFanSpeed, ACSwing

# Create client with your credentials
client = E7SwitcherClient("your_account", "your_password")

# List all devices
devices = client.list_devices()
for device in devices:
    print(f"Device: {device['name']}, Type: {device['type']}")

# Control a switch (optional auto-off timer in seconds)
client.control_switch("Your Switch Name", True, 0)    # Turn on, no timer
client.control_switch("Your Switch Name", False, 600)  # Turn off with 600-second timer

# Get switch status
status = client.get_switch_status("Your Switch Name")
print(f"Switch is {'ON' if status['switch_state'] else 'OFF'}")

# Control a boiler (optional auto-off timer in seconds)
client.control_boiler("Your Boiler Name", True, 1800)  # Turn on for 1800 seconds (30 minutes)

# Get boiler status
boiler = client.get_boiler_status("Your Boiler Name")
print(f"Boiler is {'ON' if boiler['switch_state'] else 'OFF'}; power={boiler['power']}W; energy={boiler['electricity']}kWh")

# Control an AC unit
client.control_ac(
    "Your AC Name",
    True,                  # Turn on
    ACMode.COOL,           # Mode
    22,                    # Temperature
    ACFanSpeed.FAN_MEDIUM, # Fan speed
    ACSwing.SWING_ON       # Swing
)

# Get AC status
status = client.get_ac_status("Your AC Name")
print(f"AC is {'ON' if status['power_status'] == 1 else 'OFF'}")

Fluent AC Control (Python)

You can use a fluent, chainable interface to control AC devices. The fluent builder initializes from the current AC status and lets you set properties in a readable manner before executing with do().

from e7_switcher import E7SwitcherClient

client = E7SwitcherClient("your_account", "your_password")

# Start from current state, set target state fluently, then execute
client.control_ac_fluent("Your AC Name").cool().fan_low().temperature(22).on().do()

# Flexible setters: strings, enums, ints, and booleans
client.control_ac_fluent("Bedroom").mode("heat").fan("HIGH").swing_off().timer(30).on().do()

# Using enums explicitly
from e7_switcher import ACMode, ACFanSpeed, ACSwing
client.control_ac_fluent("Office").mode(ACMode.DRY).fan(ACFanSpeed.FAN_AUTO).swing(ACSwing.SWING_ON).do()

Available chainable methods include:

  • Power: on(), off(), power(value)
  • Mode: mode(value), auto(), dry(), fan_mode(), cool(), heat()
  • Temperature: temperature(value)
  • Fan speed: fan(value), fan_low(), fan_medium(), fan_high(), fan_auto()
  • Swing: swing(value), swing_on(), swing_off()
  • Timer: operation_time(seconds), timer(seconds)
  • Execute: do()

Notes:

  • The fluent API accepts Python enums (from e7_switcher.enums), strings (e.g., "cool", "FAN_HIGH"), integers, and booleans where applicable.
  • The Python enums are converted internally to the native _core enums for the underlying call, so you can use the Pythonic API without worrying about low-level details.

Examples

The library includes examples for both ESP32 desktop and Python platforms:

ESP32 Example

A simple example showing how to connect to WiFi and control Switcher devices from an ESP32.

cd examples/esp32_example
pio run -t upload

Desktop Example

A command-line example for controlling devices from desktop platforms.

cd examples/desktop_example
pio run
# Or with CMake:
mkdir build && cd build
cmake .. -DBUILD_EXAMPLES=ON
make
./e7-switcher-desktop-example status  # Get device status
./e7-switcher-desktop-example on      # Turn device on
./e7-switcher-desktop-example off     # Turn device off

Python Example

A Python example for controlling devices using the Python bindings:

python python/examples/example_usage.py --account your_account --password your_password list
python python/examples/example_usage.py --account your_account --password your_password switch-status --device "Your Switch Name"
python python/examples/example_usage.py --account your_account --password your_password ac-on --device "Your AC Name" --mode cool --temp 22 --fan medium --swing on
python python/examples/example_usage.py --account your_account --password your_password boiler-status --device "Your Boiler Name"
python python/examples/example_usage.py --account your_account --password your_password boiler-on --device "Your Boiler Name" --time 30
python python/examples/example_usage.py --account your_account --password your_password boiler-off --device "Your Boiler Name"

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

Project details


Download files

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

Source Distribution

e7_switcher-1.0.8.tar.gz (50.4 kB view details)

Uploaded Source

Built Distributions

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

e7_switcher-1.0.8-cp313-cp313-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.13Windows x86-64

e7_switcher-1.0.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

e7_switcher-1.0.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

e7_switcher-1.0.8-cp313-cp313-macosx_14_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

e7_switcher-1.0.8-cp312-cp312-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.12Windows x86-64

e7_switcher-1.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

e7_switcher-1.0.8-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

e7_switcher-1.0.8-cp312-cp312-macosx_14_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

e7_switcher-1.0.8-cp311-cp311-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.11Windows x86-64

e7_switcher-1.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

e7_switcher-1.0.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

e7_switcher-1.0.8-cp311-cp311-macosx_14_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file e7_switcher-1.0.8.tar.gz.

File metadata

  • Download URL: e7_switcher-1.0.8.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for e7_switcher-1.0.8.tar.gz
Algorithm Hash digest
SHA256 9b908c6f9fe0285a5f552839f2ea8f04ea11716b85870d43dcb2bdde9f2be0ca
MD5 d1473d93a163cfd910f153934b44cdcf
BLAKE2b-256 e4466d751535322f414a7c510ba0dde01d2acd4c755ddc635a039e9242080ad1

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7754c5a1324501e746b0fdf3e23f64965172cab1f9feae5c92bfc22525015cd3
MD5 a7b8265e3df2946875c13f247ffa1a44
BLAKE2b-256 51465d57b0e7103cc5fa903b1a61a6c4394e70852235c8f2e2d7b46bea20b74d

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eaea135d05befde479a91525cd6a3ee44db4f0d38ae6438cee630490bf12b59e
MD5 f12f21b70159de86ffa144dc5c861f39
BLAKE2b-256 1288db571eb1fdda3410a2ad35e185d8daf8c66036cda3300bcc11b4a9a3bc0f

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 40b03ac24ebdcfe128e4296220dcc5d81cfb687140ec4a7df8b440fc6d62da01
MD5 3da69136db45d9aa7ceb7295e5f123f5
BLAKE2b-256 a6d4008e8e610a08b6aef7614eef374f8de133f669082e802651a487362bbf1b

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 571253a7c54039ef4386ca015e0ce71621d7ba2da7a471df569e25bd70d569fb
MD5 b5dd1f30f4d050a3229ec0edfd6803cb
BLAKE2b-256 33c07f4f59a6f76bf5455d6868ecc72d2df9cefb2987644bb8ed1d6b7bb50289

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 89ceb1e4d226dbd8a9aabbe1ee0d4d950b0a5b42f244d9a926091db2241576c4
MD5 a10ca48eadbaee04969b0314c3b21c16
BLAKE2b-256 099c656349da99a4d9e46ea4c86d0dc71ca457c945eda26d12709b675891e822

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29a3eb6d427816ef07e994850b94c7ee7d504df923cd129daffca3a34c232d12
MD5 307f4f118f47e634b26798c0af0b7c86
BLAKE2b-256 66ce44ade27d1c9ef2869d2621c1e7a93eef719af0b118b351b2f4acee722d05

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 166d5da52d8794f1b210c2ebc0bc794f3a9ec1a7e06e614dcb6713184fce6400
MD5 83449c0988fac32fa5ac463e912cb879
BLAKE2b-256 4daf742dd51b945ff260b076d42ab3957e2e166288ece1e4787c0cd697c96d54

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 60624a569e4880f1dfd92f51a1672f99fe4effd1a6fb52e1737f0199ea808eb8
MD5 b2b4399bc79cec6da66756b19802d2ee
BLAKE2b-256 a78ea94335fc5216f6ab9d5cafc6a45d9a1717d41118221c53ef0b15ea845750

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 82c881d69fd9ed501af4898d7968c81484dfba2e0aa74d56602bb77d2c21ac23
MD5 7e2140032c3d0fb966d06ff817763a5e
BLAKE2b-256 24cf047e52e719f3a372aa77ceef70d2990d5dd35f04aed202051a61dac12cbb

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb27bf5c3197af710df495120728e6cb70b95e0aeafd1598a2641d865e2a56a1
MD5 79331d759e73b6b4173e5697e7d8cb93
BLAKE2b-256 6da8a1e11d14c0746e968d5773b5d68fa0bbb3a5fe6c1416ab53731db2bff789

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 78dc45fdc4cbff09ecebedfc346f22a820dc9f212044744463ad361d1b2bcb2e
MD5 1a1cd7b8a83a5ee9309e1faa5240a817
BLAKE2b-256 c833d9007ec2ab62a7a9b1440631679c58e80e4f1701c10ca73cc3af466ae1c3

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.8-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.8-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dd7923264df02f3c5b5230d9c16047ec1a8f9c7f3a8f0014c564114f80ed318b
MD5 6dac6261073d1fbe744174370754c01c
BLAKE2b-256 ebc804e99ef26ff06935b88355358af9db151baa9e7adfddefee023e6ffb6caf

See more details on using hashes here.

Supported by

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