tuya / tuya-home-assistant

Home Assistant integration for controlling Powered by Tuya (PBT) devices using Tuya Open API, maintained by the Home Assistant Community and Tuya Developer Team.
MIT License
882 stars 207 forks source link

Smart Plug with energy monitoring - incorrect measuring units #102

Open prehodacs opened 3 years ago

prehodacs commented 3 years ago

Describe the bug

Added Blitzwolf BW-SHP6 smart socket to Home assistant with the new tuya_v2 integration. The issue I discovered is that the measure units are mixed for Power, Voltage. Also an issue is for Voltage displayed value is multiplied by 10 See the screenshot szaritogep

Expected behavior Power unit should be W or kW - instead of V Voltage unit should be V instead of W Voltage should be divided by 10: eg on screenshoot 227.5V instead of 2275

Home Assistant Version Home Assistant 2021.4.6

**Device info { "active_time": 1621244982, "biz_type": 18, "category": "cz", "create_time": 1621244982, "icon": "smart/icon/ay1519551146071pEnBd/f3fca8ef65c979cb1aed14fc878c9107.jpg", "id": "1744254370039f5dbbc8", "ip": "62.201.71.127", "lat": "47.654344", "local_key": "18ebc89d17b5777d", "lon": "19.2956575", "model": "SP111-A,棒谷,15A,带计电量", "name": "Szárítógép", "online": true, "owner_id": "14557030", "product_id": "ab4kwxlrok0yvxuo", "product_name": "BW-SHP6", "status": [ { "code": "switch", "value": true }, { "code": "countdown_1", "value": 0 }, { "code": "cur_current", "value": 0 }, { "code": "cur_power", "value": 0 }, { "code": "cur_voltage", "value": 2243 } ], "sub": false, "time_zone": "+01:00", "uid": "eu1596231650476O2RQr", "update_time": 1625483822, "uuid": "1744254370039f5dbbc8" },

**Device specifications 2021-07-06 18:30:13 DEBUG (SyncWorker_2) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/1744254370039f5dbbc8/specifications, params = None, body = None, headers = {'client_id': 'xp5yh8ctaqbejm2ghow7', 'sign': '08F3AA05940D587F28C5891ABA9469E76B77E909232864965214055619E67DE7', 'sign_method': 'HMAC-SHA256', 'access_token': '2addcf6fcf26468eb22a07a33d9a890c', 't': '1625589013592', 'lang': 'en'} 2021-07-06 18:30:13 DEBUG (SyncWorker_2) [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,\"scale\":0,\"unit\":\"W\",\"max\":50000,\"step\":1}" }, { "code": "cur_power", "type": "Integer", "values": "{\"min\":0,\"unit\":\"V\",\"scale\":0,\"max\":2500,\"step\":1}" }, { "code": "switch", "type": "Boolean", "values": "{}" } ] }, "success": true, "t": 1625589013621 }

Additional context Add any other context or logs about the problem here.

tsutsuku commented 3 years ago

@prehodacs Get it.

tsutsuku commented 3 years ago

@prehodacs The unit is fixed, try again.

AndreOrth commented 3 years ago

Hello, I have exactly the same problem with several Gosund SP111, 15A WiFi sokets: image

Volt (V) is Watt (W) in Home Assistant and vice versa. Both measures are too high by factor 10.

Home Assistant: 2021.7.0 Installation Type: Home Assistant OS

DEVICE DETAILS { "result": { "active_time": 1624575898, "biz_type": 0, "category": "cz", "create_time": 1623334919, "icon": "smart/icon/1541647698myzx2yx1yk_0.jpg", "id": "3038076070039f63e98e", "ip": "178.85.139.189", "lat": "52.35110345583657", "local_key": "d34e9e59e0cbdf48", "lon": "4.801993022378849", "model": "SP111,15A,带计电量,中性", "name": "Dell work plug", "online": true, "owner_id": "30055001", "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": 2277 } ], "sub": false, "time_zone": "+01:00", "uid": "eu1619794810347GUY7B", "update_time": 1625760027, "uuid": "3038076070039f63e98e" }, "success": true, "t": 1625762840241 }

