YET another time controlled cover (RFLink)

@javicalle If I add a cover with your code, then I get the following error:

Logger: homeassistant.setup
Source: setup.py:213
First occurred: 09:02:59 (1 occurrences)
Last logged: 09:02:59

Setup failed for knx: Unable to import component: cannot import name 'XknxConnectionState' from 'xknx.core' (/usr/local/lib/python3.10/site-packages/xknx/core/__init__.py)

Probably the same topic like this?
https://github.com/nagyrobi/home-assistant-custom-components-cover-rf-time-based/issues/50

See also https://community.home-assistant.io/t/hass-somfy-rts-blinds-and-rflink/124156/12

@javicalle
I did the same changes which are described in the links above on my own (and also other like is_opening) and now it worked.
Probably you could update your files?

1 Like

Thanks for reporting.
I’ll take a look later.

1 Like

Hey,
I have no operating problem with an RFLINK installed on Arduino Mega and SOMFY RTS covers.

The problem comes if you have a RFLink integration and the Knx integration too.
My custom component fixed the xknx dependency version and that creates all the trouble. I have removed the pinned version from the requirements and added it like a dependency (without a version).

Checking now in my environment. :crossed_fingers:

Checked and working without issues.
I don’t have the Knx integration settled but with the current version there’s no reason to generate any errors.

Hi :wave:!

Please don’t do that. Copy that one travelcalculator.py module you need for your thing (maybe attach xknx’ licence on top) and ship it with your custom component. You really only need that 160 lines of its 16k lines of knx code (and neither do you need its dependency tree).

It will save some headache for you and the xknx developers.

Sincerely Matthias, maintainer of xknx

Hi @farmio,
I want to apologize for any problem that my ignorance may have caused you. Nothing further from my will.

I followed your advice and included the travelcalculator module inside my custom_component.
I’m not sure how ‘attach xknx’ license on top’ would be appropriate. I’ve created a travelcalculator.readme file, but feel free to tell me the best way to include your credit in my component.

Kind regards.

Don’t worry, I had no troubles with that. There has been a similar custom_component - and I was quite surprised to find the reason for the knx integration not working for users of it back then. I’m just trying to prevent this from happening again.

For the licence thing, I’m no expert, but I’d just copy it on top as module docstring.

"""
license
"""
from __future__ import annotations

from enum import Enum
import time

class TravelCalculator:

https://github.com/XKNX/xknx/blob/78d71a62cbb67f5903c5088065bd79734a093579/LICENSE

Yes, your code use has spread a bit :sweat_smile:

Done!

2 Likes

Hello and thank you for your great work!

I have a Somfy RTS electric awning at which i’m not able to program the my-Position. Dont know why but also i dont need it.
So if i press the my-Position Button, the Somfy RTS just stops and dont goes further.

Is it possible to disable the my-Position e.g. by yaml-configuration?
If i just delete the rts_my_position doesnt works.

Hi, not sure what do you mean.
If you don’t configure the rts_my_position the stop button in HA should behave just as stop button. Isn’t that in your instalation?

If you want to alter the behavior of the physical remote it is not possible.

If i delete rts_my_position in my config, the cover wont work anymore in Homeassistant.
Leaving empty like

rts_my_position: []

or

rts_my_position: 

doesn’t work also.

The problem is when i press on the physical remote the my-button while the cover is not moving, the rflink integration sets the state curent_position in HomeAssistant to the rts_my_position’ from the config, which is wrong

edit:
I reached my goals by editing the cover.py
From

    def _handle_my_button(self):
        """Handle the MY button press"""
        self._require_stop_cover = False
        if self.tc.is_traveling():
            _LOGGER.debug('_handle_my_button :: button stops cover')
            self.tc.stop()
            self.stop_auto_updater()
        elif self._rts_my_position is not None:
            _LOGGER.debug('_handle_my_button :: button sends to MY')
            self.tc.start_travel(self.shift_position(self._rts_my_position))
            self.start_auto_updater()

