Etekcity and VeSync

Are any of you seeing accurate wattage values as compared to the VeSync app? I have nine of these and none are close to accurate in hassio. It really shows up when I use one on my 110v gas clothes dryer. It shows around 13 watts (running and not running) while the Vesync app shows it is over 500 watts when the dryer is running and <1 watt when the dryer is off.

Can anyone shed some light on this?

I’m just starting to look into this as I want to see about shutting off the switch when my phone is done charging. My plan was to use the power draw when it goes from Hi to Lo, but it’s only reporting about 1.5W in HASS, but 21W in the VeSync app.

This doesn’t actually show the current wattage. It shows the daily consumption divided by the hours. I looked at the library PyVesync and this is the function for calculating current wattage:

def calculate_watts(self, kwh, minutes):
        """Return current watt usage of a device"""

        try:
            watts = (kwh * 60 * 1000) / minutes
        except ZeroDivisionError:
            return None
        except Exception as e:
            logger.error('Unable to calculate watts')
            return None
        else:
return watts

It turns out the current wattage returned by the api is in hex format. I found a rough conversion factor and made a few changes to the script. I submitted it for a pull request and haven’t done much more with it. Let me know if you have any suggestions

Modified PyVesync

1 Like

Too bad this appears to have stalled since you submitted the PR back in August. I suppose we could manually update the pyvesync.py in our HA instances to take advantage of your updates?

That is an option although its not ideal. Another option is to take the VeSync Switch Component and create a custom component with a reference to the function below and do the math in the custom component file. I’ve been distracted with other things lately but I was hoping to get it working over the holiday. Let me know if you make any progress

def call_api(self, api, method, json=None, headers=None):
        response = None

        try:
            logger.debug("[%s] calling '%s' api" % (method, api))
            if method == 'get':
                r = requests.get(API_BASE_URL + api, json=json, headers=headers, timeout=API_TIMEOUT)
            elif method == 'post':
                r = requests.post(API_BASE_URL + api, json=json, headers=headers, timeout=API_TIMEOUT)
            elif method == 'put':
                r = requests.put(API_BASE_URL + api, json=json, headers=headers, timeout=API_TIMEOUT)
        except requests.exceptions.RequestException as e:
            logger.error(e)
        except Exception as e:
            logger.error(e)
        else:
            if r.status_code == 200:
                response = r.json()
        finally:
return response

@homefire - it seems that the VeSync component does not work with the latest plug by Etekcity / VeSync (https://www.amazon.com/dp/B07GDFQ38D). Did you notice that in your testing when you were building this out?

does anyone get vesync component working with their light outlet?
it did not work for me :frowning:

https://www.amazon.com/Etekcity-Wireless-Required-Installation-Warranty/dp/B07DZY5JYT/ref=asc_df_B07DZY5JYT/?tag=hyprod-20&linkCode=df0&hvadid=242022044358&hvpos=1o1&hvnetw=g&hvrand=1250271209637246560&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9030091&hvtargid=pla-531051781147&psc=1

I dropped this:

https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/switch/vesync.py

into: /config/custom_components/switch/vesync.py

(create the custom_components folder if it doesn’t exist)

Then I dropped:

into: /config/custom_components/vesync.py

FInally, I edited /config/custom_components/switch/vesync.py and changed:

from pyvesync.vesync import VeSync

to:

from custom_components.vesync import VeSync

and the watts reading should work great after that. Our washing machine now notifies me when it’s done of a load! lol

Thanks a lot for this code @ homefire - you rock!

3 Likes

I have a mix of the older round, and the newer rectangle outlets.
The newer outlets are not reported as devices in the existing python libraries, looks like vesync changed their api for the new devices.

The new devices are returned if you call /platform/v1/app/devices
for the get devices function. The format of the returned json is different. All the devices are returned in the new api, so hopefully someone can figure it out.

There are sites online that will decompile the veSync APK file. Looks like the new api calls are defined here: com.etekcity.vesyncplatform-v2.4.7_source_from_JADX\sources\com\etekcity\vesyncplatform\data\service\DeviceService.java

I haven’t had any luck figuring it out. Maybe if someone can catch the traffic that the app is sending, someone could write a new library that uses the newer API.

Thank you for spelling out in detail how to do this! I’m now getting correct current wattage. :grinning:

Question: It generally takes as long as 22 seconds for the state (off and on) to update within HA. I’m seeing roughly the same times to update the current wattage.

Do you know of any way to force HA to decrease the scan_interval for this component? Or is there something else at play here. I notice the vesync app updates the state and wattage significantly quicker if I manually turn off the switch for example.

And thank you @homefire

I am in the same boat as you. I decompiled the APK and spent days pouring through it, but could not figure out the API to turn the new plugs off and on. I can get the device list and a couple of other things, but cannot interact with them unfortunately.

I love a challenge. I just bought one of them, I will keep you updated if I make any progress

Edit: Finally figured out the new API. I’m working on rebuilding the library now. Should have it out in a few days (hopefully).

1 Like

awesome! I’m not an home assistant user, but I’m curious to see what the API looks like.

Finally got this to work with the new outlets, check it out in this post:

2 Likes

@homefire Thanks to you I have vesync showing up in my entities.
I can see the current power in watts and Kwh when I select the switch entity.
How to get the current power in watts and Kwh to display in a card in the UI?

[SOLVED] I researched and found you can create sensor templates from an entities attributes. So I now have 2 sensors entities one for instant power and the other for Kwh’s. I still have something incorrect in my configuration file, but I’m close.

Are you still having this problem @vkeiper?

You can create a sensor template that reads the value from the switch attributes. I updated the documentation in a PR but until it is merged you can reference this and just use the vesync entities and attributes: