0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
225 stars 68 forks source link

power consumption remains the same #268

Open svenkopp opened 1 year ago

svenkopp commented 1 year ago

Prerequisite

Version

1.7.0-beta.33

Device Infomation JSON File

[
  {
    "active_time": 1676041875,
    "biz_type": 0,
    "category": "cz",
    "create_time": 1676041875,
    "icon": "smart/icon/ay1567515183020AepWs/f19c907ac8893fb78873c9e5ca868c55.png",
    "id": "bf2f8b196651cebebe7bbd",
    "model": "3235",
    "name": "Warmtepomp",
    "online": true,
    "product_id": "wyishxl59fefa00i",
    "product_name": "Silvergear Smart Socket",
    "status": [
      {
        "code": "add_ele",
        "value": 1
      },
      {
        "code": "child_lock",
        "value": false
      },
      {
        "code": "countdown_1",
        "value": 0
      },
      {
        "code": "cur_current",
        "value": 0
      },
      {
        "code": "cur_power",
        "value": 0
      },
      {
        "code": "cur_voltage",
        "value": 2268
      },
      {
        "code": "cycle_time",
        "value": ""
      },
      {
        "code": "light_mode",
        "value": "relay"
      },
      {
        "code": "overcharge_switch",
        "value": false
      },
      {
        "code": "random_time",
        "value": ""
      },
      {
        "code": "relay_status",
        "value": "power_on"
      },
      {
        "code": "switch_1",
        "value": true
      },
      {
        "code": "switch_inching",
        "value": ""
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "eu1635784823390FzK0b",
    "update_time": 1679462614,
    "uuid": "6734ad11e84dadc2",
    "schema": [
      {
        "code": "add_ele",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "min": 0,
          "max": 50000,
          "scale": 3,
          "step": 100
        }
      },
      {
        "code": "child_lock",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "countdown_1",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "cur_current",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "mA",
          "min": 0,
          "max": 30000,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "cur_power",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "W",
          "min": 0,
          "max": 80000,
          "scale": 1,
          "step": 1
        }
      },
      {
        "code": "cur_voltage",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "V",
          "min": 0,
          "max": 5000,
          "scale": 1,
          "step": 1
        }
      },
      {
        "code": "cycle_time",
        "mode": "rw",
        "type": "String",
        "property": {}
      },
      {
        "code": "light_mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "relay",
            "pos",
            "none"
          ]
        }
      },
      {
        "code": "overcharge_switch",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "random_time",
        "mode": "rw",
        "type": "String",
        "property": {}
      },
      {
        "code": "relay_status",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "power_off",
            "power_on",
            "last"
          ]
        }
      },
      {
        "code": "switch_1",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "switch_inching",
        "mode": "rw",
        "type": "String",
        "property": {}
      }
    ]
  },
  {
    "active_time": 1676038291,
    "biz_type": 0,
    "category": "cz",
    "create_time": 1676038291,
    "icon": "smart/icon/ay1567515183020AepWs/f19c907ac8893fb78873c9e5ca868c55.png",
    "id": "bf57dcbce679cff5d5xypt",
    "model": "3235",
    "name": "Ventilatie unit",
    "online": true,
    "product_id": "wyishxl59fefa00i",
    "product_name": "Silvergear Smart Socket",
    "status": [
      {
        "code": "add_ele",
        "value": 1
      },
      {
        "code": "child_lock",
        "value": false
      },
      {
        "code": "countdown_1",
        "value": 0
      },
      {
        "code": "cur_current",
        "value": 0
      },
      {
        "code": "cur_power",
        "value": 0
      },
      {
        "code": "cur_voltage",
        "value": 2262
      },
      {
        "code": "cycle_time",
        "value": ""
      },
      {
        "code": "light_mode",
        "value": "relay"
      },
      {
        "code": "overcharge_switch",
        "value": false
      },
      {
        "code": "random_time",
        "value": ""
      },
      {
        "code": "relay_status",
        "value": "power_on"
      },
      {
        "code": "switch_1",
        "value": true
      },
      {
        "code": "switch_inching",
        "value": ""
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "eu1635784823390FzK0b",
    "update_time": 1678771429,
    "uuid": "71ca4dfde254092a",
    "schema": [
      {
        "code": "add_ele",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "min": 0,
          "max": 50000,
          "scale": 3,
          "step": 100
        }
      },
      {
        "code": "child_lock",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "countdown_1",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "cur_current",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "mA",
          "min": 0,
          "max": 30000,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "cur_power",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "W",
          "min": 0,
          "max": 80000,
          "scale": 1,
          "step": 1
        }
      },
      {
        "code": "cur_voltage",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "V",
          "min": 0,
          "max": 5000,
          "scale": 1,
          "step": 1
        }
      },
      {
        "code": "cycle_time",
        "mode": "rw",
        "type": "String",
        "property": {}
      },
      {
        "code": "light_mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "relay",
            "pos",
            "none"
          ]
        }
      },
      {
        "code": "overcharge_switch",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "random_time",
        "mode": "rw",
        "type": "String",
        "property": {}
      },
      {
        "code": "relay_status",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "power_off",
            "power_on",
            "last"
          ]
        }
      },
      {
        "code": "switch_1",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "switch_inching",
        "mode": "rw",
        "type": "String",
        "property": {}
      }
    ]
  },
  {
    "active_time": 1676066616,
    "biz_type": 0,
    "category": "cz",
    "create_time": 1676066616,
    "icon": "smart/icon/ay1567515183020AepWs/f19c907ac8893fb78873c9e5ca868c55.png",
    "id": "bfc9a14b802d289225v2xh",
    "model": "3235",
    "name": "Badkamer verwarming",
    "online": true,
    "product_id": "wyishxl59fefa00i",
    "product_name": "Silvergear Smart Socket",
    "status": [
      {
        "code": "add_ele",
        "value": 62
      },
      {
        "code": "child_lock",
        "value": false
      },
      {
        "code": "countdown_1",
        "value": 0
      },
      {
        "code": "cur_current",
        "value": 0
      },
      {
        "code": "cur_power",
        "value": 0
      },
      {
        "code": "cur_voltage",
        "value": 2271
      },
      {
        "code": "cycle_time",
        "value": ""
      },
      {
        "code": "light_mode",
        "value": "relay"
      },
      {
        "code": "overcharge_switch",
        "value": false
      },
      {
        "code": "random_time",
        "value": ""
      },
      {
        "code": "relay_status",
        "value": "last"
      },
      {
        "code": "switch_1",
        "value": false
      },
      {
        "code": "switch_inching",
        "value": ""
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "eu1635784823390FzK0b",
    "update_time": 1678771427,
    "uuid": "359a1c1c07eafdab",
    "schema": [
      {
        "code": "add_ele",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "min": 0,
          "max": 50000,
          "scale": 3,
          "step": 100
        }
      },
      {
        "code": "child_lock",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "countdown_1",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "cur_current",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "mA",
          "min": 0,
          "max": 30000,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "cur_power",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "W",
          "min": 0,
          "max": 80000,
          "scale": 1,
          "step": 1
        }
      },
      {
        "code": "cur_voltage",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "V",
          "min": 0,
          "max": 5000,
          "scale": 1,
          "step": 1
        }
      },
      {
        "code": "cycle_time",
        "mode": "rw",
        "type": "String",
        "property": {}
      },
      {
        "code": "light_mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "relay",
            "pos",
            "none"
          ]
        }
      },
      {
        "code": "overcharge_switch",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "random_time",
        "mode": "rw",
        "type": "String",
        "property": {}
      },
      {
        "code": "relay_status",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "power_off",
            "power_on",
            "last"
          ]
        }
      },
      {
        "code": "switch_1",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "switch_inching",
        "mode": "rw",
        "type": "String",
        "property": {}
      }
    ]
  },
  {
    "active_time": 1672319890,
    "biz_type": 0,
    "category": "dj",
    "create_time": 1635784583,
    "icon": "smart/icon/ay1541056239985fDGjj/300d549b11618ebe32f08dbfe4d868df.png",
    "id": "bf01d4890f3db64d49gkyt",
    "model": "灯带-五色-三键-红外+wifi-板载-calex",
    "name": "klok",
    "online": true,
    "product_id": "vqwcnabamzrc2kab",
    "product_name": "Light Strip-RGBCW ",
    "status": [
      {
        "code": "bright_value_v2",
        "value": 390
      },
      {
        "code": "colour_data_v2",
        "value": "{\"h\":35,\"s\":800,\"v\":1000}"
      },
      {
        "code": "control_data",
        "value": ""
      },
      {
        "code": "countdown_1",
        "value": 0
      },
      {
        "code": "music_data",
        "value": ""
      },
      {
        "code": "remote_switch",
        "value": true
      },
      {
        "code": "scene_data_v2",
        "value": "{\"scene_num\":2,\"scene_units\":[{\"bright\":1000,\"h\":0,\"s\":0,\"temperature\":500,\"unit_change_mode\":\"static\",\"unit_gradient_duration\":13,\"unit_switch_duration\":14,\"v\":0}]}"
      },
      {
        "code": "switch_led",
        "value": false
      },
      {
        "code": "temp_value_v2",
        "value": 608
      },
      {
        "code": "work_mode",
        "value": "colour"
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "eu1635784823390FzK0b",
    "update_time": 1678771426,
    "uuid": "8e013b9ba7bb7357",
    "schema": [
      {
        "code": "bright_value_v2",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "min": 10,
          "max": 1000,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "colour_data_v2",
        "mode": "rw",
        "type": "Json",
        "property": {
          "h": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 360,
            "step": 1
          },
          "s": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 1000,
            "step": 1
          },
          "v": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 1000,
            "step": 1
          }
        }
      },
      {
        "code": "control_data",
        "mode": "rw",
        "type": "Json",
        "property": {
          "change_mode": {
            "range": [
              "direct",
              "gradient"
            ]
          },
          "bright": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 1000,
            "step": 1
          },
          "temperature": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 1000,
            "step": 1
          },
          "h": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 360,
            "step": 1
          },
          "s": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 255,
            "step": 1
          },
          "v": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 255,
            "step": 1
          }
        }
      },
      {
        "code": "countdown_1",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "music_data",
        "mode": "rw",
        "type": "Json",
        "property": {
          "change_mode": {
            "range": [
              "direct",
              "gradient"
            ]
          },
          "bright": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 1000,
            "step": 1
          },
          "temperature": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 1000,
            "step": 1
          },
          "h": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 360,
            "step": 1
          },
          "s": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 255,
            "step": 1
          },
          "v": {
            "min": 0,
            "scale": 0,
            "unit": "",
            "max": 255,
            "step": 1
          }
        }
      },
      {
        "code": "remote_switch",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "scene_data_v2",
        "mode": "rw",
        "type": "Json",
        "property": {
          "scene_num": {
            "min": 1,
            "scale": 0,
            "max": 8,
            "step": 1
          },
          "scene_units": {
            "unit_change_mode": {
              "range": [
                "static",
                "jump",
                "gradient"
              ]
            },
            "unit_switch_duration": {
              "min": 0,
              "scale": 0,
              "max": 100,
              "step": 1
            },
            "unit_gradient_duration": {
              "min": 0,
              "scale": 0,
              "max": 100,
              "step": 1
            },
            "bright": {
              "min": 0,
              "scale": 0,
              "max": 1000,
              "step": 1
            },
            "temperature": {
              "min": 0,
              "scale": 0,
              "max": 1000,
              "step": 1
            },
            "h": {
              "min": 0,
              "scale": 0,
              "unit": "",
              "max": 360,
              "step": 1
            },
            "s": {
              "min": 0,
              "scale": 0,
              "unit": "",
              "max": 1000,
              "step": 1
            },
            "v": {
              "min": 0,
              "scale": 0,
              "unit": "",
              "max": 1000,
              "step": 1
            }
          }
        }
      },
      {
        "code": "switch_led",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "temp_value_v2",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "min": 0,
          "max": 1000,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "work_mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "white",
            "colour",
            "scene",
            "music"
          ]
        }
      }
    ]
  }
]

