Bouni / luxtronik

Luxtronik integration for Home Assistant
MIT License
82 stars 14 forks source link

Integration hangs after writing - write / read at the same time? #10

Closed BenPru closed 2 years ago

BenPru commented 3 years ago

Sometimes the integration stops working. No state updates since 20:07:42 image --- Log: 2020-11-05 20:07:42 INFO (MainThread) [homeassistant.components.automation.a_heizung_aufheizen] z Heizung 8 Springt an --> Aufheizen WP->HA: Running automation actions 2020-11-05 20:07:42 INFO (MainThread) [homeassistant.components.automation.a_heizung_aufheizen] z Heizung 8 Springt an --> Aufheizen WP->HA: Executing step call service 2020-11-05 20:07:42 INFO (MainThread) [homeassistant.components.automation.a_heizung_aufheizen] z Heizung 8 Springt an --> Aufheizen WP->HA: Executing step call service 2020-11-05 20:07:42 ERROR (MainThread) [homeassistant.helpers.entity] Update for luxtronik.betriebsstunden_gesamt fails Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 278, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 474, in async_device_update raise exc File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, *self.kwargs) File "/config/custom_components/luxtronik/sensor.py", line 118, in update self._luxtronik.update() File "/usr/src/homeassistant/homeassistant/util/init.py", line 239, in wrapper result = method(args, **kwargs) File "/config/custom_components/luxtronik/init.py", line 111, in update self._luxtronik.read() File "/usr/local/lib/python3.8/site-packages/luxtronik/init.py", line 39, in read self._read_parameters() File "/usr/local/lib/python3.8/site-packages/luxtronik/init.py", line 68, in _read_parameters length = struct.unpack(">i", self._socket.recv(4))[0] OSError: [Errno 9] Bad file descriptor --- sensors.yaml:

Bouni commented 3 years ago

Hi, you might be right that writing and reading at the same time causes a crash. I connect/disconnect for both, reading and writing and have no clue what happens if both happens at the same time 🤔

BenPru commented 3 years ago

I added a dely in my automation. I hope this is a workaround for me at the moment. Another strange thing is, that luxtronik.status is in state "heating" since yesterday but the heatpump is idle. A complete restart from home assistant didn't change that. And in the log is nothing about this sensor. 😦 This is my config:

platform: luxtronik scan_interval: 60 sensors: id: ID_WEB_WP_BZ_akt group: calculations friendly_name: Status

Bouni commented 3 years ago

Was the luxtronik.status changing in the past?

BenPru commented 3 years ago

Yes. But I looked under heatpump24.com and I see the same status "heating" here. So it is a problem in the heatpump. Do you known an alternative variable I can use instead of "ID_WEB_WP_BZ_akt"?

Bouni commented 3 years ago

The problem ist that on heatpump24.com you cannot determin which calculation number refers to the state value!

image

For the settings, you can see the corresponding ID:

image

You can install python-luxtronik (pip install luxtronik) and then read and dump all values and check for changes as the status changes.

Here is an example how to do that:

#!/usr/bin/env python

from luxtronik import Luxtronik

l = Luxtronik("192.168.178.100", 8889)

# Parameters
for n, s in l.parameters.parameters.items():
    print(f"Parameter: {n:<4d} {s.name:<60} {l.parameters.get(n)}")

# Calculations
for n, s in l.calculations.calculations.items():
    print(f"Calculation: {n:<4d} {s.name:<60} {l.calculations.get(n)}")

# Visibilities commented out as they are mostly useless
## Visibility
#for n, s in l.visibilities.visibilities.items():
#    print(f"Visibility: {n:<4d} {s.name:<60} {l.visibilities.get(n)}")
Bouni commented 3 years ago

For me ID_WEB_WP_BZ_akt matches the actual state 🤔

a python dump.py | grep BZ gives me:

Calculation: 80   ID_WEB_WP_BZ_akt                                             no request
Calculation: 191  ID_WEB_SEC_BZ                                                off

Note: dump.py is the name of the file with the script from the previous post

BenPru commented 3 years ago

I have checked all params and there is only ID_WEB_WP_BZ_akt I can use for this. But at the moment nearly all the time the luxtronik has the correct value there.

In all my automations I have add a delay to prevent read and write at the same time. But about one time a day the integration hangs. Do you know a method or something to reset a integration without restarting ha?