to

    def _handle_my_button(self):
        """Handle the MY button press"""
        self._require_stop_cover = False
        if self.tc.is_traveling():
            _LOGGER.debug('_handle_my_button :: button stops cover')
            self.tc.stop()
            self.stop_auto_updater()
        elif self._rts_my_position is not None:
            _LOGGER.debug('_handle_my_button :: button sends to MY')
            self.tc.stop()
            self.stop_auto_updater()

and comment out the my_position attribute

    @property
    def device_state_attributes(self):
        """Return the device state attributes."""
        attr = {}
        super_attr = super().device_state_attributes
        if super_attr is not None:
            attr.update(super_attr)
#        if self._rts_my_position is not None:
#            attr[CONF_MY_POSITION] = self._rts_my_position
        if self._travel_time_down is not None:
            attr[CONF_TRAVELLING_TIME_DOWN] = self._travel_time_down
        if self._travel_time_up is not None:
            attr[CONF_TRAVELLING_TIME_UP] = self._travel_time_up
        return attr

I would prefer to figure out why isn’t working if you don’t configure the rts_my_position attribute.

The attribute is optional:

The code that you proposed is the same that would execute if cover is_traveling

            _LOGGER.debug('_handle_my_button :: button stops cover')
            self.tc.stop()
            self.stop_auto_updater()

So let’s fix the issue and then see if something else must fixed.
Can you check if there are any errors in the HA start when you remove the attribute? Or when you press any button (with the attribute removed)?

Yes of course we can.
When i comment out rts_my_position the logs say:

Nr 1.:

Logger: homeassistant.components.cover
Source: custom_components/rts_rflink/cover.py:110
Integration: Abdeckung (documentation, issues)
First occurred: 22:54:01 (1 occurrences)
Last logged: 22:54:01
Error while setting up rts_rflink platform for cover

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/rts_rflink/cover.py", line 124, in async_setup_platform
    async_add_entities(devices_from_config(config))
  File "/config/custom_components/rts_rflink/cover.py", line 110, in devices_from_config
    rts_my_position = config.pop(CONF_MY_POSITION)
KeyError: 'rts_my_position'

Nr. 2:

2023-04-01 22:54:00.681 INFO (MainThread) [homeassistant.components.rflink] Initiating Rflink connection
2023-04-01 22:54:00.684 INFO (MainThread) [homeassistant.components.rflink] Connected to Rflink
2023-04-01 22:54:01.355 ERROR (MainThread) [homeassistant.components.cover] Error while setting up rts_rflink platform for cover
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/rts_rflink/cover.py", line 124, in async_setup_platform
async_add_entities(devices_from_config(config))
File "/config/custom_components/rts_rflink/cover.py", line 110, in devices_from_config
rts_my_position = config.pop(CONF_MY_POSITION)
KeyError: 'rts_my_position'

It seems that will need a few fixes, but could you try with that version (default None in the pop function)

def devices_from_config(domain_config):
    """Parse configuration and add RFLink cover devices."""
    devices = []
    for entity_id, config in domain_config[CONF_DEVICES].items():
        entity_type = config.pop(CONF_TYPE)
        entity_class = entity_class_for_type(entity_type)
        rts_my_position = config.pop(CONF_MY_POSITION, None)
        travel_time_down = config.pop(CONF_TRAVELLING_TIME_DOWN)
        travel_time_up = config.pop(CONF_TRAVELLING_TIME_UP)
        device_config = dict(domain_config[CONF_DEVICE_DEFAULTS], **config)
        device = entity_class(
            entity_id, rts_my_position, travel_time_down,
            travel_time_up, **device_config)
        devices.append(device)
    return devices

That worked fine, thanks a lot.
Here is the log:

2023-04-02 09:58:24.532 INFO (MainThread) [homeassistant.components.rflink] Initiating Rflink connection
2023-04-02 09:58:24.535 INFO (MainThread) [homeassistant.components.rflink] Connected to Rflink
2023-04-02 09:58:27.411 DEBUG (MainThread) [custom_components.rts_rflink.cover] async_added_to_hass :: oldState <state cover.markise_wohnzimmer_sud=open; current_position=100, assumed_state=True, friendly_name=Markise Wohnzimmer Süd, supported_features=15 @ 2023-04-01T23:43:51.196485+02:00>
2023-04-02 09:59:31.331 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'stop'}
2023-04-02 09:59:47.110 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'stop'}
2023-04-02 09:59:52.743 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'stop'}
2023-04-02 09:59:56.241 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'up'}
2023-04-02 09:59:56.241 DEBUG (MainThread) [custom_components.rts_rflink.cover] start_auto_updater
2023-04-02 09:59:56.241 DEBUG (MainThread) [custom_components.rts_rflink.cover] init _unsubscribe_auto_updater
2023-04-02 09:59:56.343 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 09:59:56.343 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook :: position_reached
2023-04-02 09:59:56.343 DEBUG (MainThread) [custom_components.rts_rflink.cover] stop_auto_updater
2023-04-02 10:00:19.029 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'down'}
2023-04-02 10:00:19.029 DEBUG (MainThread) [custom_components.rts_rflink.cover] start_auto_updater
2023-04-02 10:00:19.029 DEBUG (MainThread) [custom_components.rts_rflink.cover] init _unsubscribe_auto_updater
2023-04-02 10:00:19.131 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.232 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.333 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.434 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.535 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.637 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.738 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.839 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:19.940 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.041 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.142 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.243 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.345 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.446 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.547 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.648 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.749 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.850 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:20.952 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.053 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.155 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.256 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.357 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.458 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.560 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.661 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.762 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.864 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:21.964 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.066 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.166 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.267 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.369 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.470 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.571 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.672 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.773 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.875 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:22.976 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:23.044 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'stop'}
2023-04-02 10:00:23.044 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_my_button :: button stops cover
2023-04-02 10:00:23.044 DEBUG (MainThread) [custom_components.rts_rflink.cover] stop_auto_updater
2023-04-02 10:00:45.971 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'stop'}
2023-04-02 10:00:50.489 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'stop'}
2023-04-02 10:00:52.955 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'up'}
2023-04-02 10:00:52.955 DEBUG (MainThread) [custom_components.rts_rflink.cover] start_auto_updater
2023-04-02 10:00:52.955 DEBUG (MainThread) [custom_components.rts_rflink.cover] init _unsubscribe_auto_updater
2023-04-02 10:00:53.056 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.158 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.259 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.360 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.462 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.563 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.664 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.765 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.867 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:53.968 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.069 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.170 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.271 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.372 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.473 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.574 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.677 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.779 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.880 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:54.981 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:55.082 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:00:55.093 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'stop'}
2023-04-02 10:00:55.093 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_my_button :: button stops cover
2023-04-02 10:00:55.094 DEBUG (MainThread) [custom_components.rts_rflink.cover] stop_auto_updater
2023-04-02 10:01:01.000 DEBUG (MainThread) [custom_components.rts_rflink.cover] _handle_event {'id': 'rts_f7a934_01', 'command': 'up'}
2023-04-02 10:01:01.001 DEBUG (MainThread) [custom_components.rts_rflink.cover] start_auto_updater
2023-04-02 10:01:01.001 DEBUG (MainThread) [custom_components.rts_rflink.cover] init _unsubscribe_auto_updater
2023-04-02 10:01:01.102 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.203 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.305 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.407 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.508 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.609 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.710 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.812 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:01.913 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.014 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.116 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.217 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.318 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.419 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.520 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.621 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook
2023-04-02 10:01:02.622 DEBUG (MainThread) [custom_components.rts_rflink.cover] auto_updater_hook :: position_reached
2023-04-02 10:01:02.622 DEBUG (MainThread) [custom_components.rts_rflink.cover] stop_auto_updater

Thanks to you for testing and reporting back.
I’ll update the component ASAP.

Hello @javicalle,
i have this error msg when trying to add the repo through HACS.
<Integration javicalle/custom_components> Repository structure for master is not compliant
Is that normal ?
Thanks

The custom component is not prepared for HACS. I tried it at some time ago but ran into trouble at some point and gave it up.
You can add in HACS this other repository that contains the same version, but as you will see it does not have any details nor is it documented: