tuya-local icon indicating copy to clipboard operation
tuya-local copied to clipboard

New device - Compteur Digital Electric (power meter 1 phase)

Open Der-Nax opened this issue 3 years ago • 6 comments
trafficstars

I added new device. Please add in a new release.

name: Compteur Digital Electric
primary_entity:
  entity: sensor
  class: energy
  dps:
    - id: 17
      type: integer
      name: sensor
      mapping:
        - scale: 100
      unit: kWh
      class: total_increasing
secondary_entities:
  - entity: sensor
    category: diagnostic
    name: Voltage
    class: voltage
    dps:
      - id: 20
        name: sensor
        type: integer
        unit: V
        mapping:
          - scale: 10
  - entity: sensor
    category: diagnostic
    class: current
    name: Current
    dps:
      - id: 18
        name: sensor
        type: integer
        unit: A
        mapping:
          - scale: 1000
  - entity: sensor
    category: diagnostic
    class: power
    name: Power
    dps:
      - id: 19
        name: sensor
        type: integer
        unit: W

I have unknow dps:

  - entity: sensor
    category: diagnostic
    name: unknown_21
    dps:
      - id: 21
        name: sensor
        type: integer
  - entity: sensor
    category: diagnostic
    name: unknown_22
    dps:
      - id: 22
        name: sensor
        type: integer
  - entity: sensor
    category: diagnostic
    name: unknown_23
    dps:
      - id: 23
        name: sensor
        type: integer
  - entity: sensor
    category: diagnostic
    name: unknown_24
    dps:
      - id: 24
        name: sensor
        type: integer
  - entity: sensor
    category: diagnostic
    name: unknown_25
    dps:
      - id: 25
        name: sensor
        type: integer
  - entity: sensor
    category: diagnostic
    name: unknown_26
    dps:
      - id: 26
        name: sensor
        type: integer

but it is static and it don't exist in tuya iot portal.

Additional about device - "product_id": "1whdy4a8ypamjloi". I don't add this parameter into my config. You are owner of final product and I think that I should provide maximum information about it for you. Thank you for you time and work!

Der-Nax avatar Jul 19 '22 21:07 Der-Nax

I would put the unknown dps as extra attributes on the primary entity. It isn't really useful to break them out into individual sensors until you know what they mean. The product id is not currently used, but if known it may be useful in future for unambiguously identifying the config for a device, so the syntax for adding it into the config is already defined:

product:
  - id: 1whdy4a8ypamjloi

with optional name: as well, in case multiple devices are covered by one config (the matching product name is intended to override the global name in this case).

make-all avatar Jul 20 '22 01:07 make-all

I'm sorry. I found mistakes in my file. Please use V2 zip smartpowermeter1_V2.zip The errors were in scale of 2 sensors. Info from IoT: { "result": { "category": "cz", "functions": [], "status": [ { "code": "add_ele", "dp_id": 17, "type": "Integer", "values": "{"unit":"kwh","min":0,"max":50000,"scale":3,"step":100}" }, { "code": "cur_current", "dp_id": 18, "type": "Integer", "values": "{"unit":"mA","min":0,"max":70000,"scale":0,"step":1}" }, { "code": "cur_power", "dp_id": 19, "type": "Integer", "values": "{"unit":"W","min":0,"max":9999999,"scale":1,"step":1}" }, { "code": "cur_voltage", "dp_id": 20, "type": "Integer", "values": "{"unit":"V","min":0,"max":5000,"scale":1,"step":1}" } ] }, "success": true, "t": XXX, "tid": "XXX" }

Der-Nax avatar Jul 20 '22 19:07 Der-Nax

Available in 0.18.1

make-all avatar Jul 24 '22 10:07 make-all

I updated integration. But device was not working. I will need to add my files to device folder. I have not time to undestand the problem. Sorry. Could you please provide name of file which you add? I'll try to check.

Der-Nax avatar Jul 28 '22 17:07 Der-Nax

You can see the change at the link to the commit above. compteur_energy_meter.yaml was the name of the config file.

make-all avatar Aug 02 '22 06:08 make-all

