localtuya icon indicating copy to clipboard operation
localtuya copied to clipboard

Support ZMAi-90 Energy Meter

Open sanyatuning opened this issue 3 years ago • 10 comments

based on codetheweb/tuyapi#440 You can add the device as a switch.

Be careful, if you turn off your wifi router with this switch you won't be able to turn it back on. (tip: make a mobile hotspot with the same wifi credentials)

image

image

sanyatuning avatar May 02 '21 10:05 sanyatuning

@rospogrigio can you review this? Thx

sanyatuning avatar Oct 28 '21 05:10 sanyatuning

This code is too specifically tailored on this device. What if someone has standard values coming out from DP 6? You should find a way to have this behavior to be configurable in some way, sorry I don't have a suggestion on how to do this. I really liked the test part you introduced, though. Can you try to make it configurable? Nice job anyway 👍

Edit: sorry, I checked the code again and I saw that you are intercepting the error if you cannot base64decode the data. Still you have hardcoded the "6" value, I would try to make it more general.

rospogrigio avatar Oct 28 '21 12:10 rospogrigio

@rospogrigio Thanks for the review! This DSP looks very special to me. I don't know, how to handle it more generic. This "6" ID can be a constant or could be an array of IDs if you wish. Suggestions are welcome.

sanyatuning avatar Oct 31 '21 17:10 sanyatuning

How do I implement this fix, I have the same meter but I do not see 6A, 6W or 6V?

ha-bnst avatar Jun 05 '22 05:06 ha-bnst

OK I think I have found the best way to make this PR more generic. Instead of selecting the DP as attributes, I would introduce the 3 energy meters as 3 sensors. To make this, I would add the option to select the starting and ending bits when configuring the sensor parameters, obviously using the first and last bits as default (so I would use 0 and -1). @sanyatuning can you try to implement this? Thank you

rospogrigio avatar Jun 06 '22 07:06 rospogrigio

@rospogrigio you can add these as sensors the encoded value is filtered out somewhere, so you cant select it and set the needed bits after that (I tried without the "del" line)

image

sanyatuning avatar Jun 08 '22 19:06 sanyatuning

image

@sanyatuning What device revision you have?

my ZMAi-90 have very different output

python3 -m tinytuya wizard
TinyTuya Setup Wizard [1.1.2]
...
[SPM] - 192.168.1.80 - On - DPS: {'1': True, '17': 78640, '18': 156, '19': 163, '20': 2175}

{
	'1': True,      -- Switch status
	'17': 78640, -- Total KWh (*00.1)
	'18': 156,   -- mA - current (*0.1)
	'19': 163,   -- W  - consumption (*0.1)
	'20': 2175   -- V  - voltage (*0.1)
}

Saentist avatar Jun 27 '22 12:06 Saentist

IMG_20220627_213520.jpg from tuya app

sanyatuning avatar Jun 27 '22 19:06 sanyatuning

from tuya app

Main Module: V3.1.4
MCU Module V1.0.0

with is rev.2

Saentist avatar Jun 28 '22 05:06 Saentist

Man !!! A need this.

guiseco avatar Sep 26 '22 20:09 guiseco

Hi, Any update on this?

ha-bnst avatar Nov 12 '22 00:11 ha-bnst

Is this implemented yet?. Still dont know how to add zmai like energy meter devices.. any updates on this.. thanks

kmb36td avatar Nov 18 '22 21:11 kmb36td

Is this implemented yet?. Still dont know how to add zmai like energy meter devices.. any updates on this.. thanks

No Tuya device's can be added to energy monitoring. Even Tuya app want money for monitoring.

Saentist avatar Nov 18 '22 22:11 Saentist

Is this implemented yet?. Still dont know how to add zmai like energy meter devices.. any updates on this.. thanks

No Tuya device's can be added to energy monitoring. Even Tuya app want money for monitoring.

sure you can.. I can already get the energy part kWh of my tuya device just with 4.1.1 default.. but not the voltage current and power.. I added the code above.. and the needed dps 6 shows up with its value string to be decoded even though I see there is a del "dps" "6" line added by sanyatuning.. but cannot use it.. somehow the value filtered out somewhere and set to null.. means localtuya can read the data.. but is filtered out by itself..

kmb36td avatar Nov 21 '22 03:11 kmb36td

sure you can.. I can already get the energy part kWh of my tuya device just with 4.1.1 default.. but not the voltage current and power.. I added the code above.. and the needed dps 6 shows up with its value string to be decoded even though I see there is a del "dps" "6" line added by sanyatuning.. but cannot use it.. somehow the value filtered out somewhere and set to null.. means localtuya can read the data.. but is filtered out by itself..

DPS values classification and multiplier (scale_factor) can be taken online, or set manually or if implemented by template. Currently free text is not solution. Case sensitive (KWH Kwh KWh kwh) with is correct?

python3 -m tinytuya wizard
TinyTuya Setup Wizard [1.1.2]
...json
[SPM] - 192.168.1.80 - On - DPS: {'1': True, '17': 78640, '18': 156, '19': 163, '20': 2175}

{
	'1': True,      -- Switch status
	'17': 78640, -- Total KWh (*00.1)
	'18': 156,   -- mA - current (*0.1)
	'19': 163,   -- W  - consumption (*0.1)
	'20': 2175   -- V  - voltage (*0.1)
}

DPS 6 not exist on my device revision. Hardcoded values is not solution.

Saentist avatar Nov 21 '22 06:11 Saentist

image

@sanyatuning What device revision you have?

my ZMAi-90 have very different output

python3 -m tinytuya wizard
TinyTuya Setup Wizard [1.1.2]
...
[SPM] - 192.168.1.80 - On - DPS: {'1': True, '17': 78640, '18': 156, '19': 163, '20': 2175}

{
	'1': True,      -- Switch status
	'17': 78640, -- Total KWh (*00.1)
	'18': 156,   -- mA - current (*0.1)
	'19': 163,   -- W  - consumption (*0.1)
	'20': 2175   -- V  - voltage (*0.1)
}

I have done it already.. Mine also does not show DP6.. but you can tell tuya to force detect it.. there is there is a set manual DPS in the localtuya gui.. just type 6 there.. and you should see DP6..and see the the string to be decoded.. in my case the value is initially -1.. but just add it to any atrributes.. I added mine to current.. then just create 3 command_line sensor for current voltage power in homeassistant and use it to execute python code to decode the string.. see I already made mine working... mine is not even zmai-90 its just similar.. yours have different output,, not all zmai are encoded the same.. mine is different from sanyatuning.. so I decoded it myself.. easy if you just learn basic python.. I learn by reading 1 page tutorial LOL... note im just using vanila localtuya v4.1.1 https://postimg.cc/qgnbSWdK https://community.home-assistant.io/t/pass-sensor-value-to-python-script-process-it-and-return-back-as-another-sensor-value/225270

kmb36td avatar Nov 24 '22 04:11 kmb36td