localtuya
localtuya copied to clipboard
Support ZMAi-90 Energy Meter
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)
@rospogrigio can you review this? Thx
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 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.
How do I implement this fix, I have the same meter but I do not see 6A, 6W or 6V?
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 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)
@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)
}
from tuya app
from tuya app
Main Module: V3.1.4
MCU Module V1.0.0
with is rev.2
Man !!! A need this.
Hi, Any update on this?
Is this implemented yet?. Still dont know how to add zmai like energy meter devices.. any updates on this.. thanks
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.
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..
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.
@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