galletn / iaqualink

Home Assistant Iaqualink Vacuums Robots
8 stars 1 forks source link

Temperature not updating #14

Closed justinmaiuto closed 4 months ago

justinmaiuto commented 4 months ago

This has been working for a while, but stopped seemingly when I updated to 480e9cd.

Something weird happened where it created a new robot entity, not sure if it is related. I have since uninstalled via HACS, deleted all robot entities, reinstalled and now have just the 1 entity. But the temperature value is not updating. Normally this would only update when the robot is running which is fine, but it's now no longer updating regardless of whether the robot is running or not.

Interestingly, in the iAqualink app there is a new notification saying that the robot temperature only updates when the robot is running which I don't recall seeing before, but either way I can't find anywhere which actually shows the temperature value in the app. Why is this relevant - suggests perhaps iAqualink may have made some recent changes to the temperature functionality.

These are the relevant errors in the logs:

Logger: homeassistant
Source: components/sensor/__init__.py:670
First occurred: 20:59:12 (1 occurrences)
Last logged: 20:59:12

Error doing job: Exception in callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f02b744a160>>(<Event homeassistant_start[L]>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 663, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

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

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1196, in __call__
    self.hass.async_run_job(self.listener, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 775, in async_run_job
    return self.async_run_hass_job(HassJob(target), *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 727, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 40, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
  File "/usr/src/homeassistant/homeassistant/core.py", line 727, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 486, in _async_template_startup
    result_info.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1076, in async_refresh
    self._refresh(None)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1262, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 727, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 434, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1050, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.pool_temperature_robot_cleaner has device class 'temperature', state class 'measurement' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)
Logger: homeassistant.helpers.template
Source: helpers/template.py:2377
First occurred: 20:59:12 (2 occurrences)
Last logged: 20:59:12

Template variable warning: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'temperature' when rendering '{{ states.sensor.iaqualinkrobots_viron_qt1050_pool_cleaner_robot.attributes.temperature }}'
justinmaiuto commented 4 months ago

Here is the notification in the app which I've not seen before, suggesting recent changes on iaqualink side Screenshot_20240327_210818_iAquaLink

galletn commented 4 months ago

Do you have experience with API's?

you can use postman.

you should first do a login and then with the IdToken returned call the get device status, you also need the device id in the url in case you don't have that you need first to call the get devices to get your serial_number.

I'll need the return of your getdevicestatus to make sure the code works for you. It still runs here.

Test.postman_collection.json

justinmaiuto commented 4 months ago

So, the "19" temperature value has been the same for 2 days, regardless of whether the robot is running or not. Seems something wrong on the iAqualink side around updating temperature value given this response seems fine.

{
    "state": {
        "reported": {
            "aws": {
                "status": "connected",
                "timestamp": 1711528456440,
                "session_id": "3dc92331-129f-4042-b569-09540d4ff647"
            },
            "sn": "KD2100004952",
            "dt": "vr",
            "vr": "V32C41",
            "eboxData": {
                "controlBoxSn": "OMA2122910",
                "controlBoxPn": "30121700",
                "completeCleanerSn": "HLCA03011922211357",
                "completeCleanerPn": "WR000386",
                "powerSupplySn": "AP21070277",
                "sensorBlockSn": "EL21011624",
                "motorBlockSn": "EMB2117450"
            },
            "equipment": {
                "robot": {
                    "vr": "V32E41",
                    "state": 0,
                    "liftControl": 0,
                    "prCyc": 2,
                    "cycleStartTime": 1711528462,
                    "canister": 0,
                    "equipmentId": "JZ21016289",
                    "rmt_ctrl": 0,
                    "logger": 0,
                    "firstSmrtFlag": 0,
                    "scanTimeDuration": 30,
                    "stepper": 0,
                    "stepperAdjTime": 15,
                    "errorState": 0,
                    "errorCode": 0,
                    "customCyc": 1,
                    "customIntensity": 0,
                    "totalHours": 1088,
                    "durations": {
                        "waterTim": 45,
                        "quickTim": 75,
                        "smartTim": 111,
                        "deepTim": 165,
                        "customTim": 150,
                        "firstSmartTim": 150
                    },
                    "sensors": {
                        "sns_1": {
                            "type": "temperature",
                            "state": 0,
                            "val": 19
                        },
                        "sns_2": {
                            "type": "pressure",
                            "state": 0
                        },
                        "sns_3": {
                            "type": "compass",
                            "state": 0
                        }
                    },
                    "schConf1Enable": 1,
                    "schConf1Prt": 2,
                    "schConf1Hour": 21,
                    "schConf1Min": 30,
                    "schConf1WDay": 0,
                    "schConf2Enable": 1,
                    "schConf2Prt": 2,
                    "schConf2Hour": 21,
                    "schConf2Min": 30,
                    "schConf2WDay": 1,
                    "schConf3Enable": 1,
                    "schConf3Prt": 3,
                    "schConf3Hour": 21,
                    "schConf3Min": 0,
                    "schConf3WDay": 2,
                    "schConf4Enable": 1,
                    "schConf4Prt": 2,
                    "schConf4Hour": 21,
                    "schConf4Min": 30,
                    "schConf4WDay": 3,
                    "schConf5Enable": 1,
                    "schConf5Prt": 2,
                    "schConf5Hour": 21,
                    "schConf5Min": 30,
                    "schConf5WDay": 4,
                    "schConf6Enable": 1,
                    "schConf6Prt": 3,
                    "schConf6Hour": 21,
                    "schConf6Min": 0,
                    "schConf6WDay": 5,
                    "schConf0Enable": 1,
                    "schConf0Prt": 2,
                    "schConf0Hour": 21,
                    "schConf0Min": 30,
                    "schConf0WDay": 6,
                    "repeat": 0
                }
            }
        }
    },
    "deviceId": "KD2100004952",
    "ts": 1711538173
}
justinmaiuto commented 4 months ago

How is the polling for this integration working? It seems that maybe it fails once and then stops polling for anything? For example, although the temperature is not changing from 19 degrees when using postman, the hours count of run time is increasing each time I use the robot. But in HA it is not reflecting the updated hours count (at least not straight away as far as I can see)

galletn commented 4 months ago

it is polling every 30 seconds:

SCAN_INTERVAL = timedelta(seconds=30)

for me its non stop updating, but it could be that due to it crashing its not updating after it.

the data also still appears to be on the same location:

                #temperature seems to depend on robot model and has 2 possible locations:
                try:
                    self._temperature = data["state"]["reported"]["equipment"]["robot"]["sensors"]["sns_1"]["val"]
                except:
                    try: 
                        self._temperature = data["state"]["reported"]["equipment"]["robot"]["sensors"]["sns_1"]["state"]
                    except:
                        self._temperature = '0' #Zodiac XA 5095 iQ does not support temp for example see https://github.com/galletn/iaqualink/issues/9

                self._attributes['temperature'] = self._temperature
justinmaiuto commented 4 months ago

Ok how do we stop it crashing. Looks like a cast from string to float error as per my first post

galletn commented 4 months ago

can you test https://github.com/galletn/iaqualink/pull/15

I gave it a fix value 0 at initial run already.

The only thing that I find strange is that it freaks out at a line that is not referring to the code.

Did you create template sensors based on it ?

justinmaiuto commented 4 months ago

Yep i have a template sensor for it

galletn commented 4 months ago

I think that is the one blocking it ... so please can you remove it for a second and then restart and see if it runs? Also with this code it should be fixed at runtime already. But 99% chance its your template sensor.

justinmaiuto commented 4 months ago

Hi, I've tried with the code you updated and also with removing the template sensors. Neither seems to have made a difference. Seems to me like some bigger problems at play here - the integration is no longer receiving/capturing updates related for when the robot is running vs. not running. This used to work fine also. Seems to be stuck on whatever values it retrieves on HA startup and nothing post that until next startup.

galletn commented 4 months ago

@justinmaiuto I think you are right there was an very crucial update missing towards the data factory class.

Can you check again now? (branch version not main release yet)

I did not notice as I just pulled out my robot just last week.

galletn commented 4 months ago

tested and worked for me now

justinmaiuto commented 4 months ago

Yep seems sorted!

justinmaiuto commented 4 months ago

Ok, so the updates seem to be working now for everything.....except for the temperature updates. which was the original issue I raised. After a couple of days of running, the temperature has not updated once. I have other sensors in the pool and the report as expected (ie the pool is heatig up in the day and cooling down over night). But the pool robot has been stuck on 16 degrees Celsius the whole time.

galletn commented 3 months ago

For me the temperature is still updating, I also do not have the popup you have in the app about the temperature.

Does it update when you have the app opened while running?

Also code wise there is no difference between any other of the values (like running hours or last start time), so it must be that the API of your robot remains sending that value.

Not a lot that I can do about that I'm afraid.