Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TomerFi/aioswitcher
PyPi module integrating with various Switcher devices
https://github.com/TomerFi/aioswitcher
home-automation pypi-package smart-switch smarthome
Last synced: 2 months ago
JSON representation
PyPi module integrating with various Switcher devices
- Host: GitHub
- URL: https://github.com/TomerFi/aioswitcher
- Owner: TomerFi
- License: apache-2.0
- Created: 2019-02-05T14:50:23.000Z (almost 6 years ago)
- Default Branch: dev
- Last Pushed: 2024-10-29T13:23:29.000Z (3 months ago)
- Last Synced: 2024-10-29T15:33:56.400Z (3 months ago)
- Topics: home-automation, pypi-package, smart-switch, smarthome
- Language: Python
- Homepage: https://aioswitcher.tomfi.info
- Size: 6.38 MB
- Stars: 28
- Watchers: 3
- Forks: 18
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-opensource-israel - aioswitcher - PyPi module integrating with various Switcher smart devices. (Projects by main language / python)
README
# Switcher Python Integration[![pypi-version]][11] [![pypi-downloads]][11] [![license-badge]][4]
[![gh-build-status]][7] [![gh-pages-status]][8] [![codecov]][3]
PyPi module integrating with various [Switcher][12] devices.
Check out the [wiki pages][0] for a list of supported devices.```shell
pip install aioswitcher
```Documentation
Wiki
Contributing## Example Usage
State Bridge
```python
async def print_devices(delay):
def on_device_found_callback(device):
# a switcher device will broadcast a state message approximately every 4 seconds
print(asdict(device))async with SwitcherBridge(on_device_found_callback):
await asyncio.sleep(delay)# run the bridge for 60 seconds
asyncio.run(print_devices(60))
```Power Plug API
```python
async def control_power_plug(device_type, device_ip, device_id, device_key) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
# get the device current state
await api.get_state()
# turn the device on
await api.control_device(Command.ON)
# turn the device off
await api.control_device(Command.OFF)
# set the device name to 'my new name'
await api.set_device_name("my new name")asyncio.run(control_power_plug(DeviceType.POWER_PLUG, "111.222.11.22", "ab1c2d", "00"))
```Water Heater API
```python
async def control_water_heater(device_type, device_ip, device_id, device_key) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType1Api(device_type, device_ip, device_id, device_key) as api:
# get the device current state
await api.get_state()
# turn the device on for 15 minutes
await api.control_device(Command.ON, 15)
# turn the device off
await api.control_device(Command.OFF)
# set the device name to 'my new name'
await api.set_device_name("my new name")
# configure the device for 02:30 auto shutdown
await api.set_auto_shutdown(timedelta(hours=2, minutes=30))
# get the schedules from the device
await api.get_schedules()
# delete and existing schedule with id 1
await api.delete_schedule("1")
# create a new recurring schedule for 13:00-14:30
# executing on sunday and friday
await api.create_schedule("13:00", "14:30", {Days.SUNDAY, Days.FRIDAY})asyncio.run(control_water_heater(DeviceType.MINI, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.TOUCH, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.V2_ESP, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.V2_QCA, "111.222.11.22", "ab1c2d" , "00"))
asyncio.run(control_water_heater(DeviceType.V4, "111.222.11.22", "ab1c2d" , "00"))
```Runner API
```python
async def control_runner(device_type, device_ip, device_id, device_key, token) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key, token) as api:
# get the shutter current state, circuit number is 0
await api.get_shutter_state(0)
# open the shutter to 30%, circuit number is 0
await api.set_position(30, 0)
# stop the shutter if currently rolling, circuit number is 0
await api.stop_shutter(0)
# turn on the light, circuit number is 0 (Only for Runner S11 and Runner S12)
await api.set_light(DeviceState.ON, 0)
# turn off the light, circuit number is 0 (Only for Runner S11 and Runner S12)
await api.set_light(DeviceState.OFF, 0)asyncio.run(control_runner(DeviceType.RUNNER, "111.222.11.22", "ab1c2d", "00"))
asyncio.run(control_runner(DeviceType.RUNNER_MINI, "111.222.11.22", "ab1c2d", "00"))
asyncio.run(control_runner(DeviceType.RUNNER_S11, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
asyncio.run(control_runner(DeviceType.RUNNER_S12, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
```Breeze API
```python
async def control_breeze(device_type, device_ip, device_id, device_key, remote_manager, remote_id) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key) as api:
# get the device current state
await api.get_breeze_state()
# initialize the Breeze RemoteManager and get the remote
remote = remote_manager.get_remote(remote_id)
# prepare a control command that turns on the Breeze
# set to 24 degree (Celsius) cooling with vertical swing
# send command to the device
await api.control_breeze_device(
remote,
DeviceState.ON,
ThermostatMode.COOL,
24,
ThermostatFanLevel.MEDIUM,
ThermostatSwing.ON,
)# create the remote manager outside the context for re-using
remote_manager = SwitcherBreezeRemoteManager()
asyncio.run(control_breeze(DeviceType.BREEZE, "111.222.11.22", "ab1c2d", "00", remote_manager, "DLK65863"))
```Light API
```python
async def control_light(device_type, device_ip, device_id, device_key, token) :
# for connecting to a device we need its type, id, login key and ip address
async with SwitcherType2Api(device_type, device_ip, device_id, device_key, token) as api:
# get the light current state, circuit number is 0
await api.get_light_state(0)
# turn on the light, circuit number is 0 (Only for Runner S11, Runner S12 and Lights)
await api.set_light(DeviceState.ON, 0)
# turn off the light, circuit number is 0 (Only for Runner S11, Runner S12 and Lights)
await api.set_light(DeviceState.OFF, 0)asyncio.run(control_light(DeviceType.LIGHT_SL01, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
asyncio.run(control_light(DeviceType.LIGHT_SL01_MINI, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
asyncio.run(control_light(DeviceType.LIGHT_SL02, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
asyncio.run(control_light(DeviceType.LIGHT_SL02_MINI, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
asyncio.run(control_light(DeviceType.LIGHT_SL03, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
```## Command Line Helper Scripts
- [discover_devices.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/discover_devices.py) can discover devices and their states (can be run by `poetry run discover_devices`).
- [control_device.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/control_device.py) can control a device (can be run by `poetry run control_device`).
- [get_device_login_key.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/get_device_login_key) can get a device login key (can be run by `poetry run get_device_login_key`).
- [validate_token.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/validate_token.py) can validate a device token which is a must for newer devices, used for communicating with devices (can be run by `poetry run validate_token`).## Disclaimer
This is **NOT** an official module and it is **NOT** officially supported by the vendor.
That said, thanks are in order to all the people at [Switcher][12] for their cooperation and general support.## Contributors [![all-contributors]][2]
Thanks goes to these wonderful people ([emoji key][1]):
Aviad Golan
🔣
Dolev Ben Aharon
📖
Fabian Affolter
💻
Itzik Ephraim
💻
Kesav890
📖
Liad Avraham
💻
Marc Mueller
💻
Or Bin
💻
Roeeeee
💻
Shai rod
🔣
Shay Levy
💻 🤔 🚧
YogevBokobza
💻 ⚠️ 🚧
Yuval Moran
💻 ⚠️
ayal
🐛 💻
dmatik
📝 🤔 📓
epenet
🐛 💻
jafar-atili
💻 📖
[0]: https://github.com/TomerFi/aioswitcher/wiki
[1]: https://allcontributors.org/docs/en/emoji-key
[2]: https://allcontributors.org
[3]: https://codecov.io/gh/TomerFi/aioswitcher
[4]: https://github.com/TomerFi/aioswitcher
[7]: https://github.com/TomerFi/aioswitcher/actions/workflows/stage.yml
[8]: https://aioswitcher.tomfi.info/
[11]: https://pypi.org/project/aioswitcher
[12]: https://www.switcher.co.il/[all-contributors]: https://img.shields.io/github/all-contributors/tomerfi/aioswitcher?color=ee8449&style=flat-square
[codecov]: https://codecov.io/gh/TomerFi/aioswitcher/graph/badge.svg
[gh-build-status]: https://github.com/TomerFi/aioswitcher/actions/workflows/stage.yml/badge.svg
[gh-pages-status]: https://github.com/TomerFi/aioswitcher/actions/workflows/pages.yml/badge.svg
[license-badge]: https://img.shields.io/github/license/tomerfi/aioswitcher
[pypi-downloads]: https://img.shields.io/pypi/dm/aioswitcher.svg?logo=pypi&color=1082C2
[pypi-version]: https://img.shields.io/pypi/v/aioswitcher?logo=pypi