Hi @make-all @Der-Nax sorry to bring back a closed issue, I installed this device today, the instant readings work well (voltage, current, power) but the KWh energy sensor always reports 0.1. So I don't get the energy dashboard chart. Am I doing something wrong? Here is my full diagnostics

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.12.8",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.7",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Europe/Rome",
    "os_name": "Linux",
    "os_version": "5.15.76-v8",
    "supervisor": "2022.12.1",
    "host_os": "Home Assistant OS 9.4",
    "docker_version": "20.10.19",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "garbage_collection": {
      "version": "4.10.2",
      "requirements": [
        "python-dateutil>=2.8.2"
      ]
    },
    "tuya_local": {
      "version": "2022.12.1",
      "requirements": [
        "pycryptodome~=3.16.0",
        "tinytuya==1.9.1"
      ]
    },
    "hacs": {
      "version": "1.29.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    }
  },
  "integration_manifest": {
    "domain": "tuya_local",
    "iot_class": "local_polling",
    "integration_type": "device",
    "name": "Tuya Local",
    "version": "2022.12.1",
    "documentation": "https://github.com/make-all/tuya-local",
    "issue_tracker": "https://github.com/make-all/tuya-local/issues",
    "dependencies": [],
    "codeowners": [
      "@make-all"
    ],
    "requirements": [
      "pycryptodome~=3.16.0",
      "tinytuya==1.9.1"
    ],
    "config_flow": true,
    "is_built_in": false
  },
  "data": {
    "name": "Energy Meter",
    "type": "compteur_energy_meter",
    "device_id": "**REDACTED**",
    "local_key": "**REDACTED**",
    "host": "**REDACTED**",
    "protocol_version": "auto",
    "api_version": 3.3,
    "status": {},
    "cached_state": {
      "updated_at": 1672413714.358312,
      "17": 100,
      "18": 2170,
      "19": 3624,
      "20": 2246,
      "21": 1,
      "22": 581,
      "23": 14197,
      "24": 7733,
      "25": 1344,
      "26": 0
    },
    "pending_state": {},
    "home_assistant": {
      "name": "Energy Meter",
      "name_by_user": null,
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": "energy",
          "icon": null,
          "unit_of_measurement": "kWh",
          "state": {
            "entity_id": "sensor.energy_meter",
            "state": "0.1",
            "attributes": {
              "state_class": "total_increasing",
              "unknown_21": 1,
              "unknown_22": 581,
              "unknown_23": 14197,
              "unknown_24": 7733,
              "unknown_25": 1344,
              "unknown_26": 0,
              "unit_of_measurement": "kWh",
              "device_class": "energy",
              "friendly_name": "Energy Meter"
            },
            "last_changed": "2022-12-30T14:00:24.841513+00:00",
            "last_updated": "2022-12-30T14:00:24.841513+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "voltage",
          "icon": null,
          "unit_of_measurement": "V",
          "state": {
            "entity_id": "sensor.energy_meter_voltage",
            "state": "224.6",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "V",
              "device_class": "voltage",
              "friendly_name": "Energy Meter Voltage"
            },
            "last_changed": "2022-12-30T15:05:24.555261+00:00",
            "last_updated": "2022-12-30T15:05:24.555261+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "current",
          "icon": null,
          "unit_of_measurement": "A",
          "state": {
            "entity_id": "sensor.energy_meter_current",
            "state": "2.17",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "A",
              "device_class": "current",
              "friendly_name": "Energy Meter Current"
            },
            "last_changed": "2022-12-30T15:05:24.556916+00:00",
            "last_updated": "2022-12-30T15:05:24.556916+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "power",
          "icon": null,
          "unit_of_measurement": "W",
          "state": {
            "entity_id": "sensor.energy_meter_power",
            "state": "362.4",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "W",
              "device_class": "power",
              "friendly_name": "Energy Meter Power"
            },
            "last_changed": "2022-12-30T15:05:24.558089+00:00",
            "last_updated": "2022-12-30T15:05:24.558089+00:00"
          }
        }
      ]
    }
  }
}

Pimentoso avatar Dec 30 '22 15:12 Pimentoso

This was my experience with Tuya devices that have an energy reading also. Once they have reported to the cloud, they seem to reset, so you only ever see 0 or 1 on that attribute. So in Home Assistant you will need to set up an integration helper to calculate energy usage from the power reading instead of reading the energy directly from the device.

make-all avatar Dec 31 '22 00:12 make-all

I probably got how it works, fumbling around in the Tuya API explorer I noticed the sensor name is actually "Add electricity" and always returns 0.1. So I think it triggers an event every time the energy consumption increases by 0.1kwh. The correct way to display the energy consumption should be gather all this events and sum them, but I have no idea how to do it in home assistant energy dashboard

Screenshot 2023-01-08 at 18 14 09

Pimentoso avatar Jan 08 '23 17:01 Pimentoso