Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuya Presence Detection "Power" Error as it reports "dc" and not a number. #246

Closed
ajtatum opened this issue Jan 5, 2024 · 4 comments
Closed

Comments

@ajtatum
Copy link

ajtatum commented Jan 5, 2024

Just installed a Tuya Presence Detector in Hubitat and brought it over to HA. I took a look at the logs and saw error messages about Hubitat sending the power as "dc" instead of a value that Home Assistant can recognize.

Here is the log information:

2024-01-04 19:13:33.554 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform hubitat
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 644, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'dc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 647, in state
    numerical_value = float(value)
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'dc'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1278, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 941, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1062, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 999, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 947, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 651, in state
    raise ValueError(
ValueError: Sensor sensor.bathroom_tuya_presence_sensor_powersource has device class 'power', state class 'None' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'dc' (<class 'str'>)
2024-01-04 19:13:33.568 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 644, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'dc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 647, in state
    numerical_value = float(value)
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'dc'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1418, in _async_registry_updated
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 941, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1062, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 999, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 947, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 651, in state
    raise ValueError(
ValueError: Sensor sensor.bathroom_tuya_presence_sensor_powersource has device class 'power', state class 'None' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'dc' (<class 'str'>)
2024-01-04 19:13:33.570 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up hubitat platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 644, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'dc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 647, in state
    numerical_value = float(value)
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'dc'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 368, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1278, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 941, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1062, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 999, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 947, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 651, in state
    raise ValueError(
ValueError: Sensor sensor.bathroom_tuya_presence_sensor_powersource has device class 'power', state class 'None' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'dc' (<class 'str'>)

Here's more information about the device:

{
  "id": "44",
  "name": "Tuya Human Presence Detector WZ-M100",
  "label": "Bathroom Tuya Presence Sensor",
  "type": "Tuya Multi Sensor 4 In 1",
  "room": "Basement Bathroom",
  "attributes": [
    {
      "name": "all",
      "currentValue": null,
      "dataType": "STRING"
    },
    {
      "name": "illuminance",
      "currentValue": 11,
      "dataType": "NUMBER"
    },
    {
      "name": "humidity",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "staticDetectionSensitivity",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "temperature",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "detectionDelay",
      "currentValue": "0.1",
      "dataType": "DECIMAL"
    },
    {
      "name": "radarAlarmVolume",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "0 - low",
        "1 - medium",
        "2 - high",
        "3 - mute"
      ]
    },
    {
      "name": "radarStatus",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "checking",
        "check_success",
        "check_failure",
        "others",
        "comm_fault",
        "radar_fault"
      ]
    },
    {
      "name": "tamper",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "clear",
        "detected"
      ]
    },
    {
      "name": "distance",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "unacknowledgedTime",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "radarAlarmMode",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "0 - arm",
        "1 - off",
        "2 - alarm",
        "3 - doorbell"
      ]
    },
    {
      "name": "radarSensitivity",
      "currentValue": 5,
      "dataType": "NUMBER"
    },
    {
      "name": "battery",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "checkInterval",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "powerSource",
      "currentValue": "dc",
      "dataType": "ENUM",
      "values": [
        "battery",
        "dc",
        "mains",
        "unknown"
      ]
    },
    {
      "name": "fadingTime",
      "currentValue": "5.0",
      "dataType": "DECIMAL"
    },
    {
      "name": "healthStatus",
      "currentValue": "online",
      "dataType": "ENUM",
      "values": [
        "offline",
        "online"
      ]
    },
    {
      "name": "minimumDistance",
      "currentValue": "0.25",
      "dataType": "DECIMAL"
    },
    {
      "name": " pushed",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "batteryVoltage",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "leave_time",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "maximumDistance",
      "currentValue": "2.5",
      "dataType": "DECIMAL"
    },
    {
      "name": "motion",
      "currentValue": "active",
      "dataType": "ENUM",
      "values": [
        "inactive",
        "active"
      ]
    },
    {
      "name": "sensitivity",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "low",
        "medium",
        "high"
      ]
    },
    {
      "name": "occupancy",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "occupied",
        "unoccupied"
      ]
    },
    {
      "name": "keepTime",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "10 seconds",
        "30 seconds",
        "60 seconds",
        "120 seconds"
      ]
    },
    {
      "name": "existance_time",
      "currentValue": null,
      "dataType": "NUMBER"
    },
    {
      "name": "humanMotionState",
      "currentValue": null,
      "dataType": "ENUM",
      "values": [
        "none",
        "moving",
        "small_move",
        "stationary",
        "presence",
        "peaceful",
        "large_move"
      ]
    }
  ],
  "capabilities": [
    "RelativeHumidityMeasurement",
    {
      "attributes": [
        {
          "name": "humidity",
          "dataType": null
        }
      ]
    },
    "MotionSensor",
    {
      "attributes": [
        {
          "name": "motion",
          "dataType": null
        }
      ]
    },
    "PowerSource",
    {
      "attributes": [
        {
          "name": "powerSource",
          "dataType": null
        }
      ]
    },
    "Refresh",
    "Battery",
    {
      "attributes": [
        {
          "name": "battery",
          "dataType": null
        }
      ]
    },
    "TamperAlert",
    {
      "attributes": [
        {
          "name": "tamper",
          "dataType": null
        }
      ]
    },
    "IlluminanceMeasurement",
    {
      "attributes": [
        {
          "name": "illuminance",
          "dataType": null
        }
      ]
    },
    "TemperatureMeasurement",
    {
      "attributes": [
        {
          "name": "temperature",
          "dataType": null
        }
      ]
    },
    "Sensor",
    "HealthCheck",
    {
      "attributes": [
        {
          "name": "checkInterval",
          "dataType": null
        }
      ]
    }
  ],
  "commands": [
    "configure",
    "initialize",
    "ping",
    "refresh",
    "refresh",
    "sendCommand",
    "setMotion",
    "setPar"
  ]
}

Please let me know if you need any further information.

@jason0x43
Copy link
Owner

The issue here is that "power source" sensors are currently being given the device class of "power" which is incorrect and causes Home Assistant to treat the values as numeric. That will be fixed in the next release (which will be soon).

@jason0x43
Copy link
Owner

This should be fixed in v0.9.19.

@jason0x43
Copy link
Owner

Have you had a chance to check if this is working?

@jason0x43
Copy link
Owner

Closing this as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants