home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.73k stars 30.46k forks source link

Expose Tuya energy sensor #71649

Closed yuvalabou closed 2 years ago

yuvalabou commented 2 years ago

The problem

Currently the switch sensors does not provide energy metering, However those readings are present on the app as well as in diagnostics data ("add_ele" key which is currently at 0) but still missing from the sensors provided by the integration.

What version of Home Assistant Core has the issue?

2022.05

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Tuya

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tuya/

Diagnostics information

{
  "home_assistant": {
    "installation_type": "Home Assistant Container",
    "version": "2022.5.0",
    "dev": false,
    "hassio": false,
    "virtualenv": false,
    "python_version": "3.9.9",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Asia/Jerusalem",
    "os_name": "Linux",
    "os_version": "5.15.25-rockchip64",
    "run_as_root": true
  },
  "custom_components": {
    "smartthinq_sensors": {
      "version": "0.13.0",
      "requirements": [
        "pycountry\u003e\u003d20.7.3",
        "xmltodict\u003e\u003d0.12.0"
      ]
    },
    "thermal_comfort": {
      "version": "1.4.3",
      "requirements": []
    },
    "watchman": {
      "version": "0.2.5",
      "requirements": [
        "prettytable\u003d\u003d3.0.0"
      ]
    },
    "hacs": {
      "version": "1.24.5",
      "requirements": [
        "aiogithubapi\u003e\u003d21.11.0"
      ]
    },
    "xiaomi_cloud_map_extractor": {
      "version": "v2.1.5",
      "requirements": [
        "pillow",
        "pybase64",
        "python-miio",
        "requests",
        "pycryptodome"
      ]
    },
    "pyscript": {
      "version": "1.3.3",
      "requirements": [
        "croniter\u003d\u003d1.3.4",
        "watchdog\u003d\u003d2.1.6"
      ]
    },
    "home_connect_alt": {
      "version": "0.4.4",
      "requirements": [
        "home-connect-async\u003d\u003d0.6.3"
      ]
    },
    "feedparser": {
      "version": "0.1.7",
      "requirements": [
        "feedparser\u003d\u003d6.0.8"
      ]
    }
  },
  "integration_manifest": {
    "domain": "tuya",
    "name": "Tuya",
    "documentation": "https://www.home-assistant.io/integrations/tuya",
    "requirements": [
      "tuya-iot-py-sdk\u003d\u003d0.6.6"
    ],
    "dependencies": [
      "ffmpeg"
    ],
    "codeowners": [
      "@Tuya",
      "@zlinoliver",
      "@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*"
      }
    ],
    "loggers": [
      "tuya_iot"
    ],
    "is_built_in": true
  },
  "data": {
    "endpoint": "https://openapi.tuyaeu.com",
    "auth_type": 0,
    "country_code": "972",
    "app_type": "tuyaSmart",
    "mqtt_connected": true,
    "disabled_by": null,
    "disabled_polling": false,
    "name": "DELTACO SH-P02",
    "model": "SH-P02",
    "category": "pc",
    "product_id": "kiqzy4lajnailxsz",
    "product_name": "DELTACO SH-P02",
    "online": true,
    "sub": false,
    "time_zone": "+02:00",
    "active_time": "2021-12-16T21:32:26+00:00",
    "create_time": "2021-12-16T21:32:26+00:00",
    "update_time": "2022-05-10T12:52:24+00:00",
    "function": {
      "switch_1": {
        "type": "Boolean",
        "value": {}
      },
      "switch_2": {
        "type": "Boolean",
        "value": {}
      },
      "countdown_1": {
        "type": "Integer",
        "value": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      "countdown_2": {
        "type": "Integer",
        "value": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      }
    },
    "status_range": {
      "switch_1": {
        "type": "Boolean",
        "value": {}
      },
      "switch_2": {
        "type": "Boolean",
        "value": {}
      },
      "countdown_1": {
        "type": "Integer",
        "value": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      "countdown_2": {
        "type": "Integer",
        "value": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      "add_ele": {
        "type": "Integer",
        "value": {
          "unit": "",
          "min": 0,
          "max": 50000,
          "scale": 3,
          "step": 100
        }
      },
      "cur_current": {
        "type": "Integer",
        "value": {
          "unit": "mA",
          "min": 0,
          "max": 30000,
          "scale": 0,
          "step": 1
        }
      },
      "cur_power": {
        "type": "Integer",
        "value": {
          "unit": "W",
          "min": 0,
          "max": 50000,
          "scale": 1,
          "step": 1
        }
      },
      "cur_voltage": {
        "type": "Integer",
        "value": {
          "unit": "V",
          "min": 0,
          "max": 5000,
          "scale": 1,
          "step": 1
        }
      }
    },
    "status": {
      "switch_1": true,
      "switch_2": true,
      "countdown_1": 0,
      "countdown_2": 0,
      "add_ele": 0,
      "cur_current": 306,
      "cur_power": 350,
      "cur_voltage": 2416
    },
    "home_assistant": {
      "name": "DELTACO SH-P02",
      "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.deltaco_sh_p02_current",
            "state": "0.306",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "A",
              "device_class": "current",
              "friendly_name": "DELTACO SH-P02 Current"
            },
            "last_changed": "2022-05-10T16:14:50.826197+00:00",
            "last_updated": "2022-05-10T16:14:50.826197+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.deltaco_sh_p02_power",
            "state": "35.0",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "W",
              "device_class": "power",
              "friendly_name": "DELTACO SH-P02 Power"
            },
            "last_changed": "2022-05-10T16:14:55.830280+00:00",
            "last_updated": "2022-05-10T16:14:55.830280+00:00"
          }
        },
        {
          "disabled": true,
          "disabled_by": "integration",
          "entity_category": null,
          "device_class": null,
          "original_device_class": "voltage",
          "icon": null,
          "original_icon": null,
          "unit_of_measurement": "V",
          "state": null
        },
        {
          "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.deltaco_sh_p02_socket_1",
            "state": "on",
            "attributes": {
              "device_class": "outlet",
              "friendly_name": "DELTACO SH-P02 Socket 1"
            },
            "last_changed": "2022-05-10T16:14:00.289773+00:00",
            "last_updated": "2022-05-10T16:14:00.289773+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.deltaco_sh_p02_socket_2",
            "state": "on",
            "attributes": {
              "device_class": "outlet",
              "friendly_name": "DELTACO SH-P02 Socket 2"
            },
            "last_changed": "2022-05-10T16:14:00.291946+00:00",
            "last_updated": "2022-05-10T16:14:00.291946+00:00"
          }
        }
      ]
    }
  }
}

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Screenshot_2022-05-10-19-14-58-59_d448303990bb92d03c4d800220c6084a

probot-home-assistant[bot] commented 2 years ago

tuya documentation tuya source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @tuya, @zlinoliver, @frenck, mind taking a look at this issue as it has been labeled with an integration (tuya) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

frenck commented 2 years ago

add_ele is an incremental notification for the use or larger chunks of energy and is not a consistent value. Additionally, the Tuya API does not provide the total/current/past, or any other energy value that is usable.

At this point, this is not implementable for Home Assistant; as the data is simply not provided.

As a workaround, you can use Integration - Riemann sum integral to calculate the energy usage based on the power usage that is provided.

yuvalabou commented 2 years ago

Thank you frenck, what a bummer. Hope tuya will provide those values natively soon.