Open erwin opened 2 years ago
There is some calculations made in cloud, with is made to show in app. Amp*Volt=Watt with you see locally. But for kWh you need array of data containing W for per time, ~30 sec interval for 1 hour. Smart plugs don't have dedicated chip as some Wattmeter's to see it locally as on ZMAi-90, or similar.
If anyone else is using the Smart Socket 2 on their network, and noticed that it's EXTREMELY unstable (like constantly disconnects from network) and frequently doesn't respond, I've found that using the Reconnect
feature in my Unifi Controller, the device comes back online 99% of the time.
Currently I have a cron job running every 2 minutes that just checks if the device is responding to icmp (ping) requests. If it is, then everything should be fine. If it's not responding, then use the network's disconnect function.
You can use the Python unificontrol library to automatically do this reconnect.
client = UnifiClient(host="unifi.localdomain",
username=UNIFI_USER, password=UNIFI_PASSWORD, site=UNIFI_SITE)
client.reconnect_client('MAC ADDRESS')
Lately I've been connecting my computer via wifi instead of ethernet, and it seems to make the Smart Plug located next to my computer disconnect even more frequently. Hopefully I'll soon move back to ethernet and hopefully the device will stop disconnecting so frequently.
If it does continue to disconnect frequently, I'll probably make a toggle state
script that combines the above ping / reconnect with the nodejs tuya-cli to check the status and set the status.
Something like:
# Get the current Status
tuya-cli get --dps 1 --id xxx --key xxx --ip xxx --protocol-version 3.3
# Turn Power On
tuya-cli set --dps 1 --set true --id xxx --key xxx --ip xxx --protocol-version 3.3
# Turn Power Off
tuya-cli set --dps 1 --set false --id xxx --key xxx --ip xxx --protocol-version 3.3
It took me a little while to get what tuya-cli reports as
SMART socket 2
working with tuya-local.In my case, when using TuyaDebug,
I got the following DPS:
``` DeviceIf you're unable to connect, it's usually that the IP, Device ID or Local Key isn't right. Sometimes while setting up a device, I've had to reset the Local Key multiple times to get it right. I actually like the method of just using the iot.tuya.com website and the tuya app better than tuya-cli for the
SMART plug 2
because there are some stats stored in the other DPS and accessing directly via the Tuya App will make it easier to verify configuration for those in the future.Here's the configuration that got my
SMART socket 2
working:I wrote
<Which One>
here because you want give each of these a unique name... Maybe it's "Living Room TV" or "Office Monitor" or "Coffee Maker"...DP9, and DP22-26 have values, but I'm not sure of the format. Looking at what's shown in the Tuya App, I think these values may be a running total of electricity usage, but that's just a guess.
Here's what I've got in the Tuya App:
Here's what shows up for me now in Home Assistant with the config above:
The rounding of numbers is a little bit different on each value, but for my use this is close enough.
The
Office Display Total
when shown in HA is currently too small a value,0.15
so I think HA is rounding that down to 0... I'm not sure though. May be that I need to configure DP21 differently.And as I mentioned before, the totals aren't showing up.
Overall works pretty good though. Already for me it's even more functionality than I was hoping for.