Here is my current log from this morning: 2020-11-20 08:39:10 INFO (MainThread) [homeassistant.components.generic_thermostat.climate] Turning on heater input_boolean.brauchwasser 2020-11-20 08:39:11 INFO (MainThread) [homeassistant.components.automation.heizung_brauchwasser_an_aus_schalten] z Heizung Warmwasser 1 an/aus schalten HA->WP: Running automation actions 2020-11-20 08:39:11 INFO (MainThread) [homeassistant.components.automation.heizung_brauchwasser_an_aus_schalten] z Heizung Warmwasser 1 an/aus schalten HA->WP: Executing step call service 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_aufheizen] z Heizung 8 Springt an --> Aufheizen WP->HA: Running automation actions 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_aufheizen] z Heizung 8 Springt an --> Aufheizen WP->HA: Executing step delay 0:00:03 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.z_heizung_geht_aus_ha_wp] z Heizung 9 geht aus HA->WP: Running automation actions 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.z_heizung_geht_aus_ha_wp] z Heizung 9 geht aus HA->WP: Executing step call service 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_temperatur] z Heizung 2 Temperatur HA->WP: Running automation actions 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_temperatur] z Heizung 2 Temperatur HA->WP: Executing step delay 0:00:03 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.z_heizung_geht_aus_ha_wp] z Heizung 9 geht aus HA->WP: Executing step call service 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.heizung_brauchwasser_an_aus_ruckmeldung] z Heizung Warmwasser 1a an/aus Rückmeldung WP->HA: Running automation actions 2020-11-20 08:40:11 INFO (MainThread) [homeassistant.components.automation.heizung_brauchwasser_an_aus_ruckmeldung] z Heizung Warmwasser 1a an/aus Rückmeldung WP->HA: Choose at step 1: default: Running automation actions 2020-11-20 08:40:14 INFO (MainThread) [homeassistant.components.automation.a_heizung_aufheizen] z Heizung 8 Springt an --> Aufheizen WP->HA: Executing step call service 2020-11-20 08:40:14 WARNING (MainThread) [homeassistant.components.automation.a_heizung_temperatur] z Heizung 2 Temperatur HA->WP: Already running 2020-11-20 08:40:14 INFO (MainThread) [homeassistant.components.automation.a_heizung_aufheizen] z Heizung 8 Springt an --> Aufheizen WP->HA: Executing step call service 2020-11-20 08:40:14 INFO (MainThread) [homeassistant.components.automation.a_heizung_temperatur] z Heizung 2 Temperatur HA->WP: Executing step call service 2020-11-20 08:41:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_warmwasser_springt_an_aufheizen] z Heizung Warmwasser 8 Springt an --> Aufheizen HA->WP: Running automation actions 2020-11-20 08:41:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_warmwasser_springt_an_aufheizen] z Heizung Warmwasser 8 Springt an --> Aufheizen HA->WP: Executing step call service 2020-11-20 08:41:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_brauchwasser_manuell] z Heizung Warmwasser 2 Temperatur HA->WP (manuell): Running automation actions 2020-11-20 08:41:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_brauchwasser_manuell] z Heizung Warmwasser 2 Temperatur HA->WP (manuell): Executing step call service 2020-11-20 08:41:11 INFO (MainThread) [homeassistant.components.automation.a_heizung_warmwasser_springt_an_aufheizen] z Heizung Warmwasser 8 Springt an --> Aufheizen HA->WP: Executing step call service 2020-11-20 08:41:11 WARNING (SyncWorker_18) [Luxtronik.Parameters] Parameter 'ID_Einst_BW_akt' not found 2020-11-20 08:41:11 WARNING (SyncWorker_18) [Luxtronik.Parameters] Parameter 'ID_Einst_BW_akt' not found 2020-11-20 08:41:21 WARNING (MainThread) [homeassistant.helpers.entity] Update of luxtronik.id_einst_hzhkrabs_akt is taking over 10 seconds 2020-11-20 08:41:21 INFO (MainThread) [homeassistant.components.automation.a_heizung_warmwasser_springt_an_aufheizen] z Heizung Warmwasser 8 Springt an --> Aufheizen HA->WP: Executing step call service 2020-11-20 08:41:21 INFO (MainThread) [homeassistant.components.automation.a_heizung_brauchwasser] z Heizung Warmwasser 2 Temperatur HA->WP: Running automation actions 2020-11-20 08:41:21 INFO (MainThread) [homeassistant.components.automation.a_heizung_brauchwasser] z Heizung Warmwasser 2 Temperatur HA->WP: Executing step call service 2020-11-20 08:42:10 WARNING (MainThread) [homeassistant.components.sensor] Updating luxtronik sensor took longer than the scheduled update interval 0:01:00 2020-11-20 08:43:10 WARNING (MainThread) [homeassistant.components.sensor] Updating luxtronik sensor took longer than the scheduled update interval 0:01:00

Bouni commented 3 years ago

Hi,

