GithubHelp home page GithubHelp logo

webdjoe / pyvesync_v2 Goto Github PK

View Code? Open in Web Editor NEW
30.0 5.0 17.0 116 KB

Python Library for controlling vesync API for all etekcity smart outlets, switches and bulbs and Levoit Air Purifier

License: MIT License

Python 100.00%
iot versync smart home etekcity smart-outlets air-purifier levoit smart-bulb smart-switch

pyvesync_v2's Introduction

pyvesync_v2

Python 3.5+ https://img.shields.io/azure-devops/build/webdjoe/c13ec6f6-2149-46a0-95ba-98bdd60eed28/1 codecov PYPI

pyvesync_v2 is a library to manage VeSync compatible smart home devices

This library is depreciated - Please see PyVesync

Only compatible with python 3.5+

Table of Contents

Installation

Install the latest version from pip:

pip install pyvesync_v2

Supported Devices

  1. Etekcity Voltson Smart WiFi Outlet (7A model ESW01-USA)
  2. Etekcity Voltson Smart WiFi Outlet (10A model ESW01-EU)
  3. Etekcity Voltson Smart Wifi Outlet (10A model ESW03-USA)
  4. Etekcity Voltson Smart WiFi Outlet (15A model ESW15-USA)
  5. Etekcity Two Plug Outdoor Outlet (ESO15-TB) (Each plug is a separate object, energy readings are for both plugs combined)
  6. Etekcity Smart WiFi Light Switch (model ESWL01)
  7. Levoit Smart Wifi Air Purifier (LV-PUR131S)
  8. Etekcity Soft White Dimmable Smart Bulb (ESL100)
  9. Etekcity Cool to Soft White Tunable Dimmable Bulb (ESL100CW)
  10. Etekcity Wifi Dimmer Switch (ESD16)

Usage

To start with the module:

from pyvesync_v2 import VeSync

manager = VeSync("EMAIL", "PASSWORD", time_zone=DEFAULT_TZ)
manager.login()

# Get/Update Devices from server - populate device lists
manager.update()

my_switch = manager.outlets[0]
# Turn on the first switch
my_switch.turn_on()
# Turn off the first switch
my_switch.turn_off()

# Get energy usage data
manager.update_energy()

# Display outlet device information
for device in manager.outlets:
    device.display()

Configuration

The time_zone argument is optional but the specified time zone must match time zone in the tz database (IANNA Time Zone Database), see this link for reference: tz database. The time zone determines how the energy history is generated for the smart outlets, i.e. for the week starts at 12:01AM Sunday morning at the specified time zone. If no time zone or an invalid time zone is entered the default is America/New_York

#Devices are respectively located in their own lists that can be iterated over
manager.outlets = [VeSyncOutletObjects]
manager.switches = [VeSyncSwitchObjects]
manager.fans = [VeSyncFanObjects]
manger.bulbs = [VeSyncBulbObjects]

If outlets are going to be continuously polled, a custom energy update interval can be set - The default is 6 hours (21600 seconds)

manager.energy_update_interval = time # time in seconds

Example Usage

Get electricity metrics of outlets

for s in manager.outlets:
  s.update_energy(check_bypass=False) # Get energy history for each device

API Details

Manager API

VeSync.get_devices() - Returns a list of devices

VeSync.login() - Uses class username and password to login to VeSync

VeSync.update() - Fetch updated information about devices

VeSync.update_all_devices() - Fetch details for all devices (run VeSyncDevice.update())

VeSync.update_energy(bypass_check=False) - Get energy history for all outlets - Builds week, month and year nested energy dictionary. Set bypass_check=True to disable the library from checking the update interval

Device API

VeSyncDevice.turn_on() - Turn on the device

VeSyncDevice.turn_off() - Turn off the device

VeSyncDevice.update() - Fetch updated information about device

VeSyncDevice.active_time - Return active time of the device in minutes

VeSyncDevice.get_config() - Retrieve Configuration data such as firmware version for device and store in the VeSyncDevice.config dictionary

VeSyncDevice.firmware_update - Return true if Firmware has update available. VeSyncDevice.get_config() must be called first

Outlet Specific Energy Methods and Properties

VeSyncOutlet.update_energy(bypass_check=False) - Get outlet energy history - Builds week, month and year nested energy dictionary. Set bypass_check=True to disable the library from checking the update interval

VeSyncOutlet.energy_today - Return current energy usage in kWh

VeSyncOutlet.power - Return current power in watts of the device

VeSyncOutlet.voltage - Return current voltage reading

VesyncOutlet.weekly_energy_total - Return total energy reading for the past week in kWh, starts 12:01AM Sunday morning

VesyncOutlet.monthly_energy_total - Return total energy reading for the past month in kWh

VesyncOutlet.yearly_energy_total - Return total energy reading for the past year in kWh

