EZVIZ - Support for smart plugs

Hi. I have a smart plug from EZVIZ (T30) that I’d like to control using my Home Assistant. The official EZVIZ integration only seems to support cameras. Also, the official integration uses the pyezviz Python module, which can be used to access the smart plug.
Here’s an example code using this module:

from pyezviz import client
from time import sleep

email = "[email protected]"
password = "my_password"
ezclient = client.EzvizClient(email, password)
token = ezclient.login()

def find_smart_plug():
    global ezclient
    switches = ezclient.get_switch()
    #Find a device who's serial starts with "Q" (smart plugs)
    #If you have multiple smart plugs, this will return the first one
    #depending on the output of ezclient.get_switch()
    my_plug = next((switches[device] for device in switches.keys() if device.startswith("Q")), None)
    if my_plug == None:
        raise Exception("You do not have an EZVIZ smart plug configured")
    else:
        #my_plug will be a list of 3 dictionaries, we need the one who's "type" key is 14
        #Don't know why exactly 14 though...
        my_plug = next(device for device in my_plug if device["type"] == 14)
        return my_plug

def get_plug_name(plug):
    """ Gets the name of the smart plug. """
    my_devices = ezclient.get_device()
    my_plug_info = next((device for index, device in enumerate(my_devices) if device["deviceSerial"] == plug["deviceSerial"]))
    return my_plug_info["name"]

def get_current_state(plug):
    """ Gets the current state of the smart plug. """
    return plug["enable"]

def set_state(plug, state):
    """ Sets the current state of the smart plug. """
    state = int(state) #Just in case if state is a boolean
    ezclient.switch_status(plug["deviceSerial"], 14, state)

my_plug = find_smart_plug()
plug_serial = my_plug["deviceSerial"]
plug_name = get_plug_name(my_plug)
current_state = ("on" if  get_current_state(my_plug) else "off")
print(f"Found a smart plug called \"{plug_name}\" with serial {plug_serial}, which is currently {current_state}")

set_state(my_plug, 1)
sleep(1)
set_state(my_plug, 0)
sleep(1)
set_state(my_plug, 1)
sleep(1)
set_state(my_plug, 0)

ezclient.close_session()

I know the code is a bit messy, but the pyezviz module was designed for cameras, but still, it can be used to mess with other EZVIZ devices.

I got it working with a little change. Thanks for the code.

Change:

    switches = ezclient.get_switch()

To:

    switches = ezclient._api_get_pagelist(
            page_filter="SWITCH", json_key="SWITCH"
        )

I have the same plug, and can’t connect it to HS, can someone plz explain how can we use this script to control the plug?

3 Likes

This is just python script that uses pyezviz module. I don’t know why there is no direct support of this in HA Ezviz integration since it works without any problems and same python module is used by Ezviz integration in HA.

I managed to make a “go-around” Ezviz smart plugs support for Home Assistant (docker) using mqtt. If anyone is interested, here are the scripts: https://github.com/ordigital/homeassistant-ezviz-plugs

Hi @br0kenpixel
could you explain me how to integrate it in home assistant?

Would you please explain the script installation process ?

I managed to use those power plugs with this:

Thanks, Simone, for the reference … is almost working, but HA only add an entity and no device was discovered, so Lovelace is not available: Plug can be monitored but cannot be actioned. …

Do you know where should be the location of hacs.json file? And files iinside github.workflows folder are needed?

Hi Carlos,
with the integration I posted above you should be able also to control the plug (on/off).

I did it this way:

Good morning, I have the model ezviz t30 10b with the power measurement, but with this integration the power measurement don’t work for me. Thank you.

Hi !

Thanks for sharing ! I’ve downloaded it but when I try to install the integration I get an error " Config flow could not be loaded: {“message”:“Invalid handler specified”}"

Would you know what causes this ?

Thanks

Edit :

Found the issue by looking at the log, and I didn’t install pyezviz
Now it works

Hi Simone77,

I’m new to the community and i thank you all for your support.

I tried the steps in the configuration you described, but at the end of the installation, i find an Ezviz smart plug in the devices, and can add a card to the dashboard, but it is not able to control the plug, instead it only says “Ezviz Smart Plug update”.

I’m affraid that i might have missed someting, could you please help on this issue?

Many thanks in advance