jeroenterheerdt / HAsmartirrigation

Smart Irrigation custom component for Home Assistant
https://jeroenterheerdt.github.io/HAsmartirrigation/
MIT License
355 stars 48 forks source link

Not calculating anything anymore since last update #395

Closed MrBurnst closed 3 months ago

MrBurnst commented 4 months ago

What happened?

Updating to the latest version broke SmartIrrigation.

It seems that "const" is None (see below). I tried restarting HA, clearing all weather data, recalculating everything, did not help.

How to reproduce

Maybe it's just me?

Relevant log output

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/smart_irrigation/__init__.py:591
integration: Smart Irrigation (documentation, issues)

First occurred: June 6, 2024 at 2:48:29 PM (2383 occurrences)
Last logged: 6:30:35 AM

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/smart_irrigation/__init__.py", line 591, in _async_update_all
    weatherdata[const.RETRIEVED_AT] = datetime.datetime.now()
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object does not support item assignment

Which version are you running?

2024.6.1

Diagnostics file

Additional information

here's my diagnostics file:

{
  "home_assistant": {
    "installation_type": "Home Assistant Supervised",
    "version": "2024.6.0",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.12.2",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Amsterdam",
    "os_name": "Linux",
    "os_version": "6.5.0-35-generic",
    "supervisor": "2024.06.0",
    "host_os": "Ubuntu 22.04.4 LTS",
    "docker_version": "26.1.4",
    "chassis": "desktop",
    "run_as_root": true
  },
  "custom_components": {
    "epex_spot": {
      "documentation": "https://github.com/mampfes/ha_epex_spot",
      "version": "2.3.5",
      "requirements": [
        "beautifulsoup4"
      ]
    },
    "average": {
      "documentation": "https://github.com/Limych/ha-average",
      "version": "2.3.4",
      "requirements": []
    },
    "smart_irrigation": {
      "documentation": "https://github.com/jeroenterheerdt/HASmartIrrigation",
      "version": "v2024.6.2",
      "requirements": []
    },
    "thermal_comfort": {
      "documentation": "https://github.com/dolezsa/thermal_comfort/blob/master/README.md",
      "version": "2.2.2",
      "requirements": []
    },
    "hacs": {
      "documentation": "https://hacs.xyz/docs/configuration/start",
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "midea_dehumidifier": {
      "documentation": "https://github.com/barban-dev/homeassistant-midea-dehumidifier/blob/master/README.md",
      "version": "1.0.3",
      "requirements": [
        "midea-inventor-lib==1.0.4"
      ]
    }
  },
  "integration_manifest": {
    "domain": "smart_irrigation",
    "name": "Smart Irrigation",
    "codeowners": [
      "jeroenterheerdt"
    ],
    "config_flow": true,
    "dependencies": [
      "http",
      "panel_custom"
    ],
    "documentation": "https://github.com/jeroenterheerdt/HASmartIrrigation",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/jeroenterheerdt/HASmartIrrigation/issues",
    "requirements": [],
    "version": "v2024.6.2",
    "is_built_in": false
  },
  "setup_times": {
    "null": {
      "setup": 7.401200127787888e-05
    },
    "8ec902ff25e8a0225a814b5f42f44379": {
      "config_entry_setup": 0.02395213197451085,
      "wait_import_platforms": -4.817497384006856,
      "config_entry_platform_setup": 0.002150840009562671
    }
  },
  "data": {
    "config": {
      "data": {
        "owm_api_key": "XXXXXXXX",
        "owm_api_version": "3.0",
        "use_owm": true,
        "name": "Smart Irrigation"
      },
      "disabled_by": null,
      "domain": "smart_irrigation",
      "entry_id": "8ec902ff25e8a0225a814b5f42f44379",
      "minor_version": 1,
      "options": {},
      "pref_disable_new_entities": false,
      "pref_disable_polling": false,
      "source": "user",
      "title": "Smart Irrigation",
      "unique_id": "Smart Irrigation",
      "version": 1
    },
    "storage": {
      "config": {
        "calctime": "5:00",
        "units": "metric",
        "use_owm": true,
        "autocalcenabled": true,
        "autoupdateenabled": true,
        "autoupdateschedule": "minutes",
        "autoupdatedelay": "10",
        "autoupdateinterval": "1",
        "autoclearenabled": true,
        "cleardatatime": "23:50",
        "starteventfiredtoday": false
      },
      "zones": [
        {
          "id": 0,
          "name": "Vorgarten",
          "size": 30.0,
          "throughput": 4.0,
          "state": "automatic",
          "bucket": 1.287254599709456,
          "old_bucket": 0,
          "delta": 0,
          "duration": 0,
          "module": 0,
          "multiplier": 1.0,
          "explanation": null,
          "mapping": 0,
          "lead_time": 10.0,
          "maximum_duration": 3600.0,
          "maximum_bucket": 50,
          "last_calculated": "2024-06-06T14:00:00.814191",
          "last_updated": "2024-06-06T14:46:59.701709",
          "number_of_data_points": 46
        },
        {
          "id": 1,
          "name": "Hecken",
          "size": 50.0,
          "throughput": 5.0,
          "state": "automatic",
          "bucket": 1.287254599709456,
          "old_bucket": 0,
          "delta": 0,
          "duration": 0,
          "module": 0,
          "multiplier": 1.0,
          "explanation": null,
          "mapping": 0,
          "lead_time": 10.0,
          "maximum_duration": 3600.0,
          "maximum_bucket": 50,
          "last_calculated": "2024-06-06T14:00:01.048158",
          "last_updated": "2024-06-06T14:46:59.701709",
          "number_of_data_points": 46
        },
        {
          "id": 2,
          "name": "Wiese",
          "size": 100.0,
          "throughput": 30.0,
          "state": "automatic",
          "bucket": 1.287254599709456,
          "old_bucket": 0,
          "delta": 0,
          "duration": 0,
          "module": 0,
          "multiplier": 1.0,
          "explanation": null,
          "mapping": 0,
          "lead_time": 10.0,
          "maximum_duration": 3600.0,
          "maximum_bucket": 50,
          "last_calculated": "2024-06-06T14:00:01.304935",
          "last_updated": "2024-06-06T14:46:59.701709",
          "number_of_data_points": 46
        }
      ],
      "modules": [
        {
          "id": 0,
          "name": "PyETO",
          "description": "Calculate duration based on the FAO56 calculation from the PyETO library.",
          "config": {
            "solrad_behavior": "1",
            "forecast_days": "0"
          },
          "schema": [
            {
              "type": "boolean",
              "name": "coastal",
              "optional": true,
              "default": false
            },
            {
              "type": "select",
              "options": [
                [
                  "1",
                  "EstimateFromTemp"
                ],
                [
                  "2",
                  "EstimateFromSunHours"
                ],
                [
                  "3",
                  "DontEstimate"
                ],
                [
                  "4",
                  "EstimateFromSunHoursAndTemperature"
                ]
              ],
              "name": "solrad_behavior",
              "required": true,
              "default": "1"
            },
            {
              "type": "integer",
              "name": "forecast_days",
              "required": true,
              "default": 0
            }
          ]
        }
      ],
      "mappings": [
        {
          "id": 0,
          "name": "Default sensor group",
          "mappings": {
            "Dewpoint": {
              "source": "sensor",
              "sensorentity": "sensor.thermal_comfort_aussen_dew_point",
              "unit": "",
              "aggregate": "average"
            },
            "Evapotranspiration": {
              "source": "none",
              "sensorentity": "",
              "unit": ""
            },
            "Humidity": {
              "source": "sensor",
              "sensorentity": "sensor.bresser_5in1_102_humidity",
              "unit": "",
              "aggregate": "average"
            },
            "Precipitation": {
              "source": "sensor",
              "sensorentity": "sensor.nierderschlag_24h",
              "unit": "",
              "aggregate": "last"
            },
            "Pressure": {
              "source": "sensor",
              "sensorentity": "sensor.wohnzimmer_thermohygrometer_2_pressure",
              "unit": "",
              "aggregate": "average"
            },
            "Solar Radiation": {
              "source": "none",
              "sensorentity": "",
              "unit": ""
            },
            "Temperature": {
              "source": "sensor",
              "sensorentity": "sensor.bresser_5in1_102_temperature",
              "unit": "",
              "aggregate": "average"
            },
            "Windspeed": {
              "source": "sensor",
              "sensorentity": "sensor.bresser_5in1_102_wind_average",
              "unit": "km/h"
            }
          },
          "data": [
            {
              "Dewpoint": "14.0668179998702",
              "retrieved": "2024-06-08T06:40:24.225494"
            },
            {
              "Dewpoint": "13.9705285370634",
              "retrieved": "2024-06-08T06:41:31.071001"
            },
            {
              "Dewpoint": "14.1804095298909",
              "retrieved": "2024-06-08T06:41:31.093426"
            },
            {
              "Temperature": "unknown",
              "retrieved": "2024-06-08T06:41:56.976319"
            },
            {
              "Humidity": "unknown",
              "retrieved": "2024-06-08T06:41:56.989094"
            },
            {
              "Windspeed": "unknown",
              "retrieved": "2024-06-08T06:41:57.047525"
            },
            {
              "Temperature": "18.6",
              "retrieved": "2024-06-08T06:42:08.890638"
            },
            {
              "Humidity": "80.0",
              "retrieved": "2024-06-08T06:42:08.893038"
            },
            {
              "Windspeed": "2.88",
              "retrieved": "2024-06-08T06:42:08.897290"
            },
            {
              "Temperature": "18.6",
              "retrieved": "2024-06-08T06:42:20.945376"
            },
            {
              "Humidity": "80.0",
              "retrieved": "2024-06-08T06:42:20.949827"
            },
            {
              "Windspeed": "2.88",
              "retrieved": "2024-06-08T06:42:20.956299"
            },
            {
              "Temperature": "18.6",
              "retrieved": "2024-06-08T06:42:33.000428"
            },
            {
              "Humidity": "80.0",
              "retrieved": "2024-06-08T06:42:33.008445"
            },
            {
              "Windspeed": "2.88",
              "retrieved": "2024-06-08T06:42:33.012615"
            },
            {
              "Temperature": "18.6",
              "retrieved": "2024-06-08T06:42:44.930037"
            },
            {
              "Humidity": "80.0",
              "retrieved": "2024-06-08T06:42:44.937027"
            },
            {
              "Windspeed": "2.88",
              "retrieved": "2024-06-08T06:42:44.948107"
            }
          ],
          "data_last_updated": null
        }
      ]
    }
  }
}
jeroenterheerdt commented 4 months ago

Weird, your last updated is null. Not sure why, I'll take a look at it ASAP.

MrBurnst commented 4 months ago

I think I found it. I have all my data coming from sensors, if I use OWM for for example pressure, the error disappears.

MrBurnst commented 4 months ago

... nope, still not working. Now I'm getting

Logger: aiohttp.server
Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:421
First occurred: June 8, 2024 at 6:57:43 AM (2 occurrences)
Last logged: 7:19:14 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/statistics.py", line 327, in _exact_ratio
    return (x.numerator, x.denominator)
            ^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'numerator'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 70, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/smart_irrigation/websockets.py", line 197, in post
    await coordinator.async_update_zone_config(zone, data)
  File "/config/custom_components/smart_irrigation/__init__.py", line 1343, in async_update_zone_config
    await self._async_calculate_all()
  File "/config/custom_components/smart_irrigation/__init__.py", line 795, in _async_calculate_all
    sensor_values = await self.apply_aggregates_to_mapping_data(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/smart_irrigation/__init__.py", line 722, in apply_aggregates_to_mapping_data
    resultdata[key] = statistics.mean(d)
                      ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/statistics.py", line 484, in mean
    T, total, n = _sum(data)
                  ^^^^^^^^^^
  File "/usr/local/lib/python3.12/statistics.py", line 193, in _sum
    for n, d in map(_exact_ratio, values):
  File "/usr/local/lib/python3.12/statistics.py", line 330, in _exact_ratio
    raise TypeError(msg)
TypeError: can't convert type 'str' to numerator/denominator
Kurisutian commented 4 months ago

Same problem here.

MrBurnst commented 4 months ago

I "fixed" it by casting the values of "d" in init.py to float, but I have no idea why some sensor readings are str and some float ...

Kurisutian commented 3 months ago

I "fixed" it by casting the values of "d" in init.py to float, but I have no idea why some sensor readings are str and some float ...

Would you mind sharing exactly what you changed where? I would love to get it to work again until an "official" fix has been released. 😉

Thanks a lot!

MrBurnst commented 3 months ago

a probably cleaner solution is given in issue https://github.com/jeroenterheerdt/HAsmartirrigation/issues/398 , but I added

d = [float(dd) if isinstance(dd, str) and dd.replace('.', '', 1).isdigit() else dd for dd in d if isinstance(dd, (int, float)) or (isinstance(dd, str) and dd.replace('.', '', 1).isdigit())]

before https://github.com/jeroenterheerdt/HAsmartirrigation/blob/3e83f76ec7ef7d669a9fefe3fd1f861d23424c96/custom_components/smart_irrigation/__init__.py#L696

after that, only numeric values remain in list d .

jeroenterheerdt commented 3 months ago

I am going to implement the solution in #398, so closing this as duplicate. please reopen if the fix doesn't fix it when released.