DEVICE ATTRIBUTES { "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,\"scale\":0,\"unit\":\"W\",\"max\":50000,\"step\":1}" }, { "code": "cur_power", "type": "Integer", "values": "{\"min\":0,\"unit\":\"V\",\"scale\":0,\"max\":2500,\"step\":1}" }, { "code": "switch", "type": "Boolean", "values": "{}" } ] }, "success": true, "t": 1625762774780 }

Would this fix include the Gosund Smart WiFi sockets as well? If that's not the case would it be possible to fix the values as well (or maybe there is an option how I can do it myself? 😅

Any help is much appreciated!

Best regards, Andre

tsutsuku commented 3 years ago

@AndreOrth You can create a ticket in the Tuya service console with your device specifications. https://service.console.tuya.com/8/2/create?step=3&id=01030503&source=content_feedback.

AndreOrth commented 3 years ago

@tsutsuku thank you very much for your reply and information. I just created a ticket in the Tuya service console as you advised :).

prehodacs commented 3 years ago

@tsutsuku - thanks units are corrected - looks good now. Although the Voltage range is still high - it shows 2302 V which would definitely too much for any machine in my household. Capture In SmartLife app the correct value visible , in Home Assistant this value is multiplied by 10. Can you correct that also?

gijsje commented 3 years ago

I have uploaded all the latest files to my custom components but it still shows the wrong voltage and power 2021-07-13 This is with a 40w light bulb

tsutsuku commented 3 years ago

@gijsje Can you provide your device specification? https://github.com/tuya/tuya-home-assistant/wiki/How-to-Get-the-Log

gijsje commented 3 years ago

@tsutsuku

{ "active_time": 1626184675, "biz_type": 0, "category": "cz", "create_time": 1626184675, "icon": "smart/icon/ay1519551146071pEnBd/f3fca8ef65c979cb1aed14fc878c9107.jpg", "id": "", "ip": "", "lat": "", "local_key": "", "lon": "", "name": "Anthony 1", "online": true, "owner_id": "5538396", "product_id": "ab4kwxlrok0yvxuo", "product_name": "BW-SHP6", "status": [ { "code": "switch", "value": true }, { "code": "countdown_1", "value": 0 }, { "code": "cur_current", "value": 172 }, { "code": "cur_power", "value": 391 }, { "code": "cur_voltage", "value": 2266 }

patrik-malina commented 3 years ago

with v1.3.2 everything ok with me

andrewbeyou88 commented 3 years ago

{ "result": { "active_time": 1625171169, "biz_type": 18, "category": "cz", "create_time": 1625160394, "icon": "smart/icon/1541647698myzx2yx1yk_0.jpg", "lon": "23.7563449", "name": "Smart Socket", "online": true, "owner_id": "30719948", "product_id": "37mnhia3pojleqfh", "product_name": "Smart Socket", "status": [ { "code": "switch", "value": true }, { "code": "countdown_1", "value": 0 }, { "code": "cur_current", "value": 3070 }, { "code": "cur_power", "value": 7089 }, { "code": "cur_voltage", "value": 2309 } ], "sub": false, "time_zone": "+02:00", "uid": "eu1620898850249QRdB9", "update_time": 1626714523, "uuid": "3038076070039f64c78f" }, "success": true, "t": 1627217006331 }

Gosund SP111-A Same problem, with late and multiplied values!

maxallepi commented 3 years ago

Same here BW-SHP11

chrismanivong commented 3 years ago

@tsutsuku Did you receive a notice about my report?

tsutsuku commented 3 years ago

Can you provide your device specifications? not the device info you have provided.

andrewbeyou88 commented 3 years ago

Smart plug WiFi Gosund SP111 3450W 15A Until i have link it to iot platform is reading wrong values. https://github.com/tuya/tuya-home-assistant/issues/102#issuecomment-886197454 What can i do, i need iot platform for tuya V2 integration.

maxallepi commented 3 years ago

@tsutsuku Some info from the log that might help. I'm getting 10x the power. Value should be 14.2w for example.

{ "active_time": 1620542319, "biz_type": 18, "category": "cz", "create_time": 1611328600, "icon": "smart/icon/ay149682747096840kwW/79364394c3297745a408fe5dafbbabc1.jpg", "id": "05157867fcf5c4aaec1d", "ip": "", "lat": "", "local_key": "", "lon": "", "model": "", "name": "Power Plug", "online": true, "owner_id": "23663464", "product_id": "pdjgpz7mta86mvyh", "product_name": "BW-SHP11", "status": [ { "code": "switch", "value": true }, { "code": "countdown_1", "value": 0 }, { "code": "add_ele", "value": 7 }, { "code": "cur_current", "value": 123 }, { "code": "cur_power", "value": 142 }, { "code": "cur_voltage", "value": 2283 } ], "sub": false, "time_zone": "+02:00", "uid": "***", "update_time": 1628690261, "uuid": "05157867fcf5c4aaec1d" },

chrismanivong commented 3 years ago

@tsutsuku

here the device specs are:

2021-08-11 15:07:48 DEBUG (SyncWorker_5) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/8113680070039f17c164/specifications, params = None, body = None, t = 1628687268029 2021-08-11 15:07:48 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,\"scale\":0,\"unit\":\"W\",\"max\":50000,\"step\":1}" }, { "code": "cur_power", "type": "Integer", "values": "{\"min\":0,\"unit\":\"V\",\"scale\":0,\"max\":2500,\"step\":1}" }, { "code": "switch", "type": "Boolean", "values": "{}" } ] }, "success": true, "t": 1628687268083 }