if I understand correctly, you use automations to write values which cause a lot of writes that have the potential to overlap with reads and cause the integration to crash, right?

I think about a solution where a write would set up a kind of buffer and when the next read happens, the value from the buffer gets written to heatpump 🤔

Or I need some kind of thread lock (but I have absolutely 0 experiance with these 😬 )

I will try to find a solution for this within the next few days!

Bouni commented 3 years ago

@BenPru If I create a version with a possible fix, would you mind testing it for us? As I do not use the write function myself that would be very helpful!

BenPru commented 3 years ago

If I create a version with a possible fix, would you mind testing it for us?

Yes of course. How can I get it?

Bouni commented 3 years ago

I first have to do it :smile: When I'm done I let you know!

But I guess you have to install it manually instead of using HACS (but thats no problem I hope)

BenPru commented 3 years ago

Oh, yes. I should read slower and better. 🤦‍♂️ Yes, I can install it manually.

Bouni commented 3 years ago

Ok, will take me some days, my time is very limited at the moment :innocent:

BenPru commented 3 years ago

Current error message: 2021-02-19 08:47:41 INFO (MainThread) [homeassistant.components.automation.a_heizung_nachts] z Heizung 6 Nachts HA->WP: Running automation actions 2021-02-19 08:47:41 INFO (MainThread) [homeassistant.components.automation.a_heizung_nachts] z Heizung 6 Nachts HA->WP: Executing step call service 2021-02-19 08:47:41 INFO (MainThread) [homeassistant.components.automation.z_heizung_geht_aus_ha_wp] z Heizung 9 geht aus HA->WP: Running automation actions 2021-02-19 08:47:41 INFO (MainThread) [homeassistant.components.automation.z_heizung_geht_aus_ha_wp] z Heizung 9 geht aus HA->WP: Executing step delay 0:00:05 2021-02-19 08:47:41 INFO (MainThread) [homeassistant.components.automation.a_heizung_temperatur] z Heizung 2 Temperatur HA->WP: Running automation actions 2021-02-19 08:47:41 INFO (MainThread) [homeassistant.components.automation.a_heizung_temperatur] z Heizung 2 Temperatur HA->WP: Executing step delay 0:00:03 2021-02-19 08:47:41 INFO (MainThread) [homeassistant.components.automation.a_heizung_nachts] z Heizung 6 Nachts HA->WP: Executing step call service 2021-02-19 08:47:41 ERROR (MainThread) [homeassistant.components.automation.a_heizung_nachts] z Heizung 6 Nachts HA->WP: Error executing script. Unexpected error for call_service at pos 2: unpack requires a buffer of 4 bytes Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step await getattr( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1494, in _execute_service await self._hass.async_add_executor_job(handler.job.target, service_call) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, *self.kwargs) File "/config/custom_components/luxtronik/init.py", line 73, in write_parameter luxtronik.write(parameter, value) File "/config/custom_components/luxtronik/init.py", line 114, in write self._luxtronik.write() File "/usr/local/lib/python3.8/site-packages/luxtronik/init.py", line 57, in write val = struct.unpack(">i", self._socket.recv(4))[0] struct.error: unpack requires a buffer of 4 bytes 2021-02-19 08:47:41 ERROR (MainThread) [homeassistant.components.automation.a_heizung_nachts] While executing automation automation.a_heizung_nachts Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/automation/init.py", line 404, in async_trigger await self.action_script.async_run( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1033, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 714, in async_run await super().async_run() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step await getattr( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1494, in _execute_service await self._hass.async_add_executor_job(handler.job.target, service_call) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, **self.kwargs) File "/config/custom_components/luxtronik/init.py", line 73, in write_parameter luxtronik.write(parameter, value) File "/config/custom_components/luxtronik/init.py", line 114, in write self._luxtronik.write() File "/usr/local/lib/python3.8/site-packages/luxtronik/init.py", line 57, in write val = struct.unpack(">i", self._socket.recv(4))[0] struct.error: unpack requires a buffer of 4 bytes

BenPru commented 3 years ago

Hmm, long time it looks good and I have no error. But today its back again 😥

Bouni commented 3 years ago

I guess that we need a Lock on writing and reading, so no write is done while a read is in progress ...

BenPru commented 3 years ago

I have extend the lock to read operations. And I have added a param "update_immediately_after_write" - but this is not working. :-/ Do you know how to force a sensor update?

Bouni commented 3 years ago

Unfortunately no, does your PR fix the lock problem?

tetsuo55 commented 2 years ago

Is this still an issue? I am writing an automation that simulates the RBE room temperature correction and i imagine it will trigger quite often

BenPru commented 2 years ago

@tetsuo55 No, this is fixed. Sorry for the late reply.