Model ESW15-USA 15A/1800W Methods

The rectangular smart switch model supports some additional functionality on top of the regular api call

VeSyncOutlet.turn_on_nightlight() - Turn on the nightlight

VeSyncOutlet.turn_off_nightlight() - Turn off the nightlight

Air Purifier LV-PUR131S Methods

VeSyncFan.fan_level - Return the level of the fan (1-3) or 0 for off

VeSyncFan.filter_life - Return the percentage of filter life remaining

VeSyncFan.air_quality - Return air quality reading

VeSyncFan.auto_mode() - Change mode to auto

VeSyncFan.manual_mode() - Change fan mode to manual with fan level 1

VeSyncFan.sleep_mode() - Change fan mode to sleep

VeSyncFan.change_fan_speed(speed) - Change fan speed with level 1, 2 or 3

VeSyncFan.screen_status - Get Status of screen on/off

VesyncFan.display_on() - Turn Display on

VesyncFan.display_off() - Turn Display off

Dimmable Smart Light Bulb Method and Properties

VeSyncBulb.brightness - Return brightness in percentage (1 - 100)

VeSyncBulb.set_brightness(brightness) - Set bulb brightness values from 1 - 100

Tunable Smart Light Bulb Methods and Properties

VeSyncBulb.color_temp_pct - Return color temperature in percentage (0 - 100)

VeSyncBulb.color_temp_kelvin - Return brightness in Kelvin

VeSyncBulb.set_color_temp(color_temp) - Set color temperature in percentage (0 - 100)

Dimmable Switch Methods and Properties

VeSyncSwitch.brightness - Return brightness of switch in percentage (1 - 100)

VeSyncSwitch.indicator_light_status - return status of indicator light on switch

VeSyncSwitch.rgb_light_status - return status of rgb light on faceplate

VeSyncSwitch.rgb_light_value - return dictionary of rgb light color (0 - 255)

VeSyncSwitch.set_brightness(brightness) - Set brightness of switch (1 - 100)

VeSyncSwitch.indicator_light_on() - Turn indicator light on

VeSyncSwitch.indicator_light_off() - Turn indicator light off

VeSyncSwitch.rgb_color_on() - Turn rgb light on

VeSyncSwitch.rgb_color_off() - Turn rgb light off

VeSyncSwitch.rgb_color_set(red, green, blue) - Set color of rgb light (0 - 255)

JSON Output API

The device.display_json() method outputs properties and status of the device

JSON Output for All Devices

device.display_json()

#Returns:

{
  'Device Name': 'Device 1',
  'Model': 'Device Model',
  'Subdevice No': '1',
  'Status': 'on',
  'Online': 'online',
  'Type': 'Device Type',
  'CID': 'DEVICE-CID'
}

JSON Output for Outlets

{
  'Active Time': '1', # in minutes
  'Energy': '2.4', # today's energy in kWh
  'Power': '12', # current power in W
  'Voltage': '120', # current voltage
  'Energy Week': '12', # totaly energy of week in kWh
  'Energy Month': '50', # total energy of month in kWh
  'Energy Year': '89', # total energy of year in kWh
  'Nightlight Status': 'on', #status of nightlight for 15A outlets
  'Nightlight Automode': 'manual', #auto/manual for 15A outlets
  'Nightlight Brightness': '50' #brightness of nightlight
}

JSON Output for Dimmable Switch

This output only applies to dimmable switch. The standard switch has the default device JSON output shown above

{
  'Indicator Light': 'on', # status of indicator light
  'Brightness': '50', # percent brightness
  'RGB Light': 'on' # status of RGB Light on faceplate
}

JSON Output for Bulbs

# output for dimmable bulb
{
  'Brightness': '50' # brightness in percent
}

# output for tunable bulb
{
  'Kelvin': '5400' # color temperature in Kelvin
}

JSON Output for Air Purifier

{
  'Active Time': '50', # minutes
  'Fan Level': '2', # fan level 1-3
  'Air Quality': '95', # air quality in percent
  'Mode': 'auto',
  'Screen Status': 'on',
  'Filter Life': '99' # remaining filter life in percent
}

Energy History Data

More detailed data is available within the VesyncOutlet by inspecting the VesyncOutlet.energy dictionary.

The VesyncOutlet.energy object includes 3 nested dictionaries week, month, and year that contain detailed weekly, monthly and yearly data

VesyncOutlet.energy['week']['energy_consumption_of_today']
VesyncOutlet.energy['week']['cost_per_kwh']
VesyncOutlet.energy['week']['max_energy']
VesyncOutlet.energy['week']['total_energy']
VesyncOutlet.energy['week']['data'] # which itself is a list of values

Development

Running Tests

Test can be run with tox for python 3.5, 3.6 and 3.7. It will also run pylint and flake8 to test for style and formatting.

