Open PmNz8 opened 3 years ago
I have Blitwolf SHP-6 and the same problem - I get answer from tuya support "Hello, this is defined by product function points. The voltage multiple is "10^(-1)" and the power multiple is "10^(-2)" - but in SHP-6 looks like for power is also 10^(-1) . so looks like tuya don't want correct it, it must be corrected by integration ?
Home Assistant Version core-2021.8.8 / Tuya V2 1.5.0
Device info { "active_time": 1629660556, "biz_type": 18, "category": "cz", "create_time": 1606842490, "icon": "smart/device_icon/eu1588704937747Y0fxA/834250612462ab48e793161046619548672.png", "id": "834250612462ab48e793", "ip": "", "lat": "", "local_key": "", "lon": "", "name": "PG", "online": true, "owner_id": "24846501", "product_id": "ab4kwxlrok0yvxuo", "product_name": "BW-SHP6", "status": [ { "code": "switch", "value": false }, { "code": "countdown_1", "value": 0 }, { "code": "cur_current", "value": 0 }, { "code": "cur_power", "value": 0 }, { "code": "cur_voltage", "value": 2306 } ], "sub": false, "time_zone": "+01:00", "uid": "***", "update_time": 1629660564, "uuid": "834250612462ab48e793" },
Device specyfication
2021-08-23 07:37:49 DEBUG (SyncWorker_5) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/834250612462ab48e793/specifications, params = None, body = None, t = 1629697069800 2021-08-23 07:37:49 DEBUG (SyncWorker_5) [tuya iot] Response: { "result": { "category": "cz", "functions": [ { "code": "switch", "type": "Boolean", "values": "{}" }, { "code": "countdown_1", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"s\",\"max\":86400,\"step\":1}" } ], "status": [ { "code": "countdown_1", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"s\",\"max\":86400,\"step\":1}" }, { "code": "cur_current", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"mA\",\"max\":30000,\"step\":1}" }, { "code": "cur_voltage", "type": "Integer", "values": "{\"min\":0,\"unit\":\"V\",\"scale\":0,\"max\":2500,\"step\":1}" }, { "code": "cur_power", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"W\",\"max\":50000,\"step\":1}" }, { "code": "switch", "type": "Boolean", "values": "{}" } ] }, "success": true, "t": 1629697069908 }
Same Here with Gosund WIFI plug with meter Gosund SP111
{
"active_time": 1629812692,
"biz_type": 18,
"category": "cz",
"create_time": 1621168384,
"icon": "smart/icon/ay1519551146071pEnBd/14c77e7f9b5760eae919b3cb216cf70f.png",
"id": "8877821724a160145d3b",
"ip": "***",
"lat": "***",
"local_key": "***",
"lon": "***",
"model": "欧规,10A,带计电量,支持酷客RF产测",
"name": "Gosund Sirius",
"online": true,
"owner_id": "21339891",
"product_id": "wifvoilfrqeo6hvu",
"product_name": "Smart Socket",
"status": [
{
"code": "switch_1",
"value": true
},
{
"code": "countdown_1",
"value": 0
},
{
"code": "add_ele",
"value": 10
},
{
"code": "cur_current",
"value": 337
},
{
"code": "cur_power",
"value": 798
},
{
"code": "cur_voltage",
"value": 2362
}
],
"sub": false,
"time_zone": "+01:00",
"uid": "***",
"update_time": 1629820581,
"uuid": "8877821724a160145d3b"
},
Any progress ?
I've got a couple of Teckin SP23 plugs with the same issue:
I changed into sensor.py to: state = (value) * 0.1 / (10 ** value_range.get ("scale")) if __value_range.get ("scale") == 0: return int ( state) return f "%. {__ value_range.get ('scale')} f"% __state return "" and it works for gosunds but additionally in the case of a thermometer it divides the value, i.e. instead of 24 degrees it makes 2.4 degrees
Any ETA to fix the integration?
I don't think that this something for tuya to fix. I have the same issue when using the tuya integration but all values are ok when using the local tuya integration or checking the power consumption in the tuya android app. By the way when using the tuya integration both voltage and power consumption (W) are x10 for my gosund sp111 sockets.
Home Assistant 2022.2 has a diagnostic download tool on the device page, feel free to share your diagnostics download so we can see where the difference comes from.
It's pretty clear where the difference comes from and has been said several times, here and elsewhere:- The Tuya API, from which the integration derives it's data, correctly labels current values in mA units, but incorrectly labels voltage and power as V and W. The raw integers in fact represent dV and dW (i.e. deci-, 1e-1, 1x10e-1, 1/10, however you want to express it). The Tuya App accounts for this and displays corrected values to the user. The integration does not.
🤷
Home Assistant can only use what the API of Tuya provides.
If the API provides incorrect data, please contact Tuya support.
Home Assistant 2022.2 has a diagnostic download tool on the device page, feel free to share your diagnostics download so we can see where the difference comes from.
yeah sure. Hope it helps
tuya-f6d6165401802930ca06a887187458a9-gosund-livingroom-2cf18634bc79545625d1813c693de658.json.txt
@desosav From your diagnostics (cut out all the unrelated stuff):
{
...
"status_range": {
"cur_voltage": {
"type": "Integer",
"value": {
"min": 0,
"unit": "V",
"scale": 0,
"max": 2500,
"step": 1
}
},
}
...
"status": {
...
"cur_voltage": 2359
},
....
}
☝️ that is the information provided about voltage for your device by the Tuya API.
The first part tells us cur_voltage
is an integer (numeric), with a min, max value, a unit, and the incremental/decremental steps the voltage value has.
Furthermore, there is scale
which it was Tuya provides to tell how a value should be scaled. In this case, its 0
, so no scaling should be applied at all.
Next up, the status reported is 2359
, as the Tuya API said it should not be scaled, it results in: 2359V
(which is within the min/max values as well).
Thus, Home Assistant is displaying/showing the provided data correctly in your case, as seen in the diagnostics output of the entity that Home Assistant created:
"state": {
"entity_id": "sensor.gosund_livingroom_voltage_2",
"state": "2359.0",
"attributes": {
"state_class": "measurement",
"unit_of_measurement": "V",
"device_class": "voltage",
"friendly_name": "gosund-livingroom Voltage"
},
For now I fixed the 10x higer values using this code. I'm a noob but it works basically it's just the name of the 10x power value and "_real" added to create a new virtual value. I did this only for my SP111 plugs because my two SP211 and other tuya plugs work just fine.
Code in templates.yaml for every plug
- platform: template
sensors:
sensor_smart_socket_2_power_real:
friendly_name: "Plug 2 Real "
unit_of_measurement: W
device_class: power
value_template: " {{ states('sensor.smart_socket_2_power') | float(default=0.0) | multiply(0.1) | round(1) }} "
Code in sensor.yaml for every plug to track it in energy dashboard
- platform: integration
source: sensor.sensor_smart_socket_2_power_real
name: Real power for plug 2
unit_prefix: k
unit: kWh
round: 2
The same is with Nous A1 sockets, in the Tuya app, it shows correctly, but in Home Assistant power/voltage is 10x.
Is this a bug on all plugs, or just these two? Maybe this could be detected/fixed by looking at the max value for voltage? 2500V sockets definitely do not exist.
tuya-94707e68539e10889b2af96ab7e2cbf3-Laurynas Desk-43ffc2d6a4a8bed11d8abe7f12f974b6.json.txt ?
It's applicable to all of the differently branded power monitoring smart mains socket devices that use this category in the Tuya API. (There are many of them.)
If we are being precisely accurate this issue is for Tuya's API team to fix (presumably something Maintainer https://github.com/zlinoliver would have input to), since the units it says it's using in the API are demonstrably incorrect. Given that the Tuya app (and it's many other co-branded front ends) already make the correction for this error someone, somewhere, in the Tuya organisation knows about this and has written customer-end code to deal with it, rather than get the API corrected. (There are a multitude of possible business or operational reasons for doing it this way. Not saying they are necessarily good reasons from our point of view, but it is what it is :) )
The official
HomeAssistant view seems to be "That's the data we are given, so that's what we'll display. It's up to Tuya to correct at their end."
Whether that's a realistic view, given the large install base of the various official & rebranded Apps across the dozens of manufacturer brands and hundreds of individual device models, is a different question.
At the end of the day the HA people are volunteers, and aren't getting paid to deal with this, plus there's a whole minefield of potential issues if they decide they should unilaterally go around correcting for flaws in the various source-data APIs from manufacturers (is there even a policy for this sort of thing ?).
TL;DR - I think for now we are going to have to live with using one of the various hacky "divide by 10" workarounds on an individual basis in personal HA installs.
Hi ALl,
I have 3 shp6, 1 that don't works shares the Power and voltage X10 , looing on the logs and the Tuya IOT platform i've found a diference in the parameter: cur_power and cur_voltage, in the incorrect socket it have the scale value of each of them to 0, and the one that works fine is 1.
I't might help, seems that is a problem with the developers of the hardware....
Same problem with Gosund EP2
Still no way to fix this? :(
Yeap, same issue for me...
Same here
For now I fixed the 10x higer values using this code. I'm a noob but it works basically it's just the name of the 10x power value and "_real" added to create a new virtual value. I did this only for my SP111 plugs because my two SP211 and other tuya plugs work just fine.
Code in templates.yaml for every plug
- platform: template sensors: sensor_smart_socket_2_power_real: friendly_name: "Plug 2 Real " unit_of_measurement: W device_class: power value_template: " {{ states('sensor.smart_socket_2_power') | float(default=0.0) | multiply(0.1) | round(1) }} "
Code in sensor.yaml for every plug to track it in energy dashboard
- platform: integration source: sensor.sensor_smart_socket_2_power_real name: Real power for plug 2 unit_prefix: k unit: kWh round: 2
Where do I have to create the files?
What I have done is the following:
At the end of /hass-config/configuration.yaml file I have added the following line:
template: !include templates.yaml
Then in /hass-config/templates.yaml I have this:
sensor:
- name: "Central Plug Power"
unit_of_measurement: "W"
state: "{{ states('sensor.central_plug_power_2') | float(0) / 10 | round(2) }}"
Obviously you'll have to add a template for each sensor affected by the problem.
This issue is Tuya platform issue Submited ticket to Tuya support T202407220009
This issue is Tuya platform issue Submited ticket to Tuya support T202407220009
Any answer from Tuya support?
Describe the bug Smart Socket is reporting 2300 Volts.
Expected behavior Socket is problably missing separator, and reports 2300 V instead of 230,0 V (confirmed on 2 Gosund SP111)
Screenshots
Home Assistant Version core-2021.8.8 / Tuya V2 1.5.0
Device info 2021-08-22 00:41:31 DEBUG (SyncWorker_1) [tuya iot] Response: { "result": [ { "active_time": 1629545303, "biz_type": 0, "category": "cz", "create_time": 1629545286, "icon": "smart/icon/1541647698myzx2yx1yk_0.jpg", "id": "0406438770039f642110", "ip": "", "lat": "", "local_key": "", "lon": "", "model": "SP111,15A,带计电量,中性", "name": "Smart Socket 1", "online": true, "owner_id": "23880449", "product_id": "37mnhia3pojleqfh", "product_name": "Smart Socket", "status": [ { "code": "switch", "value": true }, { "code": "countdown_1", "value": 0 }, { "code": "cur_current", "value": 0 }, { "code": "cur_power", "value": 0 }, { "code": "cur_voltage", "value": 0 } ], "sub": false, "time_zone": "+01:00", "uid": "***", "update_time": 1629584126, "uuid": "0406438770039f642110" },
Device specifications 2021-08-22 00:41:31 DEBUG (SyncWorker_1) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/0406438770039f642110/specifications, params = None, body = None, t = 1629585691559 2021-08-22 00:41:31 DEBUG (Thread-5) [tuya iot] _on_log: Received CONNACK (0, 0) 2021-08-22 00:41:31 DEBUG (Thread-5) [tuya iot] connect flags->{'session present': 0}, rc->0 2021-08-22 00:41:31 DEBUG (Thread-5) [tuya iot] _on_log: Sending SUBSCRIBE (d0, m1) [(b'cloud/token/in/615f88c2bf66c5c750cfb45285ee34dc', 0)] 2021-08-22 00:41:31 DEBUG (SyncWorker_1) [tuya iot] Response: { "result": { "category": "cz", "functions": [ { "code": "switch", "type": "Boolean", "values": "{}" }, { "code": "countdown_1", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"s\",\"max\":86400,\"step\":1}" } ], "status": [ { "code": "countdown_1", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"s\",\"max\":86400,\"step\":1}" }, { "code": "cur_current", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"mA\",\"max\":30000,\"step\":1}" }, { "code": "cur_voltage", "type": "Integer", "values": "{\"min\":0,\"unit\":\"V\",\"scale\":0,\"max\":2500,\"step\":1}" }, { "code": "cur_power", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"W\",\"max\":50000,\"step\":1}" }, { "code": "switch", "type": "Boolean", "values": "{}" } ] }, "success": true, "t": 1629585691623 }
Thank you for looking into this! As a result of 10x higher voltage, reported power is also 10x higher:
Reported current is OK: