Open slydiman opened 2 years ago
I have the following answer from Tuya Service & Support
:
Phase_a parsing rules:
- A-phase voltage, current and power
- Big-endian mode, HEX format, 10 bytes in total
- unit accuracy: voltage, 2 bytes, unit 0.1V. Current, 3 bytes, 0.001a. Phase A active power, 3 bytes, unit 0.001kW
- Packet format
For example, 08 80 00 03 E8 00 27 10 indicates the A phase 217.6V, the A phase current 1.000A, and the A phase power 10.000 KW
In my case the following state
{
"code": "phase_a",
"value": "CXQACcQAAWwAAA=="
},
can be decoded as 09 74 00 09 c4 00 01 6c 00 00, which means 0x974 = 242.0V 0x9C4 = 2.5A 0x16C = 364W
So all necessary information is present. Please fix the Tuya v2 integration to parse this information correctly and add necessary sensors. Thanks!
total_forward_energy
has already been fixed in master branch, other things need to be added
I have the following answer from
Tuya Service & Support
:Phase_a parsing rules:
- A-phase voltage, current and power
- Big-endian mode, HEX format, 10 bytes in total
- unit accuracy: voltage, 2 bytes, unit 0.1V. Current, 3 bytes, 0.001a. Phase A active power, 3 bytes, unit 0.001kW
- Packet format
For example, 08 80 00 03 E8 00 27 10 indicates the A phase 217.6V, the A phase current 1.000A, and the A phase power 10.000 KW
In my case the following state
{ "code": "phase_a", "value": "CXQACcQAAWwAAA==" },
can be decoded as 09 74 00 09 c4 00 01 6c 00 00, which means 0x974 = 242.0V 0x9C4 = 2.5A 0x16C = 364W
So all necessary information is present. Please fix the Tuya v2 integration to parse this information correctly and add necessary sensors. Thanks!
I tried manually change sensor.py (in version 1.6) as yours PR, and all work fine. But new PR is needed, because version 1.6 is different.
But new PR is needed, because version 1.6 is different.
I don't see any reason for a new PR. I have rebased the existing PR and there is no any conflict with 1.6.
Please add a comment to PR https://github.com/tuya/tuya-home-assistant/pull/498 that all work fine.
Hope it will be merged some day and I won't need to rebase it for years after each release.
Similar issue here. The power/energy information was showing in HA as separate entities when using the tuya2 custom integration, but on moving to the 'official' tuya2 integration those entities disappeared. Checking the logs I can see the information is there, but again it's not showing as either separate entities or as attributes for the main entity itself. Here's the info for the device in the HA log showing it is actually exposing info such as current and power etc:
{ "active_time": 1602806606, "biz_type": 18, "category": "cz", "create_time": 1592870560, "icon": "smart/icon/ay1536534747810ekKBj/1567489983a750d08c70e.png", "id": "655256142*********", "ip": "***", "lat": "***", "local_key": "***", "lon": "***", "model": "PC399HA", "name": "Gaming PC", "online": true, "owner_id": "5974179", "product_id": "4ooy6eeqo6hnlax1", "product_name": "Smart Plug with Energy Meter PC399HA", "status": [ { "code": "switch_1", "value": true }, { "code": "countdown_1", "value": 0 }, { "code": "add_ele", "value": 78 }, { "code": "cur_current", "value": 1350 }, { "code": "cur_power", "value": 1716 }, { "code": "cur_voltage", "value": 250 } ], "sub": false, "time_zone": "+10:00", "uid": "***", "update_time": 1634573195, "uuid": "65525614**************" },
[sorry about the formatting - github seems to be mucking up things when inserting code for me currently!]
The power/energy information was showing in HA as separate entities when using the tuya2 custom integration, but on moving to the 'official' tuya2 integration those entities disappeared.
SMT006 is a new device. It is the breaker (over-under voltage protector) with energy meter. The category is "dlq". This device never worked with the previous integration or with this integration. So I have added the support myself.
Category of your device is "cz". It means socket. I have no such device and I don't know how it worked with the previous integration. I cannot help with it.
Please open a separate issue for your device.
OK - thanks for responding, and understood.
I have the following answer from
Tuya Service & Support
:Phase_a parsing rules:
- A-phase voltage, current and power
- Big-endian mode, HEX format, 10 bytes in total
- unit accuracy: voltage, 2 bytes, unit 0.1V. Current, 3 bytes, 0.001a. Phase A active power, 3 bytes, unit 0.001kW
- Packet format
For example, 08 80 00 03 E8 00 27 10 indicates the A phase 217.6V, the A phase current 1.000A, and the A phase power 10.000 KW
In my case the following state
{ "code": "phase_a", "value": "CXQACcQAAWwAAA==" },
can be decoded as 09 74 00 09 c4 00 01 6c 00 00, which means 0x974 = 242.0V 0x9C4 = 2.5A 0x16C = 364W
So all necessary information is present. Please fix the Tuya v2 integration to parse this information correctly and add necessary sensors. Thanks!
Hi, similar issues with a wifi smart meter switch, receiving: "code":"phase_a" "value":"CO0AAAAAAAA="
Please, how can I decode from "CO0AAAAAAAA=" to three separate HEX numbers (voltage, current and power), as you did with your value "CXQACcQAAWwAAA==" ?
Thanks in advance!
base64 decode "CO0AAAAAAAA=" > 08ed 000000 000000 228.5V 0A 0W
Yes!, no current through the switch now. I imagine you used a web decoder Base64 to Hex, so I just need to program the decoding rules into my node-red function to get the actual power, voltage and current.
Thanks a lot.
If anyone need this in PHP:
<?php
require( 'config.php' );
$app_id = 'xxxxxxxxxxxx';
$device_id = 'xxxxxxxxxxxxxx';
$tuya = new \tuyapiphp\TuyaApi( $config );
$token = $tuya->token->get_new( )->result->access_token;
$tuya = $tuya->devices( $token )->get_status( $device_id );
$array = json_encode($tuya, JSON_PRETTY_PRINT);
function left($cadena, $count)
{
return substr($cadena, 0, $count);
}
function right($str, $length)
{
return substr($str, -$length);
}
$hex = bin2hex(base64_decode($tuya->result[1]->value));
echo "<br /><br />Online: ";
echo $tuya->result[10]->value;
echo "<br /><br />Energy kWh: ";
echo $tuya->result[0]->value;
echo "<br /><br />Leak Current mA: ";
echo $tuya->result[2]->value;
echo "<br /><br />Activado: ";
echo $tuya->result[3]->value;
echo "<br /><br />Amps A: ";
$amp = right(left ($hex, 10), 6);
echo hexdec($amp)/1000;
echo "<br /><br />Volts V: ";
$volt = left ($hex, 4);
echo hexdec($volt)/10;
echo "<br /><br />Power W: ";
$wat = right($hex, 6);
echo hexdec($wat)/1000;
echo "<br /><br />Temp C: ";
echo ($tuya->result[20]->value / 10);
?>
Describe the bug The
power
,voltage
,current
,leak current
sensors are missing at all!The energy sensor is missing the attribute
state_class: total_increasing
. The attributeunit_of_measurement
is wrong -kW·h
instead ofkWh
. So it is impossible to add this sensor to the Energy panel.Expected behavior Please add the power, voltage, current and leak current sensors.
The energy sensor must contain the attributes
state_class: total_increasing
andunit_of_measurement: kWh
.Screenshots
Home Assistant Version 2021.9.7
Device info :
Device specifications:
Additional context