Run all tests:

$ tox
# Tests for python3.5, 3.6, 3.7, pylint and flake8 succeeded

Individual tests can be run with the -e flag:

$ tox -e py35
# Tests for Python 3.5 succeeded

pyvesync_v2's People

Contributors

webdjoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyvesync_v2's Issues

Add support for ESW01-USA (10A Model)

This library finds my old-revision ESW01-USA switches just fine (7A), but the new 10A models (which appear to have the same model number?) are not showing up...

cannot import name 'VeSync'

I installed the V2 version, but can't get it to work. I have tried it under python 2.7 and python3, and on at least two x86_64 PCs running Debian and Ubuntu.

charting@onyx2:$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
...
charting@onyx2:
/hello$ pip3 install pyvesync_v2
Collecting pyvesync_v2
Downloading https://files.pythonhosted.org/packages/cb/85/bf79d5000d4a7e9c50fad71d598ec21d06f3623b30a2134542cd514ba8fa/pyvesync_v2-0.9.9-py2.py3-none-any.whl
Collecting requests>=2.20.0 (from pyvesync_v2)
Using cached https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl
Collecting tzlocal (from pyvesync_v2)
Downloading https://files.pythonhosted.org/packages/ef/99/53bd1ac9349262f59c1c421d8fcc2559ae8a5eeffed9202684756b648d33/tzlocal-2.0.0-py2.py3-none-any.whl
Collecting pytz (from pyvesync_v2)
Downloading https://files.pythonhosted.org/packages/87/76/46d697698a143e05f77bec5a526bf4e56a0be61d63425b68f4ba553b51f2/pytz-2019.2-py2.py3-none-any.whl (508kB)
100% |████████████████████████████████| 512kB 1.6MB/s
Collecting certifi>=2017.4.17 (from requests>=2.20.0->pyvesync_v2)
Using cached https://files.pythonhosted.org/packages/18/b0/8146a4f8dd402f60744fa380bc73ca47303cccf8b9190fd16a827281eac2/certifi-2019.9.11-py2.py3-none-any.whl
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests>=2.20.0->pyvesync_v2)
Using cached https://files.pythonhosted.org/packages/81/b7/cef47224900ca67078ed6e2db51342796007433ad38329558f56a15255f5/urllib3-1.25.5-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests>=2.20.0->pyvesync_v2)
Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests>=2.20.0->pyvesync_v2)
Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: certifi, urllib3, idna, chardet, requests, pytz, tzlocal, pyvesync-v2
Successfully installed certifi-2019.9.11 chardet-3.0.4 idna-2.8 pytz-2019.2 pyvesync-v2-0.9.9 requests-2.22.0 tzlocal-2.0.0 urllib3-1.25.5
charting@onyx2:/hello$ /usr/bin/python3 /home/charting/hello/vesync_v2.py
Traceback (most recent call last):
File "/home/charting/hello/vesync_v2.py", line 1, in
from pyvesync_v2 import VeSync
ImportError: cannot import name 'VeSync'
charting@onyx2:
$ python3 /home/charting/hello/vesync_v2.py
Traceback (most recent call last):
File "/home/charting/hello/vesync_v2.py", line 1, in
from pyvesync_v2 import VeSync
ImportError: cannot import name 'VeSync'

===================================
From the command line, I can't import VeSync, but I can import vesync (which doesn't work):

charting@onyx2:~$ python3
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from pyvesync_v2 import VeSync
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'VeSync'
from pyvesync_v2 import vesync
manager = vesync("test", "test", time_zone="America/New_York")
Traceback (most recent call last):
File "", line 1, in
TypeError: 'module' object is not callable

LUH-D301S-WEU

This is a Humidifier (from levoit) i would like to control with this code.
Right now i get a error: WARNING - Unknown device LUH-D301S-WEU

Features:
set humidity in percent
set mode (on/off/auto)
turn display on/off
power on/off
timer
schedule
Auto-Off

I would be able to get the api calls via men in the middle.
I think it's just like the fan, but I wasn't able to just add the device.

Would you be so kind and help me to implement this device into the code?

Air quality in percent

What is the air quality a percentage of? Is there an AQI reading that translates to 100%?

Install on Hassio?

If I wanted to install this on Hassio could I just copy the files from the src folder into the custom components folder on hassio? The air purifier settings I have been using are under the mark perdue pyvesync project but it doesn't support sleep. I wanted to test and see if this fixes it. There is no PIP on hassio that I can tell.

Adding support for airpurifiers

VeSync currently supports air purifiers. As far as I can tell by tracing their app, the API is very similar to the one used for switches (in fact, using call_api from pyvesync I was able to talk to my purifier with some small updates to json payload). If that is something of interest, I may contribute my code, although the project would then evolve beyond switches :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.