Device Control Mode

Standard Instruction

Logs

No response

Other Infomations

The consumption remains the same while the power plug is switched off, in the tuya app the consumption is zero. And other plugs that give zero while they consume something.

0x5e commented 1 year ago

can you post some photos? you mean total power consumption or real time power?

svenkopp commented 1 year ago

Its both. But the most importend for me is the real time power.

image

image

0x5e commented 1 year ago

can you see if homebridge accessory page can show the power related info? are they the same value as tuya app? I have no idea yet :(

svenkopp commented 1 year ago

image

I get this in de Homebridge logs. And this is good i think.

svenkopp commented 1 year ago

It did work for but after the update is stopped working.

0x5e commented 1 year ago

274

cbornBerlin commented 11 months ago

I am having the same problem and tried everything mentioned in #274. Everything works like a charm but the sensor data for power consumption (cur_power) doesnt update in Homebridge. I have set the devices (cz, outlet) to DP instruction and the Tuya debugging shows the correct value. Yet, Homebridge doesnt update the power consumption. Any ideas on what I can try to mitigate this? It is mentioned that one should open up a ticket at Tuya but I dont know what to ask them to do actually. Appreciate any help on this. Thanks!

EDIT: There are no errors in the log. API connects (MQ) correctly and all devices are added as intented. It is just the power consumption that doesnt get updated. Its not updating at all after initial adding of devices. So the problem is not that the update doesnt happen regularly. It doesnt happen at all.

vfontes commented 10 months ago

I'm having the same issue, but voltage, consumption and current are not updated. Clearing accessory cache fixes it temporarily, but after restarting Homebridge the values no longer are updated.

Tuya IOT cloud confirms the values are being updated:

Screenshot 2024-01-12 at 11 40 35
cbornBerlin commented 10 months ago

I can confirm that Tuya IoT platform updates just fine for my devices as well. There seems to be some problem either with this plugin or with the API this plugin uses.

vfontes commented 10 months ago

When enabling debug logging in the plugin, this is how the updates show up:

[1/12/2024, 12:23:25 PM] [Tuya] [Escritório Nobreak Mesa] [Outlet/switch_1/Amperes] Update value: 0.864 => 0.852
[1/12/2024, 12:23:25 PM] [Tuya] [Escritório Nobreak Mesa] [Outlet/switch_1/Watts] Update value: 90.2 => 88.4
[1/12/2024, 12:23:25 PM] [Tuya] [Escritório Nobreak Mesa] [Outlet/switch_1/Volts] Update value: 119.8 => 118.1

However, after restarting Homebridge, these updates no longer show up. Removing the cached accessory fixes the issue until Homebridge is restarted.

vfontes commented 10 months ago

I've enabled Homebridge debug logs, and it seems like the plugin is getting the data from the cloud, but is not updating the values for some reason.

Here's the logs when it works:

[1/12/2024, 1:23:56 PM] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/new0fc7e8c1a59d9e93a873cdb8ab2c50d1
protocol = 4
message = {
  "devId": "REDACTED",
  "dataId": "ad2c5989-72f2-48e9-b4e4-f85696507303",
  "productKey": "REDACTED",
  "status": [
    {
      "18": 987,
      "code": "cur_current",
      "t": 1705076636,
      "value": 987
    },
    {
      "19": 983,
      "code": "cur_power",
      "t": 1705076636,
      "value": 983
    },
    {
      "20": 1174,
      "code": "cur_voltage",
      "t": 1705076636,
      "value": 1174
    }
  ]
}
t = 1705076636
[1/12/2024, 1:23:56 PM] [Tuya] [Escritório Nobreak Mesa] [Outlet/switch_1/Amperes] Update value: 0.742 => 0.987
[1/12/2024, 1:23:56 PM] [Tuya] [Escritório Nobreak Mesa] [Outlet/switch_1/Watts] Update value: 80.4 => 98.3
[1/12/2024, 1:23:56 PM] [Tuya] [Escritório Nobreak Mesa] [Outlet/switch_1/Volts] Update value: 117.9 => 117.4

And here's the logs when it does not work:

[1/12/2024, 1:32:07 PM] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/new0fc7e8c1a59d9e93a873cdb8ab2c50d1
protocol = 4
message = {
  "devId": "REDACTED",
  "dataId": "cdac07e7-f084-443d-be82-49f448521cb0",
  "productKey": "REDACTED",
  "status": [
    {
      "18": 923,
      "code": "cur_current",
      "t": 1705077127,
      "value": 923
    },
    {
      "19": 954,
      "code": "cur_power",
      "t": 1705077127,
      "value": 954
    },
    {
      "20": 1174,
      "code": "cur_voltage",
      "t": 1705077127,
      "value": 1174
    }
  ]
}
t = 1705077127

As always, clearing the accessory cache makes it work again, until the next restart.

0x5e commented 10 months ago

@vfontes Thanks for the information, I guess the issue is located on the way of adding characteristic in EnergyUsage.ts I don't have such device, please help to test if 1.7.0-beta.53 fixed

vfontes commented 10 months ago

It didn’t fix it, unfortunately. Same exact situation as before. On 13 Jan 2024, at 06:15, gaosen @.***> wrote: @vfontes Thanks for the information, I guess the issue is located on the way of adding characteristic in EnergyUsage.ts I don't have such device, please help to test if 1.7.0-beta.53 fixed

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

cbornBerlin commented 10 months ago

@0x5e Thanks for working on this. Much appreciated. I have now tested this and can share the following observations.

All in all, I would say, that it does the job. If possible, it might be convenient if updates would get fetched more consistently (frequency-wise).

0x5e commented 10 months ago

@cbornBerlin The update frequency is decided by the device's firmware, homebridge plugin is not able to change this. What I can do is to fix "data not get update everytime when homebridge restarted", but seems not working :(

vfontes commented 10 months ago

@0x5e is there anything else I can provide you to help fix this issue?

0x5e commented 10 months ago

Can you confirm version is beta.53 and clear cache once after upgrade? I have no idea yet. @vfontes

vfontes commented 10 months ago

Sorry, I had upgraded to beta.53 but I hadn't removed the outlet accessories from the cache.

I did just that and it seems like it is updating the values after Homebridge restarts! I'll do some more tests, but the outlook is pretty good.