mycrouch commented 3 years ago

I reported the same issue in #250

Screen Shot 2021-08-02 at 4 57 11 pm

I'm using a template for each entity as a current workaround.

 entry_lightswitch:
    friendly_name: 'Entry - Light_power_w'
    unit_of_measurement: 'w'
    value_template: '{{(states.sensor.ty57210084500291442b65_2.state | float / 10 | round(1) )}}'

This reporting error also impacts Energy Dashboards ability to report kWh correctly.

hermanops commented 3 years ago

Same problem here. Smart Socket shows voltage as Watts and Power as Volts. "model": "定制,15,带计电量", "name": "Smart Socket A1", "product_id": "m6ei1t46nqn0p0p9", "product_name": "Smart Socket A1"

url = https://openapi.tuyaeu.com/v1.0/devices/31130006c4dd571cf300/specifications { "code": "curvoltage", "type": "Integer", "values": "{\"min\":0,\"scale\":0,\"unit\":\"W\",\"max\":50000,\"step\":1}" }, { "code": "curpower", "type": "Integer", "values": "{\"min\":0,\"unit\":\"V\",\"scale\":0,\"max\":2500,\"step\":1}" },

  installed from master branch today
andrewbeyou88 commented 3 years ago

Hello guys, i've solved my Gosund SP111 problem. It was all my fault, i wasn't activated "Device Status Notification" IoT platform. https://user-images.githubusercontent.com/77467195/128992017-4e4cd6fa-5f8b-4679-87af-8ac6910e7eae.png Go to Cloud/My Services/All Services and search for "Device Status Notification" You can then Trial Subscribe to it and add your project to it. I had to restart HA and now it works perfectly.

proffa84 commented 3 years ago

I have similar error, but 1/4 smart plug shows correct(nedis indoor plug, "makkarin elektroniikka", in tuya v2 it is called "Power Monitor") Screenshot 2021-08-30 19 05 24

all of Nedis outdoor smart plugs(3 pieces) shows power and voltages incorrectly(10x of correct values) Screenshot 2021-08-30 19 05 14

In tuya "device debugging" all plugs have same setting, ("scale": 1, ") and shows same way, 10x of correct values Screenshot 2021-08-30 19 10 43 Screenshot 2021-08-30 19 09 19 Screenshot 2021-08-30 19 31 46

andrewbeyou88 commented 3 years ago

For those wrong value's you can just create a Template Sensor:

This will help, "%3.1f'%" also is for 3 number before "." and 1 number after "."

bdkacz commented 3 years ago

For those wrong value's you can just create a Template Sensor:

But it doesn't make sense. You install a dedicated integration to write everything "from your finger" on the templates :) Especially that x10 is everything - voltage, current and power :) So you have to create 3 templates * the number of sockets you have :) This should be solved by few lines of code at the integration level :)

crus1313 commented 3 years ago

Any ETA for x10 integration error?

Tntdruid commented 2 years ago

Any update for this?

andrewbeyou88 commented 2 years ago

My last update is, I gave up and started converting to tasmota. I used my raspberry pi and flashed tasmota.bin on "Gosund Plug" over the air (wifi), no soldering. Now is working perfectly, no cloud no problems ! https://templates.blakadder.com/gosund_SP111_v1_1

cutzenfriend commented 2 years ago

Will this ever be fixed?

frenck commented 2 years ago

Depends if this is a device issue, or Home Assistant issue. Home Assistant 2022.2 has a diagnostic tool. Go to the device and download the diagnostic information for that device. Drag and drop that file in a response on this issue ao we can see

hermanops commented 2 years ago

tuya-43a27f85079b276579100529d93b8fa3-Smart Socket A1-af6c83bf5385b9e2b9c7d82fa16c8e09.json (2).txt

kuraikaze commented 2 years ago

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.

car1ox commented 2 years ago

Same problem of wrongly reporting x10 in my new Tuya socket USmart

Screenshot_20220227-203539_Home Assistant

car1ox commented 2 years ago

The diagnostic information:

{ "home_assistant": { "installation_type": "Home Assistant Container", "version": "2022.2.3", "dev": false, "hassio": false, "virtualenv": false, "python_version": "3.9.7", "docker": true, "arch": "armv7l", "timezone": "Europe/Madrid", "os_name": "Linux", "os_version": "5.10.17-v7l+", "run_as_root": true }, "custom_components": { "adaptive_lighting": { "version": "1.0.14", "requirements": [] }, "config_editor": { "version": "2.0", "requirements": [] }, "hacs": { "version": "1.18.0", "requirements": [ "aiogithubapi>=21.11.0" ] }, "switch_humidifier": { "version": "1.2.0.0", "requirements": [] } }, "integration_manifest": { "domain": "tuya", "name": "Tuya", "documentation": "https://www.home-assistant.io/integrations/tuya", "requirements": [ "tuya-iot-py-sdk==0.6.6" ], "dependencies": [ "ffmpeg" ], "codeowners": [ "@Tuya", "@zlinoliver", "@METISU", "@frenck" ], "config_flow": true, "iot_class": "cloud_push", "dhcp": [ { "macaddress": "105A17" }, { "macaddress": "10D561" }, { "macaddress": "1869D8" }, { "macaddress": "381F8D" }, { "macaddress": "508A06" }, { "macaddress": "68572D" }, { "macaddress": "708976" }, { "macaddress": "7CF666" }, { "macaddress": "84E342" }, { "macaddress": "D4A651" }, { "macaddress": "D81F12*" } ], "is_built_in": true }, "data": { "endpoint": "https://openapi.tuyaeu.com", "auth_type": 0, "country_code": "34", "app_type": "tuyaSmart", "mqtt_connected": true, "disabled_by": null, "disabled_polling": false, "name": "Smart Socket", "model": "\u6b27\u89c4\uff0c10A\uff0c\u5e26\u8ba1\u7535\u91cf\uff0c\u652f\u6301\u9177\u5ba2RF\u4ea7\u6d4b", "category": "cz", "product_id": "wifvoilfrqeo6hvu", "product_name": "Smart Socket", "online": true, "sub": false, "time_zone": "+01:00", "active_time": "2022-02-27T19:13:33+00:00", "create_time": "2022-02-27T18:07:20+00:00", "update_time": "2022-02-27T19:21:55+00:00", "function": { "switch_1": { "type": "Boolean", "value": {} }, "countdown_1": { "type": "Integer", "value": { "min": 0, "scale": 0, "unit": "\u79d2", "max": 86400, "step": 1 } } }, "status_range": { "switch_1": { "type": "Boolean", "value": {} }, "countdown_1": { "type": "Integer", "value": { "min": 0, "scale": 0, "unit": "\u79d2", "max": 86400, "step": 1 } }, "add_ele": { "type": "Integer", "value": { "min": 0, "scale": 0, "unit": "\u5ea6", "max": 500000, "step": 100 } }, "cur_current": { "type": "Integer", "value": { "min": 0, "scale": 0, "unit": "mA", "max": 30000, "step": 1 } }, "cur_power": { "type": "Integer", "value": { "min": 0, "scale": 0, "unit": "W", "max": 50000, "step": 1 } }, "cur_voltage": { "type": "Integer", "value": { "min": 0, "unit": "V", "scale": 0, "max": 2500, "step": 1 } } }, "status": { "switch_1": true, "countdown_1": 0, "add_ele": 10, "cur_current": 30, "cur_power": 70, "cur_voltage": 2302 }, "home_assistant": { "name": "Smart Socket", "name_by_user": null, "disabled": false, "disabled_by": null, "entities": [ { "disabled": false, "disabled_by": null, "entity_category": null, "device_class": "current", "original_device_class": "current", "icon": null, "original_icon": null, "unit_of_measurement": "A", "state": { "entity_id": "sensor.smart_socket_current", "state": "0.03", "attributes": { "state_class": "measurement", "unit_of_measurement": "A", "device_class": "current", "friendly_name": "Smart Socket Current" }, "last_changed": "2022-02-27T19:35:31.549503+00:00", "last_updated": "2022-02-27T19:35:31.549503+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": null, "device_class": "power", "original_device_class": "power", "icon": null, "original_icon": null, "unit_of_measurement": "W", "state": { "entity_id": "sensor.smart_socket_power", "state": "70.0", "attributes": { "state_class": "measurement", "unit_of_measurement": "W", "device_class": "power", "friendly_name": "Smart Socket Power" }, "last_changed": "2022-02-27T19:35:31.549829+00:00", "last_updated": "2022-02-27T19:35:31.549829+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": null, "device_class": "voltage", "original_device_class": "voltage", "icon": null, "original_icon": null, "unit_of_measurement": "V", "state": { "entity_id": "sensor.smart_socket_voltage", "state": "2302.0", "attributes": { "state_class": "measurement", "unit_of_measurement": "V", "device_class": "voltage", "friendly_name": "Smart Socket Voltage" }, "last_changed": "2022-02-27T19:35:21.481314+00:00", "last_updated": "2022-02-27T19:35:21.481314+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": null, "device_class": null, "original_device_class": "outlet", "icon": null, "original_icon": null, "unit_of_measurement": null, "state": { "entity_id": "switch.smart_socket_socket_1", "state": "on", "attributes": { "device_class": "outlet", "friendly_name": "Smart Socket Socket 1" }, "last_changed": "2022-02-27T19:25:27.846560+00:00", "last_updated": "2022-02-27T19:25:27.846560+00:00" } } ] } } }

hermanops commented 2 years ago

A temporary solution would be:


- platform: template
  sensors:
    smart_socket_a1_power_corrected:
      friendly_name: "Smart Socket A1 Power Corected"
      unit_of_measurement: "W"
      value_template: "{{ '%4.1f'%(states('sensor.smart_socket_a1_power')|float(0) / (10)) | float(0) }}"
      device_class: power
      unique_id: smart_socket_a1_power_corrected

    smart_socket_a1_voltage_corrected:
      friendly_name: "Smart Socket A1 Voltage Corrected"
      unit_of_measurement: "V"
      value_template: "{{ '%3.1f'%(states('sensor.smart_socket_a1_voltage')|float(0) / (10)) | float(0) }}"
      device_class: voltage
      unique_id: smart_socket_a1_voltage_corrected
car1ox commented 2 years ago

@hermanops thanks for the workarround but I think that it will not work as I have seen that the reporting error is somehow random in Home Assistant, while it is fine in the Tuya app.

Edit: Most pobably HA is wrongly reporting x10 all the time.

The graph is the power reported by Home Assistant, the lower part is arround 2.300 W that is right and the top is 23.000 W that is clearly wrong.

image

IonutDanNica commented 2 years ago

I have a Gosun SP111-A plug and I'm running HA 2022.2.9 + tuya integration. For me, just the voltage is wrong, it is most likely 10 times bigger than actual value. So the smartlife App is showing correct voltage.

the tuya IOT website is showing voltage 2200V

Time | Device Event | DP ID | Event Details | Source | Source Details -- | -- | -- | -- | -- | -- 2022-03-02 15:40:29 | Report | Voltage | 2125V | device itself |   2022-03-02 15:38:29 | Report | Voltage | 2162V | device itself

So could it be that the Tuya portal shows some bad raw data? tuya-0d687989bbb92fa636b44e7f8b70de09-Zeus Socket-7097c1884acd8b0ab3414edaa54b2043.json.txt

hermanops commented 2 years ago

@josecarlosfernandez : so it's not random, right?

car1ox commented 2 years ago

No, it is not random, consistently 10 times the real measurement.

proffa84 commented 2 years ago

Like in LocalTuya, thera are scaling factor

Tuya_Scaling_Factor

crus1313 commented 2 years ago

Like in LocalTuya, thera are scaling factor

Tuya_Scaling_Factor

Where is this menu? I cannot find int. thx

ronpotter271 commented 2 years ago

when u add a new sensor to a the local tuya device that will show up

krzwiatrzyk commented 2 years ago

Any fix for this issue? I have the same incorrect readings, sensors voltage (and thus power) is 10x times bigger than the correct values.

I use Gosund SP-111A Smart Plug attached to Tuya (Cloud) and integrated to HA.

mycrouch commented 2 years ago

Any fix for this issue? I have the same incorrect readings, sensors voltage (and thus power) is 10x times bigger than the correct values.

I use Gosund SP-111A Smart Plug attached to Tuya (Cloud) and integrated to HA.

I create a sensor for each value I wish to correct that divides by 10%

`sensor:

stevedee78 commented 2 years ago

Can someone explain to me exactly how I convert this into HA?For example my sensor is "sensor.kuhlschrank_power".

hugoheinzson commented 1 year ago

I've had a conversation with the tuya support. That's what they answered:

This is fine and acceptable and has then to be fixed in HA.

So, for me it seems to depend on the kind of device tuya is delivering. Since I have different tuya devices, some deliver the "right" Watts, some not.

I've helped myself with creating a custom sensor THIS VIDEO helped me with that.

Summary:

The only problem i'm facing right now is how to tell the custom sensor that it belongs to the "mother"-Smartplug as a sub-entity - but google might fix that.

As wish for this issue: the Tuya Integration should be able to handle those different watt/volts information from tuya!

HuismAndre commented 1 year ago

The Tuya HA integration uses the following setting for devices that give the wrong voltage:

"cur_voltage": { "type": "Integer", "value": { "min": 0, "unit": "V", "scale": 0, "max": 2500, "step": 1

According to the Tuya documentation, voltage scaling should be:

{“unit”:“v”,“min”:0,“max”:50000,“scale”:1,“step”:1}

The reason for that is because the value is an integer (and you to scale it down in order to be able to represent for example 232,4V).

Scaling for current is 0 (since current is in mA) and for power is 0 too. Power is probably derived from current and voltage (so if voltage is off by a factor of 10 then power will probably be off by a factor of 10 as well).

https://developer.tuya.com/en/docs/iot/switch-socket-and-power-strip?id=K9gf7o5prgf7s

VIMVa commented 1 year ago

I tried the template solution but I am not a technical guy and complete newbie. Apparently I'm completely wrong (and in the dark). Is there a good soul who is willing to have a look?

My complete configuration.yaml:

Configure a default setup of Home Assistant (frontend, api, etc)

default_config:

Text to speech

tts:

group: !include groups.yaml automation: !include automations.yaml script: !include scripts.yaml scene: !include scenes.yaml template: !include template.yaml

homeassistant: allowlist_external_dirs:

sensor:

recorder: purge_keep_days: 367

The error I get when reloading the configuration: "Unable to reload the configuration: Cannot quick reload all YAML configurations because the configuration is not valid: Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']. Got None extra keys not allowed @ data['friendly_name']. Got 'Plug Voltage' extra keys not allowed @ data['smart_plug_voltage_round']. Got None extra keys not allowed @ data['unit_of_measurement']. Got 'V' extra keys not allowed @ data['value_template']. Got "{{ '%3.1f'%(states('sensor.smart_energy_meter_voltage')|float * (10)) | float }}". (See ?, line ?)."

mycrouch commented 1 year ago

Some promise in the latest HA release with Sensor display precision. No need for a template. Updating now to do some testing. Might not solve the current issue but headed in the right direction.

https://www.home-assistant.io/blog/2023/03/01/release-20233/#sensor-display-precision

psychowood commented 1 year ago

Nope, sorry. Sensor precision does not change the value, only the presented decimals.