shenxn / ha-dyson

HomeAssitant custom integration for dyson
MIT License
306 stars 60 forks source link

Wrong values #150

Open Ultra9k opened 1 year ago

Ultra9k commented 1 year ago

So I just bought and configured a Pure Cool Formaldehyde and apparently all values on HA are wrong. Please see the images. What's the sense in this? The values are completely different than reported by the official app. IMG_20220719_213235 IMG_20220719_213223

ZdravecG commented 1 year ago

I also saw different values in the dyson app and in home assistant. What I did is to connect tho the device and read the data from there with mqtt. dyson_app {'msg': 'ENVIRONMENTAL-CURRENT-SENSOR-DATA', 'time': '2022-10-27T12:19:23.000Z', 'data': {'tact': '3034', 'hact': '0043', 'pm25': '0001', 'pm10': '0001', 'va10': '0024', 'noxl': '0002', 'p25r': '0002', 'p10r': '0002', 'hcho': '0015', 'hchr': '0038', 'sltm': 'OFF'}} As you can see, the PM2.5 and PM10 values are stored in different key, the dyson app is using 'p25r' and 'p10r', the home assistant integration is using 'pm25' and 'pm10'. Same for HCHO, dyson app is showing the value of 'hchr' For NO2, the scale is maybe wrong, the value is 0.2 and not 2. Same for VOC, should be 2.4 and not 24 as in the home assistant integration

As I want to have the same values as the dyson app, I changed the coding in my home assistant instance, but it will be overwritten in the next update of the integration.

Actually, the better place to fix the issue is inside https://github.com/shenxn/libdyson, but as I don't know, where home assistant downloads required libraries, I modified the integration.

Here what I've changed in /config/custom_components/dyson_local/sensor.py if someone is interested, starting at line 251


class DysonPM25Sensor(DysonSensorEnvironmental):
    """Dyson sensor for PM 2.5 fine particulate matters."""

    _SENSOR_TYPE = "pm25"
    _SENSOR_NAME = "PM 2.5"
    _attr_device_class = SensorDeviceClass.PM25
    _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
    _attr_state_class = SensorStateClass.MEASUREMENT

    @environmental_property
    def state(self) -> int:
        """Return the state of the sensor."""
        return self._device._get_environmental_field_value("p25r")

class DysonPM10Sensor(DysonSensorEnvironmental):
    """Dyson sensor for PM 10 particulate matters."""

    _SENSOR_TYPE = "pm10"
    _SENSOR_NAME = "PM 10"
    _attr_device_class = SensorDeviceClass.PM10
    _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
    _attr_state_class = SensorStateClass.MEASUREMENT

    @environmental_property
    def state(self) -> int:
        """Return the state of the sensor."""
        return self._device._get_environmental_field_value("p10r")

class DysonParticulatesSensor(DysonSensorEnvironmental):
    """Dyson sensor for particulate matters for "Link" devices."""

    _SENSOR_TYPE = "pm1"
    _SENSOR_NAME = "Particulates"
    _attr_device_class = SensorDeviceClass.PM1
    _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
    _attr_state_class = SensorStateClass.MEASUREMENT

    @environmental_property
    def state(self) -> int:
        """Return the state of the sensor."""
        return self._device.particulates

class DysonVOCSensor(DysonSensorEnvironmental):
    """Dyson sensor for volatile organic compounds."""

    _SENSOR_TYPE = "voc"
    _SENSOR_NAME = "Volatile Organic Compounds"
    _attr_device_class = SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS
    _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
    _attr_state_class = SensorStateClass.MEASUREMENT

    @environmental_property
    def state(self) -> int:
        """Return the state of the sensor."""
        return round(self._device.volatile_organic_compounds/10)

class DysonNO2Sensor(DysonSensorEnvironmental):
    """Dyson sensor for Nitrogen Dioxide."""

    _SENSOR_TYPE = "no2"
    _SENSOR_NAME = "Nitrogen Dioxide"
    _attr_device_class = SensorDeviceClass.NITROGEN_DIOXIDE
    _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
    _attr_state_class = SensorStateClass.MEASUREMENT

    @environmental_property
    def state(self) -> int:
        """Return the state of the sensor."""
        return round(self._device._get_environmental_field_value("noxl", 10))

class DysonHCHOSensor(DysonSensorEnvironmental):
    """Dyson sensor for Formaldehyde."""

    _SENSOR_TYPE = "hcho"
    _SENSOR_NAME = "Formaldehyde"
    _attr_device_class = SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS
    _attr_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER

    @environmental_property
    def state(self) -> int:
        """Return the state of the sensor."""
        return self._device._get_environmental_field_value("hchr", 1000)