Aohzan / ipx800

IPX800 V4 integration for Home-Assistant
Apache License 2.0
20 stars 12 forks source link

Support for X-4FP extension #4

Closed guigeek38 closed 3 years ago

guigeek38 commented 3 years ago

First of all, thank you for this ha component which works wonderfully! Would it be possible to add compatibility with the pilot wire extension of the ipx800: X-4FP ?
I can do the tests if you don't have the required equipment and give you feedback if needed. Thank you!

Aohzan commented 3 years ago

Thank you :) It's on the TODO list, I'll contact you to test the first beta

Aohzan commented 3 years ago

@guigeek38 you can test it on the dev branch : https://github.com/Aohzan/ipx800/tree/dev

guigeek38 commented 3 years ago

I tested this new version of the component with Home Assistant 0.116.4.

I added an entity with the following configuration:

- name: Radiateur Salon
   type: x4fp
   component: climate
   id: 1
   ext_id: 1

However the entity is not working, here are the hogs of ha:

2020-10-19 21:11:30 ERROR (MainThread) [homeassistant.components.climate] Error while setting up ipx800 platform for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 201, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 310, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 481, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 522, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 296, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    sstate = self.state
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 173, in state
    return self.hvac_mode
  File "/config/custom_components/ipx800/climate.py", line 77, in hvac_mode
    if int(self.coordinator.data[f"FP{self._ext_id} Zone {self._id}"]) == 3:
ValueError: invalid literal for int() with base 10: 'Confort -1'
2020-10-19 21:11:30 ERROR (MainThread) [homeassistant.components.binary_sensor] ipx800: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 346, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 469, in async_device_update
    await self.async_update()  # type: ignore
  File "/config/custom_components/ipx800/device.py", line 89, in async_update
    await self.coordinator.async_request_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 125, in async_request_refresh
    await self._debounced_refresh.async_call()
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 60, in async_call
    await self.hass.async_add_job(self.function)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 192, in async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 296, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    sstate = self.state
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 173, in state
    return self.hvac_mode
  File "/config/custom_components/ipx800/climate.py", line 77, in hvac_mode
    if int(self.coordinator.data[f"FP{self._ext_id} Zone {self._id}"]) == 3:
ValueError: invalid literal for int() with base 10: 'Confort -1'
2020-10-19 21:11:48 WARNING (MainThread) [homeassistant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for ipx800 doing I/O at custom_components/ipx800/climate.py, line 119: self.control.set_mode(switcher.get(preset_mode))
Aohzan commented 3 years ago

@guigeek38 Could you add debug log on the component: logger: default: info logs: custom_components.ipx800: debug

and get the last update on dev branch ?

guigeek38 commented 3 years ago

I am getting the exact same error with these new tests.

I think the problem is with int(self.coordinator.data[f"FP{self._ext_id} Zone {self._id}"]) because the coordinator seems to contain a string ('Eco') and it doesn't know how to convert it to int.

Logs:

2020-10-29 16:03:13 INFO (MainThread) [homeassistant.setup] Setting up ipx800
2020-10-29 16:03:13 DEBUG (MainThread) [custom_components.ipx800] New IPX800 initialisation on host: 192.168.1.111
2020-10-29 16:03:13 INFO (MainThread) [custom_components.ipx800] Successfully connected to the IPX800 IPX.
...
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Finished fetching ipx800 data in 0.511 seconds
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Read and process devices configuration
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Read device name: Radiateur Salon
2020-10-29 16:03:14 INFO (MainThread) [custom_components.ipx800] Device Radiateur Salon added (component: climate).
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Load component light.
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Load component switch.
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Load component sensor.
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Load component binary_sensor.
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Load component cover.
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Load component climate.
2020-10-29 16:03:14 INFO (MainThread) [homeassistant.setup] Setup of domain ipx800 took 0.8 seconds
...
2020-10-29 16:03:14 INFO (MainThread) [homeassistant.setup] Setting up climate
2020-10-29 16:03:14 INFO (MainThread) [homeassistant.setup] Setup of domain climate took 0.0 seconds
2020-10-29 16:03:14 INFO (MainThread) [homeassistant.components.switch] Setting up switch.ipx800
2020-10-29 16:03:14 INFO (MainThread) [homeassistant.components.cover] Setting up cover.ipx800
2020-10-29 16:03:14 INFO (MainThread) [homeassistant.components.climate] Setting up climate.ipx800
2020-10-29 16:03:14 ERROR (MainThread) [custom_components.ipx800.climate] setup climate
2020-10-29 16:03:14 INFO (MainThread) [homeassistant.components.light] Setting up light.ipx800
2020-10-29 16:03:14 ERROR (MainThread) [homeassistant.components.climate] Error adding entities for domain climate with platform ipx800
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 314, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 505, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 531, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 296, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    sstate = self.state
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 173, in state
    return self.hvac_mode
  File "/config/custom_components/ipx800/climate.py", line 77, in hvac_mode
    if int(self.coordinator.data[f"FP{self._ext_id} Zone {self._id}"]) == 3:
ValueError: invalid literal for int() with base 10: 'Eco'
2020-10-29 16:03:14 ERROR (MainThread) [homeassistant.components.climate] Error while setting up ipx800 platform for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 205, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 314, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 505, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 531, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 296, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    sstate = self.state
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 173, in state
    return self.hvac_mode
  File "/config/custom_components/ipx800/climate.py", line 77, in hvac_mode
    if int(self.coordinator.data[f"FP{self._ext_id} Zone {self._id}"]) == 3:
ValueError: invalid literal for int() with base 10: 'Eco'
2020-10-29 16:03:14 DEBUG (MainThread) [custom_components.ipx800] Finished fetching ipx800 data in 0.183 seconds
2020-10-29 16:03:14 ERROR (MainThread) [homeassistant.components.binary_sensor] ipx800: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 357, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, in async_device_update
    await task
  File "/config/custom_components/ipx800/device.py", line 89, in async_update
    await self.coordinator.async_request_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 126, in async_request_refresh
    await self._debounced_refresh.async_call()
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 73, in async_call
    await self.hass.async_add_hass_job(self._job)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 193, in async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 296, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    sstate = self.state
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 173, in state
    return self.hvac_mode
  File "/config/custom_components/ipx800/climate.py", line 77, in hvac_mode
    if int(self.coordinator.data[f"FP{self._ext_id} Zone {self._id}"]) == 3:
ValueError: invalid literal for int() with base 10: 'Eco'
Aohzan commented 3 years ago

Can you send me what the Get=FP api call returns to you ? I commit a change with mode name returning instead of id. Can you try with last version if it's better ?

guigeek38 commented 3 years ago

/api/xdevices.json?key=XXX&Get=FP:

{
    "product": "IPX800_V4",
    "status": "Success",
    "FP1 Zone 1": "Confort",
    "FP1 Zone 2": "Confort -2",
    "FP1 Zone 3": "Eco",
    "FP1 Zone 4": "Arret",
    "FP2 Zone 1": 0,
    "FP2 Zone 2": 0,
    "FP2 Zone 3": 0,
    "FP2 Zone 4": 0,
    "FP3 Zone 1": 0,
    "FP3 Zone 2": 0,
    "FP3 Zone 3": 0,
    "FP3 Zone 4": 0,
    "FP4 Zone 1": 0,
    "FP4 Zone 2": 0,
    "FP4 Zone 3": 0,
    "FP4 Zone 4": 0
}

I will test this new version soon.

Aohzan commented 3 years ago

Ok it's what I thinked, the IPX does not return the same value than we have to send to it. The recent version should works

guigeek38 commented 3 years ago

Yes, it works much better now! But I think there is still an error: The "Stop" state is actually named "Arret" in the ipx. So the state "Stop" is not recognized by Home assistant.

Aohzan commented 3 years ago

fix in last commit 09eab038af07c4fdbc42a7ab8b3e71151b8f5a6d

guigeek38 commented 3 years ago

It works perfectly thank you! :) Just one last question: When I change the preset of the climate component, the order is well sent to the ipx, but the status in home assistant is only updated after the scan_interval has run. So I would have to add a push from the ipx to have a faster status update. However, it is impossible in the ipx to trigger a push following a change on the FP. Would it be possible to force the status update in home assistant? Or do you have another idea?

Aohzan commented 3 years ago

Great, I will merge the dev branch for a new release

Yes, ask for an update when an action is done, the same problem occurs on light, switch... Sadly, I already try and the IPX returned an error because it doesn't like multiple request at the same time. I have to search a solution, it's on my TODO list :)