Investigate and fix vesync.py to work with new VeSync / Etekcity outlets

The newest model of the VeSync / Etekcity outlets (https://www.amazon.com/dp/B07J5B2ZR8) don’t work with Home Assistant. The old ones work fine, but the latest release does not even show up. Some changes to the API may be needed? Would be nice to get this fixed!

note: I found the API to list the new devices in the source code for the android APK, but I cannot interact with them. This works to list the devices:

curl -d '{"accountID":"xxxxx", "token":"xxxxxxxxxx"}' -H "Content-Type: application/json" -X POST https://smartapi.vesync.com:443/platform/v1/app/devices/

Any luck with this?
I’ve been digging through the APK for ideas, but I haven’t been able to figure anything out.
@PUT(“https://smartapi.vesync.com/{deviceType}/v1/device/devicestatus”)
@PUT(“https://smartapi.vesync.com/v1/{deviceType}/{cid}/status/{status}”)

Not yet, no. Still trying to figure it out. I will check github later today to see if anyone has updated code.

@homefire says he was able to figure out what is going on with the new API and will update the libraries to use it.

Thanks for figuring this out!
I’m not using it for home assistant, i’m using it to import power usage into telegraf/influxDB/Grafana and it works great! Updated my script and the new outlet data showed right up!

Finally finished integrating the changes. Created a new library in hopes HA will integrate it automatically without having to use a custom component.

I’ve uploaded the package to pypi so it can be installed using pip but I haven’t made a pull request to change the HA config in case there are any more changes. I’m new at this so is there anything else I need to do to get it permanently incorporated into home assistant give me a shout.

I’m guessing they changed the API around to support more data collection and streamline the programming for future devices. The old api still works but doesn’t support the newer devices. I made the appropriate corrections for the primary functions, including daily energy usage but I haven’t yet fixed the historical data for yearly, monthly or weekly power usage.

In order to use this with home assistant now you can use the method laid out by @mahodder in his post Etekcity and VeSync :

1st- Move “vesync.py” file from the “src” directory to the “~config/custom_components” folder in your home assistant configuration directory

https://github.com/webdjoe/pyvesync-v2/blob/master/src/pyvesync-v2/vesync.py

2nd- Then move the sample home assistant component file (HACustom_Components/switch/vesync.py) to the “~config/custom_components/switch” folder in your home assistant configuration directory

https://github.com/webdjoe/pyvesync-v2/blob/master/HACustom_Components/switch/vesync.py

Hopefully this helps someone. I will post the packets I logged in the docs folder of the repository tomorrow in case anyone has any suggestions or changes. Thanks to Mark Perdue for his hard work to create the basis of the code.

2 Likes

Hi @homefire

I’m trying to make it work your changes into my Hassio without luck.

I have both files in:

/config/custom_components/vesync.py (18KB file)
/config/custom_components/switch/vesync.py (4KB file)

But I have this in the log:

   2019-03-05 17:31:43 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.vesync.switch. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/loader.py", line 147, in _load_file
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 962, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.vesync.switch'; 'custom_components.vesync' is not a package
2019-03-05 17:31:43 INFO (MainThread) [homeassistant.loader] Loaded switch.vesync from custom_components.switch.vesync

What am I doing wrong?

Thanks in advance

Do me a favor, include the latest custom component on my github without changing any lines and remove both vesync.py files. Include the the latest file below in

~/config/custom_components/vesync/switch.py

:

https://github.com/webdjoe/pyvesync_v2/blob/master/HACustom_Components/vesync/switch.py

I am running on a virtual environment, and I realized that it automatically installs the pip package in the requirements line. I’m not sure if it does the same on hassio but I don’t see why it wouldn’t.

I apologize for having to change the repo name but I made a stupid error when naming the package by including a “-”. The files on there should work now. The pull request with HA has been approved already so it should be included in the next distribution.

Now It works, no errors

2019-03-05 20:16:40 INFO (MainThread) [homeassistant.components.switch] Setting up switch.vesync
2019-03-05 20:16:42 INFO (SyncWorker_14) [homeassistant.components.switch.vesync] No VeSync devices found

As you can see, Home Assistant can´t see any device, quite strange because in the Vesync App appear two devices.

Do I need something special in my switch.yaml?. Actually I have this:

  # Etekcity
  - platform: vesync
    username: [email protected]
    password: PasswordVesync

The devices that I have are this ones: ETEKCITY ESW01-EU
https://www.amazon.es/ETEKCITY-Inteligente-Programable-Interruptor-Temporizador/dp/B07FMYTDC8/ref=pd_rhf_ee_p_img_2?_encoding=UTF8&psc=1&refRID=YNAMMN8HB45X1VMSM0YG

Thank you very much for you support

Oops, me being a selfish American I forgot about the rest of the world :cowboy_hat_face:.

I am going to try to adjust the library to include the EU suffix, but I have no way of testing the API responses from here. Are you running the vesync app on an android device or ios?

1 Like

Ha ha.

I have an Android device actually

I will PM you in a few minutes

@homefire your code is working pretty nice for my EU plugs, thanks a lot. You are a genius

The device is totally functional, HA receives the states and W

Do you tink will be an update in home assistant to include this new devices?

Best regards

I will upload new pypi package tonight and submit the pull request to HA. Usually takes up to 2 weeks depending on the timing of the releases.

Sorry for the delay, I updated everything so all that you need to do for full VeSync support is to add this custom component to ~/config/custom_components/vesync/switch.py. No other files need to be moved, it will automatically install dependencies until HA incorporates my PR.

https://github.com/webdjoe/pyvesync_v2/blob/master/HACustom_Components/vesync/switch.py

3 Likes

Just wanted to stop by and say thank you @homefire! I’ve been struggling with the same issue and this fixed it for me! You rock!

I’m having issues getting my plugs recognized. When Home Assistant starts up, it looks like it’s loading VeSync and logging in with my VeSync credentials correctly based on the logs.

I get the “No VeSync devices found” log line near the end of setup. I don’t know if the API call for the devices is failing or if something else is going on.

For reference, these are the plugs: https://tinyurl.com/y49drxx4

I’m totally new to all of this, so I’d appreciate any help! Let me know any info that would help.

same errors here. verified login and pass to the app but still no devices found even though there is 1 in the android app

Just got a couple of these on amazon and discovered that the pyvesync_v2 library doesn’t ‘support’ them at the moment. Submitting a patch now to support ‘ESW01-USA’ (Not sure why it wasn’t added with ESW01-EU in the first place)

Right now the library that is backing this integration (pyvesync_v2.py) supports a very short list of devices. It’s likely that your device needs to be added to the list of supported devices. If your devices isn’t one of

SUPOUTLETS = ['wifi-switch-1.3', 'ESW15-USA', 'ESW01-EU']

or one of

SUPSWITCHES = ['ESWL01', 'ESWL02']

it probably won’t work until this library is updated. I’ve just submitted a patch to add ESW01-USA to the list of supported outlets as that’s what i’ve got. Another problem is that the model printed on the switch itself may not necessarily be the model reported by the API. I have two switches that are labeled as model ESW01-USA, but the API reports them as ESW03-USA.

EDIT: I’ve just come to the realization that the python module that is backing this component is not being maintained and may not see any further updates.

EDIT: Got it! At the bottom of this page there are instructions for installing and using this more recently updated library. It works with my ESW01-USA outlets, I bet yours will show up too