vincentdieltiens / homeassistant-eltako

2 stars 1 forks source link

The EnOcean telegrams are sending too quickly #4

Closed apromix closed 11 months ago

apromix commented 11 months ago

Hi @vincentdieltiens,

I know this is not the problem of this component but the control of more Eltako actors one by one consecutively doesn't work because the Eltako FAM14 doesn't react to all EnOcean telegrams.

As example I created a Automation or a Script to open all covers. This doesn't work 100%. The workaround is to add between the services (here Cover:Open) short delay (Sleep 1). Then works the Automation or the Script unerringly.

Do you have a idea how we can fix this issue? Simply adding time.sleep(.2) somewhere in dongle.py doesn't work because all is asynchronous.

Thanks ..

vincentdieltiens commented 11 months ago

Hi, sorry for the delay :)

This could explain why when I used google assistant to close all covers of my house, some of the covers do not close. I need close them after.

The solution is tricky because, as you say, everything is run asynchronously.

Maybe :

That sould ensure that there is a delay between each message

vincentdieltiens commented 11 months ago

This seems to work :

dongle.py


def __init__(self, hass, serial_path) -> None:
        #...
        self.last_message_time = None

def _send_message_callback(self, packet):
        """Sends a packet through the EnOcean dongle"""
        LOGGER.debug(
            "VINCENT : send packet %s, data=%s, optional=%s"
            % (
                to_hex_string(packet.packet_type),
                to_hex_string(packet.data),
                to_hex_string(packet.optional),
            )
        )

        wait = 0.5
        now = time.time()
        if self.last_message_time is None or (now - self.last_message_time) > wait:
            self.last_message_time = now
        else:
            self.last_message_time = self.last_message_time + wait
            delay = self.last_message_time - now
            time.sleep(delay)

        self._communicator.send(packet)
vincentdieltiens commented 11 months ago

I push the changes, can you try it ?

The delay can be changed in the integration options/configuration (in milliseconds)

apromix commented 11 months ago

Hi @vincentdieltiens,

many thanks for implementation of the delay.

To check if the delay works properly I had to improve the debug logging in commit https://github.com/apromix/homeassistant-eltako/commit/3e61aaf14dc69519ce94a7ef3385c87dc8318430 .

The result:

2023-11-25 13:29:25.544 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.544 DEBUG ... VINCENT : No delay
2023-11-25 13:29:25.545 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:25.572 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.572 DEBUG ... VINCENT : Delaying for 0.172765 [s]
2023-11-25 13:29:25.587 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.588 DEBUG ... VINCENT : Delaying for 0.356708 [s]
2023-11-25 13:29:25.604 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.605 DEBUG ... VINCENT : Delaying for 0.539516 [s]
2023-11-25 13:29:25.629 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.629 DEBUG ... VINCENT : Delaying for 0.715043 [s]
2023-11-25 13:29:25.646 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.647 DEBUG ... VINCENT : Delaying for 0.897449 [s]
2023-11-25 13:29:25.655 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.655 DEBUG ... VINCENT : Delaying for 1.088709 [s]
2023-11-25 13:29:25.665 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.665 DEBUG ... VINCENT : Delaying for 1.278968 [s]
2023-11-25 13:29:25.675 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.675 DEBUG ... VINCENT : Delaying for 1.468472 [s]
2023-11-25 13:29:25.681 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.681 DEBUG ... VINCENT : Delaying for 1.663165 [s]
2023-11-25 13:29:25.689 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.689 DEBUG ... VINCENT : Delaying for 1.854857 [s]
2023-11-25 13:29:25.697 DEBUG ... VINCENT : delay of 200 [ms]
2023-11-25 13:29:25.698 DEBUG ... VINCENT : Delaying for 2.046408 [s]
2023-11-25 13:29:25.748 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:25.950 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:26.148 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:26.352 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:26.547 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:26.762 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:26.945 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:27.145 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:27.377 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:27.545 DEBUG ... VINCENT : send packet 01, data=..., optional=
2023-11-25 13:29:27.744 DEBUG ... VINCENT : send packet 01, data=..., optional=

Now the debug information show that the EnOcena telegrams are sent delayed (check the timestamps).

Only some notices: